nixio: Export more constants, introduce {g,s}et{g,u}id, getpid, getppid
[oweals/luci.git] / libs / nixio / src / splice.c
index cbfc6749940ab7451ed2f837d6210fae2860727e..0f715c2bb337e5b61545c16c8e077a5d8ea39ec8 100644 (file)
@@ -16,8 +16,6 @@
  *  limitations under the License.
  */
 
-#define _GNU_SOURCE
-
 #include "nixio.h"
 #include <fcntl.h>
 #include <string.h>
@@ -25,6 +23,8 @@
 #include <unistd.h>
 #include <sys/sendfile.h>
 
+#ifdef _GNU_SOURCE
+
 /* guess what sucks... */
 #ifdef __UCLIBC__
 #include <unistd.h>
@@ -46,30 +46,6 @@ ssize_t splice(int __fdin, __off64_t *__offin, int __fdout,
 }
 #endif /* __UCLIBC__ */
 
-/**
- * Translate splice flags to integer
- */
-static int nixio_splice_flags(lua_State *L) {
-       const int j = lua_gettop(L);
-       int flags = 0;
-       for (int i=1; i<=j; i++) {
-               const char *flag = luaL_checkstring(L, i);
-               if (!strcmp(flag, "move")) {
-                       flags |= SPLICE_F_MOVE;
-               } else if (!strcmp(flag, "nonblock")) {
-                       flags |= SPLICE_F_NONBLOCK;
-               } else if (!strcmp(flag, "more")) {
-                       flags |= SPLICE_F_MORE;
-               } else {
-                       return luaL_argerror(L, i, "supported values: "
-                        "move, nonblock, more");
-               }
-       }
-       lua_pushinteger(L, flags);
-
-       return 1;
-}
-
 /**
  * splice(fd_in, fd_out, length, flags)
  */
@@ -92,12 +68,32 @@ static int nixio_splice(lua_State *L) {
        return 1;
 }
 
-static int nixio_splice_avail(lua_State *L) {
-       splice(-1, 0, -1, 0, 0, 0);
-       lua_pushboolean(L, errno != ENOSYS);
+/**
+ * Translate splice flags to integer
+ */
+static int nixio_splice_flags(lua_State *L) {
+       const int j = lua_gettop(L);
+       int flags = 0;
+       for (int i=1; i<=j; i++) {
+               const char *flag = luaL_checkstring(L, i);
+               if (!strcmp(flag, "move")) {
+                       flags |= SPLICE_F_MOVE;
+               } else if (!strcmp(flag, "nonblock")) {
+                       flags |= SPLICE_F_NONBLOCK;
+               } else if (!strcmp(flag, "more")) {
+                       flags |= SPLICE_F_MORE;
+               } else {
+                       return luaL_argerror(L, i, "supported values: "
+                        "move, nonblock, more");
+               }
+       }
+       lua_pushinteger(L, flags);
+
        return 1;
 }
 
+#endif /* _GNU_SOURCE */
+
 /**
  * sendfile(outfd, infd, length)
  */
@@ -118,9 +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},
-       {"splice_avail",        nixio_splice_avail},
+#endif
        {"sendfile",            nixio_sendfile},
        {NULL,                  NULL}
 };