* 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) {
}
#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
*/
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)
/* module table */
static const luaL_reg R[] = {
+#ifdef _GNU_SOURCE
{"splice", nixio_splice},
{"splice_flags", nixio_splice_flags},
+#endif
{"sendfile", nixio_sendfile},
{NULL, NULL}
};