libs/nixio: fix uninitialized variable warning on Darwin in splice.c
[project/luci.git] / libs / nixio / src / splice.c
index 0704dfd..db63ea9 100644 (file)
 #endif
 
 #ifdef _GNU_SOURCE
+#ifdef SPLICE_F_MOVE
 
 /* guess what sucks... */
 #ifdef __UCLIBC__
 #include <unistd.h>
 #include <sys/syscall.h>
+
 ssize_t splice(int __fdin, __off64_t *__offin, int __fdout,
         __off64_t *__offout, size_t __len, unsigned int __flags) {
 #ifdef __NR_splice
@@ -88,7 +90,7 @@ static int nixio_splice(lua_State *L) {
                return nixio__perror(L);
        }
 
-       lua_pushnumber(L, spliced);
+       lua_pushinteger(L, spliced);
        return 1;
 }
 
@@ -116,6 +118,7 @@ static int nixio_splice_flags(lua_State *L) {
        return 1;
 }
 
+#endif /* SPLICE_F_MOVE */
 #endif /* _GNU_SOURCE */
 
 /**
@@ -140,7 +143,12 @@ static int nixio_sendfile(lua_State *L) {
        const off_t offset = lseek(infd, 0, SEEK_CUR);
 
        do {
+#ifdef __DARWIN__
+               r = sendfile(infd, sock, offset, (off_t *)&len, NULL, 0);
+               spliced = r;
+#else
                r = sendfile(infd, sock, offset, len, NULL, &spliced, 0);
+#endif
        } while (r == -1 && errno == EINTR);
 
        if (r == -1) {
@@ -148,16 +156,18 @@ static int nixio_sendfile(lua_State *L) {
        }
 #endif
 
-       lua_pushnumber(L, spliced);
+       lua_pushinteger(L, spliced);
        return 1;
 }
 
 /* module table */
 static const luaL_reg R[] = {
 #ifdef _GNU_SOURCE
+#ifdef SPLICE_F_MOVE
        {"splice",                      nixio_splice},
        {"splice_flags",        nixio_splice_flags},
 #endif
+#endif
        {"sendfile",            nixio_sendfile},
        {NULL,                  NULL}
 };