nixio: Export more constants, introduce {g,s}et{g,u}id, getpid, getppid
[oweals/luci.git] / libs / nixio / src / splice.c
index 556b4d7dadcc719ac39e1099699ae5dca75ae3fb..0f715c2bb337e5b61545c16c8e077a5d8ea39ec8 100644 (file)
  *  limitations under the License.
  */
 
-#define _GNU_SOURCE
-
 #include "nixio.h"
 #include <fcntl.h>
 #include <string.h>
+#include <errno.h>
+#include <unistd.h>
 #include <sys/sendfile.h>
 
+#ifdef _GNU_SOURCE
+
 /* guess what sucks... */
 #ifdef __UCLIBC__
 #include <unistd.h>
-#include <errno.h>
 #include <sys/syscall.h>
 ssize_t splice(int __fdin, __off64_t *__offin, int __fdout,
         __off64_t *__offout, size_t __len, unsigned int __flags) {
@@ -45,6 +46,28 @@ ssize_t splice(int __fdin, __off64_t *__offin, int __fdout,
 }
 #endif /* __UCLIBC__ */
 
+/**
+ * splice(fd_in, fd_out, length, flags)
+ */
+static int nixio_splice(lua_State *L) {
+       int fd_in = nixio__checkfd(L, 1);
+       int fd_out = nixio__checkfd(L, 2);
+       size_t len = luaL_checkinteger(L, 3);
+       int flags = luaL_optinteger(L, 4, 0);
+       long spliced;
+
+       do {
+               spliced = splice(fd_in, NULL, fd_out, NULL, len, flags);
+       } while (spliced == -1 && errno == EINTR);
+
+       if (spliced < 0) {
+               return nixio__perror(L);
+       }
+
+       lua_pushnumber(L, spliced);
+       return 1;
+}
+
 /**
  * Translate splice flags to integer
  */
@@ -69,25 +92,7 @@ static int nixio_splice_flags(lua_State *L) {
        return 1;
 }
 
-/**
- * splice(fd_in, fd_out, length, flags)
- */
-static int nixio_splice(lua_State *L) {
-       int fd_in = nixio__checkfd(L, 1);
-       int fd_out = nixio__checkfd(L, 2);
-       size_t len = luaL_checkinteger(L, 3);
-       int flags = luaL_optinteger(L, 4, 0);
-
-
-       long spliced = splice(fd_in, NULL, fd_out, NULL, len, flags);
-
-       if (spliced < 0) {
-               return nixio__perror(L);
-       }
-
-       lua_pushnumber(L, spliced);
-       return 1;
-}
+#endif /* _GNU_SOURCE */
 
 /**
  * sendfile(outfd, infd, length)
@@ -109,8 +114,10 @@ static int nixio_sendfile(lua_State *L) {
 
 /* module table */
 static const luaL_reg R[] = {
+#ifdef _GNU_SOURCE
        {"splice",                      nixio_splice},
        {"splice_flags",        nixio_splice_flags},
+#endif
        {"sendfile",            nixio_sendfile},
        {NULL,                  NULL}
 };