summaryrefslogtreecommitdiffhomepage
path: root/libs/nixio/src/splice.c
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2009-02-27 14:51:37 +0000
committerSteven Barth <steven@midlink.org>2009-02-27 14:51:37 +0000
commit7196b2cd848577f640d9268a0a34ab3ad8706c26 (patch)
tree94b74ea2ba96fdc6135c6af807e925f064a2db28 /libs/nixio/src/splice.c
parent30421d38dd004a8c1e149e40af2019cbbc4c8bd6 (diff)
nixio: Fixes, use POSIX calls for file i/o
httpclient: resume support, splice() support, cookie support
Diffstat (limited to 'libs/nixio/src/splice.c')
-rw-r--r--libs/nixio/src/splice.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/libs/nixio/src/splice.c b/libs/nixio/src/splice.c
index 538b99e69..556b4d7da 100644
--- a/libs/nixio/src/splice.c
+++ b/libs/nixio/src/splice.c
@@ -20,6 +20,7 @@
#include "nixio.h"
#include <fcntl.h>
+#include <string.h>
#include <sys/sendfile.h>
/* guess what sucks... */
@@ -45,28 +46,24 @@ ssize_t splice(int __fdin, __off64_t *__offin, int __fdout,
#endif /* __UCLIBC__ */
/**
- * Checks whether a flag is set in the table and translates it into a bitmap
- */
-static void nixio_splice_flags__w(lua_State *L, int *m, int f, const char *t) {
- lua_pushstring(L, t);
- lua_rawget(L, -2);
- if (lua_toboolean(L, -1)) {
- *m |= f;
- }
- lua_pop(L, 1);
-}
-
-/**
- * Translate integer to poll flags and vice versa
+ * Translate splice flags to integer
*/
static int nixio_splice_flags(lua_State *L) {
+ const int j = lua_gettop(L);
int flags = 0;
-
- luaL_checktype(L, 1, LUA_TTABLE);
- lua_settop(L, 1);
- nixio_splice_flags__w(L, &flags, SPLICE_F_MOVE, "move");
- nixio_splice_flags__w(L, &flags, SPLICE_F_NONBLOCK, "nonblock");
- nixio_splice_flags__w(L, &flags, SPLICE_F_MORE, "more");
+ 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;