summaryrefslogtreecommitdiffhomepage
path: root/libs/nixio/src/splice.c
diff options
context:
space:
mode:
Diffstat (limited to 'libs/nixio/src/splice.c')
-rw-r--r--libs/nixio/src/splice.c57
1 files changed, 27 insertions, 30 deletions
diff --git a/libs/nixio/src/splice.c b/libs/nixio/src/splice.c
index cbfc67499..0f715c2bb 100644
--- a/libs/nixio/src/splice.c
+++ b/libs/nixio/src/splice.c
@@ -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>
@@ -47,30 +47,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)
*/
static int nixio_splice(lua_State *L) {
@@ -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}
};