diff options
author | Rob Kendrick (monotony) <rjek@rjek.com> | 2013-01-28 17:16:21 +0000 |
---|---|---|
committer | Rob Kendrick (monotony) <rjek@rjek.com> | 2013-01-28 17:16:21 +0000 |
commit | 7bca422064f99b47c6e5654a43aed9f25e9ed56e (patch) | |
tree | 73ef2213ea927a0f870f3754ebefa32919b908dc | |
parent | a563e22ec4828b38709b0ee8caa77fae11f43fa9 (diff) | |
download | luxio-7bca422064f99b47c6e5654a43aed9f25e9ed56e.tar.gz |
Merge FreeBSD fix changes
-rw-r--r-- | luxio.c | 284 |
1 files changed, 142 insertions, 142 deletions
@@ -105,7 +105,7 @@ luxio__exec(lua_State *L, bool usep) } args[c] = NULL; - + if (usep) { ret = execvp(path, args); } else { @@ -116,7 +116,7 @@ luxio__exec(lua_State *L, bool usep) free(args); lua_pushinteger(L, ret); lua_pushinteger(L, errno); - + return 2; } @@ -156,7 +156,7 @@ luxio_waitpid(lua_State *L) /* 3.2.1 */ int options = luaL_checkinteger(L, 2); int status; pid_t proc; - + proc = waitpid(pid, &status, options); lua_pushinteger(L, proc); if (proc == -1) { @@ -236,9 +236,9 @@ static int luxio__exit(lua_State *L) /* 3.2.2 */ { int ret = luaL_optinteger(L, 1, 0); - + _exit(ret); - + return 0; } @@ -282,7 +282,7 @@ luxio_alarm(lua_State *L) /* 3.4.1 */ { unsigned int seconds = luaL_checkinteger(L, 1); lua_pushinteger(L, alarm(seconds)); - + return 1; } @@ -295,7 +295,7 @@ luxio_pause(lua_State *L) /* 3.4.2 */ { lua_pushinteger(L, pause()); lua_pushinteger(L, errno); - + return 2; } @@ -309,7 +309,7 @@ luxio_sleep(lua_State *L) /* 3.4.3 */ unsigned int seconds = luaL_checkinteger(L, 1); lua_pushinteger(L, sleep(seconds)); - + return 1; } @@ -323,7 +323,7 @@ static int luxio_getpid(lua_State *L) /* 4.1.1 */ { lua_pushinteger(L, getpid()); - + return 1; } @@ -335,7 +335,7 @@ static int luxio_getppid(lua_State *L) /* 4.1.1 */ { lua_pushinteger(L, getppid()); - + return 1; } @@ -349,7 +349,7 @@ static int luxio_getuid(lua_State *L) /* 4.2.1 */ { lua_pushinteger(L, getuid()); - + return 1; } @@ -361,7 +361,7 @@ static int luxio_geteuid(lua_State *L) /* 4.2.1 */ { lua_pushinteger(L, geteuid()); - + return 1; } @@ -373,7 +373,7 @@ static int luxio_getgid(lua_State *L) /* 4.2.1 */ { lua_pushinteger(L, getgid()); - + return 1; } @@ -385,7 +385,7 @@ static int luxio_getegid(lua_State *L) /* 4.2.1 */ { lua_pushinteger(L, getegid()); - + return 1; } @@ -400,7 +400,7 @@ luxio_setuid(lua_State *L) /* 4.2.2 */ lua_pushinteger(L, setuid(uid)); lua_pushinteger(L, errno); - + return 2; } @@ -415,7 +415,7 @@ luxio_setgid(lua_State *L) /* 4.2.2 */ lua_pushinteger(L, setgid(gid)); lua_pushinteger(L, errno); - + return 2; } @@ -431,7 +431,7 @@ luxio_getlogin(lua_State *L) /* 4.2.4 */ { char buf[LOGIN_NAME_MAX]; int r = getlogin_r(buf, sizeof(buf)); - + if (r != 0) { lua_pushinteger(L, r); lua_pushinteger(L, errno); @@ -550,14 +550,14 @@ static int luxio_getenv(lua_State *L) /* 4.6.1 */ { const char *envvar = luaL_checkstring(L, 1); - + char *envval = getenv(envvar); - + if (envval == NULL) return 0; - + lua_pushstring(L, envval); - + return 1; } @@ -571,10 +571,10 @@ luxio_setenv(lua_State *L) /* POSIX.1-2001 */ const char *envvar = luaL_checkstring(L, 1); const char *envval = luaL_checkstring(L, 2); int overwrite = luaL_optint(L, 3, 1); - + lua_pushinteger(L, setenv(envvar, envval, overwrite)); lua_pushinteger(L, errno); - + return 2; } @@ -586,10 +586,10 @@ static int luxio_unsetenv(lua_State *L) /* POSIX.1-2001 */ { const char *envvar = luaL_checkstring(L, 1); - + lua_pushinteger(L, unsetenv(envvar)); lua_pushinteger(L, errno); - + return 2; } @@ -620,10 +620,10 @@ static int luxio_readdir_gc(lua_State *L) { luxio_readdir_state *s = luaL_checkudata(L, 1, LUXIO_READDIR_METATABLE); - + closedir(s->dirp); free(s->buf); - + return 0; } @@ -638,7 +638,7 @@ luxio_readdir_tostring(lua_State *L) */ snprintf(buf, sizeof(buf), "dirent: %p", s); lua_pushstring(L, buf); - + return 1; } @@ -660,7 +660,7 @@ luxio__bless_readdir(lua_State *L) * handle = opendir(path); * nil, errno = opendir(path) * handle, errno = opendir(path) - */ + */ static int luxio_opendir(lua_State *L) /* 5.1.2 */ { @@ -742,7 +742,7 @@ luxio_closedir(lua_State *L) /* 5.1.2 */ free(s->buf); s->buf = NULL; - + return 0; } @@ -756,7 +756,7 @@ luxio_readdir(lua_State *L) /* 5.1.2 */ { luxio_readdir_state *s = luaL_checkudata(L, 1, LUXIO_READDIR_METATABLE); int err; - + err = readdir_r(s->dirp, s->buf, &s->ent); if (err == 0 && s->ent != NULL) { @@ -855,12 +855,12 @@ luxio_open(lua_State *L) /* 5.3.1 */ lua_pushstring(L, "open with O_CREAT called with no mode"); lua_error(L); } - + if (mode == INVALID_MODE) result = open(pathname, flags); else result = open(pathname, flags, mode); - + lua_pushinteger(L, result); lua_pushinteger(L, errno); @@ -963,10 +963,10 @@ luxio_mkfifo(lua_State *L) /* 5.4.2 */ { const char *pathname = luaL_checkstring(L, 1); mode_t mode = luaL_checkinteger(L, 2); - + lua_pushinteger(L, mkfifo(pathname, mode)); lua_pushinteger(L, errno); - + return 2; } @@ -980,7 +980,7 @@ static int luxio_unlink(lua_State *L) /* 5.5.1 */ { const char *s = luaL_checkstring(L, 1); - + lua_pushinteger(L, unlink(s)); lua_pushinteger(L, errno); @@ -995,7 +995,7 @@ static int luxio_rmdir(lua_State *L) /* 5.5.2 */ { const char *pathname = luaL_checkstring(L, 1); - + lua_pushinteger(L, rmdir(pathname)); lua_pushinteger(L, errno); @@ -1056,7 +1056,7 @@ luxio_stat(lua_State *L) /* 5.6.2 */ const char *pathname = luaL_checkstring(L, 1); struct stat s; int r = stat(pathname, &s); - + lua_pushinteger(L, r); if (r < 0) { @@ -1078,7 +1078,7 @@ luxio_fstat(lua_State *L) /* 5.6.2 */ int fd = luaL_checkinteger(L, 1); struct stat s; int r = fstat(fd, &s); - + lua_pushinteger(L, r); if (r < 0) { @@ -1102,7 +1102,7 @@ luxio_lstat(lua_State *L) /* POSIX.1-2001 */ int r = lstat(pathname, &s); lua_pushinteger(L, r); - + if (r < 0) { lua_pushinteger(L, errno); } else { @@ -1250,7 +1250,7 @@ luxio_pipe(lua_State *L) /* 6.1.1 */ { int res, pipefd[2]; luaL_checktype(L, 1, LUA_TTABLE); - + res = pipe(pipefd); if (res == 0) { lua_pushinteger(L, pipefd[0]); @@ -1258,10 +1258,10 @@ luxio_pipe(lua_State *L) /* 6.1.1 */ lua_pushinteger(L, pipefd[1]); lua_rawseti(L, 1, 2); } - + lua_pushinteger(L, res); lua_pushinteger(L, errno); - + return 2; } @@ -1276,10 +1276,10 @@ luxio_pipe2(lua_State *L) /* GNU extension */ { int res, pipefd[2]; int flags; - + luaL_checktype(L, 1, LUA_TTABLE); flags = luaL_checkinteger(L, 2); - + res = pipe2(pipefd, flags); if (res == 0) { lua_pushinteger(L, pipefd[0]); @@ -1287,10 +1287,10 @@ luxio_pipe2(lua_State *L) /* GNU extension */ lua_pushinteger(L, pipefd[1]); lua_rawseti(L, 1, 2); } - + lua_pushinteger(L, res); lua_pushinteger(L, errno); - + return 2; } #endif @@ -1308,7 +1308,7 @@ luxio_socketpair(lua_State *L) /* POSIX.1-2001 */ int sv[2]; int res; luaL_checktype(L, 4, LUA_TTABLE); - + res = socketpair(domain, type, protocol, sv); if (res == 0) { lua_pushinteger(L, sv[0]); @@ -1320,7 +1320,7 @@ luxio_socketpair(lua_State *L) /* POSIX.1-2001 */ lua_pushinteger(L, res); lua_pushinteger(L, errno); - return 2; + return 2; } /**# File descriptor manipulation ********************************************/ @@ -1333,7 +1333,7 @@ static int luxio_dup(lua_State *L) /* 6.2.1 */ { int oldfd = luaL_checkint(L, 1); - + lua_pushinteger(L, dup(oldfd)); lua_pushinteger(L, errno); @@ -1349,11 +1349,11 @@ luxio_dup2(lua_State *L) /* 6.2.1 */ { int oldfd = luaL_checkint(L, 1); int newfd = luaL_checkint(L, 2); - + lua_pushinteger(L, dup2(oldfd, newfd)); lua_pushinteger(L, errno); - return 2; + return 2; } #ifdef _GNU_SOURCE @@ -1367,7 +1367,7 @@ luxio_dup3(lua_State *L) /* GNU extension */ int oldfd = luaL_checkint(L, 1); int newfd = luaL_checkint(L, 2); int flags = luaL_checkint(L, 3); - + lua_pushinteger(L, dup3(oldfd, newfd, flags)); lua_pushinteger(L, errno); @@ -1404,14 +1404,14 @@ luxio_read(lua_State *L) /* 6.4.1 */ int count = luaL_checkint(L, 2); ssize_t result; char *buf = malloc(count); - + if (buf == NULL) { lua_pushstring(L, "unable to allocate read buffer: memory exhausted"); lua_error(L); } - + result = read(fd, buf, count); - + if (result == -1) { lua_pushinteger(L, result); lua_pushinteger(L, errno); @@ -1427,7 +1427,7 @@ luxio_read(lua_State *L) /* 6.4.1 */ lua_pushlstring(L, buf, result); lua_pushinteger(L, errno); } - + free(buf); return 2; @@ -1444,9 +1444,9 @@ luxio_write(lua_State *L) /* 6.4.2 */ size_t count; const char *buf = luaL_checklstring(L, 2, &count); size_t offset = luaL_optinteger(L, 3, 0); - + if (offset > count) offset = count; - + lua_pushinteger(L, write(fd, buf + offset, count - offset)); lua_pushinteger(L, errno); @@ -1464,22 +1464,22 @@ luxio_writev(lua_State *L) /* POSIX.1-2001 */ int blks = lua_gettop(L) - 1; int c; struct iovec *iov; - + /* check there is at least one string to write */ luaL_checkstring(L, 2); - + iov = malloc(blks * sizeof(*iov)); - + for (c = 0; c < blks; c++) { iov[c].iov_base = (void *)luaL_checkstring(L, c + 2); iov[c].iov_len = lua_rawlen(L, c + 2); } - + lua_pushinteger(L, writev(fd, iov, blks)); lua_pushinteger(L, errno); - + free(iov); - + return 2; } @@ -1503,7 +1503,7 @@ luxio_sendfile(lua_State *L) /* Linux-specific */ lua_pushinteger(L, errno); return 2; } - + offset = luaL_checkint(L, 3); r = sendfile(out_fd, in_fd, &offset, count); lua_pushinteger(L, r); @@ -1561,7 +1561,7 @@ luxio_fcntl(lua_State *L) /* 6.5.2 */ int cmd = luaL_checkint(L, 2); long arg_long; struct flock flock; - + switch (cmd) { /* commands that take no argument */ case F_GETFD: @@ -1594,7 +1594,7 @@ luxio_fcntl(lua_State *L) /* 6.5.2 */ case F_SETLKW: case F_GETLK: luaL_checktype(L, 3, LUA_TTABLE); - + lua_getfield(L, 3, "l_type"); lua_getfield(L, 3, "l_whence"); lua_getfield(L, 3, "l_start"); @@ -1604,7 +1604,7 @@ luxio_fcntl(lua_State *L) /* 6.5.2 */ flock.l_start = lua_tonumber(L, -2); flock.l_len = lua_tonumber(L, -1); flock.l_pid = 0; - + lua_pushinteger(L, fcntl(fd, cmd, &flock)); lua_pushinteger(L, errno); @@ -1622,12 +1622,12 @@ luxio_fcntl(lua_State *L) /* 6.5.2 */ } return 2; - + default: lua_pushstring(L, "unhandled fcntl() command"); lua_error(L); } - + return 0; /* never get here, but keep compiler happy */ } @@ -1638,7 +1638,7 @@ luxio_lseek(lua_State *L) /* 6.5.3 */ int fd = luaL_checkint(L, 1); off64_t offset = (off64_t)luaL_checknumber(L, 2); /* 56b is enough! */ int whence = luaL_checkint(L, 3); - + lua_pushinteger(L, (lua_Number)lseek64(fd, offset, whence)); lua_pushinteger(L, errno); @@ -1655,7 +1655,7 @@ luxio_lseek(lua_State *L) /* 6.5.3 */ int fd = luaL_checkint(L, 1); off_t offset = luaL_checkinteger(L, 2); int whence = luaL_checkint(L, 3); - + lua_pushinteger(L, lseek(fd, offset, whence)); lua_pushinteger(L, errno); @@ -1673,7 +1673,7 @@ static int luxio_fsync(lua_State *L) /* 6.6.1 */ { int fildes = luaL_checkinteger(L, 1); - + lua_pushinteger(L, fsync(fildes)); lua_pushinteger(L, errno); @@ -1689,7 +1689,7 @@ static int luxio_fdatasync(lua_State *L) /* 6.6.2 */ { int fildes = luaL_checkinteger(L, 1); - + lua_pushinteger(L, fdatasync(fildes)); lua_pushinteger(L, errno); @@ -1792,7 +1792,7 @@ luxio_nanosleep(lua_State *L) /* 14.2.5 */ lua_pushinteger(L, rem.tv_sec); lua_pushinteger(L, rem.tv_nsec); - return 4; + return 4; } /**# Message passing *********************************************************/ @@ -1821,7 +1821,7 @@ luxio_mq_open(lua_State *L) /* 15.2.1 */ lua_pushstring(L, "mq_open with O_CREATE called with no mode"); lua_error(L); } - + if (oflag & O_CREAT) { mq = mq_open(name, oflag, mode, NULL); } else { @@ -1859,7 +1859,7 @@ luxio_mq_unlink(lua_State *L) /* 15.2.3 */ lua_pushinteger(L, mq_unlink(name)); lua_pushinteger(L, errno); - return 2; + return 2; } /**% mq_send @@ -1942,7 +1942,7 @@ luxio_mq_setattr(lua_State *L) /* 15.2.7 */ mqd_t mq = luaL_checkinteger(L, 1); struct mq_attr mqstat = { luaL_checkinteger(L, 2), 0, 0, 0 }; struct mq_attr omqstat = { 0, 0, 0, 0 }; - + lua_pushinteger(L, mq_setattr(mq, &mqstat, &omqstat)); lua_pushinteger(L, errno); luxio_make_attr_table(L, &omqstat); @@ -1987,7 +1987,7 @@ luxio_mq_timedsend(lua_State *L) /* POSIX.1-2001 */ lua_pushinteger(L, mq_timedsend(mq, msg_ptr, msg_len, msg_prio, &abs_timeout)); lua_pushinteger(L, errno); - return 2; + return 2; } /**% mq_timedreceive @@ -2341,7 +2341,7 @@ luxio_getsockopt(lua_State *L) int res, r_int; char r_ifname[IFNAMSIZ]; socklen_t l; - + switch (level) { case SOL_SOCKET: switch (optname) { @@ -2359,7 +2359,7 @@ luxio_getsockopt(lua_State *L) } return 2; - + /* other options probably expect integers */ default: l = sizeof(r_int); @@ -2370,7 +2370,7 @@ luxio_getsockopt(lua_State *L) } else { lua_pushinteger(L, r_int); } - + return 2; } case IPPROTO_IP: @@ -2392,7 +2392,7 @@ luxio_getsockopt(lua_State *L) } else { lua_pushinteger(L, r_int); } - + return 2; default: @@ -2400,7 +2400,7 @@ luxio_getsockopt(lua_State *L) optname); } } - + return luaL_error(L, "unhandled socket level %d", level); } @@ -2418,7 +2418,7 @@ luxio_setsockopt(lua_State *L) const char *r_ifname; socklen_t l; size_t sz; - + switch (level) { case SOL_SOCKET: switch (optname) { @@ -2440,7 +2440,7 @@ luxio_setsockopt(lua_State *L) res = setsockopt(sockfd, level, optname, &r_int, l); lua_pushinteger(L, res); lua_pushinteger(L, errno); - + return 2; } case IPPROTO_IP: @@ -2459,7 +2459,7 @@ luxio_setsockopt(lua_State *L) res = setsockopt(sockfd, level, optname, &r_int, l); lua_pushinteger(L, res); lua_pushinteger(L, errno); - + return 2; default: @@ -2467,7 +2467,7 @@ luxio_setsockopt(lua_State *L) optname); } } - + return luaL_error(L, "unhandled socket level %d", level); } @@ -2504,7 +2504,7 @@ luxio_getaddrinfo(lua_State *L) if (node[0] == '\0') node = NULL; - + if (serv[0] == '\0') serv = NULL; @@ -2514,7 +2514,7 @@ luxio_getaddrinfo(lua_State *L) if (r < 0) return 1; - + lua_newtable(L); /* table we return with entries */ for (rp = results, c = 1; rp != NULL; rp = rp->ai_next, c++) { @@ -2531,7 +2531,7 @@ luxio_getaddrinfo(lua_State *L) lua_pushliteral(L, "ai_socktype"); lua_pushinteger(L, rp->ai_socktype); lua_rawset(L, -3); - + lua_pushliteral(L, "ai_protocol"); lua_pushinteger(L, rp->ai_protocol); lua_rawset(L, -3); @@ -2543,12 +2543,12 @@ luxio_getaddrinfo(lua_State *L) lua_pushliteral(L, "ai_addr"); luxio__makesockaddr(L, rp->ai_addr, rp->ai_addrlen); lua_rawset(L, -3); - + lua_rawseti(L, -2, c); } freeaddrinfo(results); - + return 2; } @@ -2688,13 +2688,13 @@ luxio_bitop_or(lua_State *L) { int value = luaL_checkint(L, 1); int n = lua_gettop(L); - + while (n > 1) { value |= luaL_checkint(L, n--); } - + lua_pushnumber(L, value); - + return 1; } @@ -2703,13 +2703,13 @@ luxio_bitop_and(lua_State *L) { int value = luaL_checkint(L, 1); int n = lua_gettop(L); - + while (n > 1) { value &= luaL_checkint(L, n--); } - + lua_pushnumber(L, value); - + return 1; } @@ -2718,13 +2718,13 @@ luxio_bitop_clear(lua_State *L) { int value = luaL_checkint(L, 1); int n = lua_gettop(L); - + while (n > 1) { value &= ~luaL_checkint(L, n--); } - + lua_pushnumber(L, value); - + return 1; } @@ -2733,7 +2733,7 @@ luxio_bitop_invert(lua_State *L) { int value = luaL_checkint(L, 1); int n = lua_gettop(L); - + /* Special case, passed 1 value, we invert that rather than * inverting the other bits supplied */ @@ -2744,9 +2744,9 @@ luxio_bitop_invert(lua_State *L) value ^= luaL_checkint(L, n--); } } - + lua_pushnumber(L, value); - + return 1; } @@ -2756,11 +2756,11 @@ luxio_bitop_test(lua_State *L) int value = luaL_checkint(L, 1); int goal = 0; int n = lua_gettop(L); - + while (n > 1) { goal |= luaL_checkint(L, n--); } - + lua_pushboolean(L, (value & goal) == goal); return 1; @@ -2775,9 +2775,9 @@ luxio_timeval_lt(lua_State *L) { struct timeval *a = luaL_checkudata(L, 1, LUXIO_TIMEVAL_METATABLE); struct timeval *b = luaL_checkudata(L, 2, LUXIO_TIMEVAL_METATABLE); - + lua_pushboolean(L, timercmp(a, b, <)); - + return 1; } @@ -2786,10 +2786,10 @@ luxio_timeval_le(lua_State *L) { struct timeval *a = luaL_checkudata(L, 1, LUXIO_TIMEVAL_METATABLE); struct timeval *b = luaL_checkudata(L, 2, LUXIO_TIMEVAL_METATABLE); - + /* <= is not portable, so use ! > */ lua_pushboolean(L, !timercmp(a, b, >)); - + return 1; } @@ -2798,10 +2798,10 @@ luxio_timeval_eq(lua_State *L) { struct timeval *a = luaL_checkudata(L, 1, LUXIO_TIMEVAL_METATABLE); struct timeval *b = luaL_checkudata(L, 2, LUXIO_TIMEVAL_METATABLE); - + /* == is not portable, so use ! != */ lua_pushboolean(L, !timercmp(a, b, !=)); - + return 1; } @@ -2811,12 +2811,12 @@ luxio_timeval_tostring(lua_State *L) { struct timeval *a = luaL_checkudata(L, 1, LUXIO_TIMEVAL_METATABLE); char buffer[LUXIO_TIME_BUFLEN]; - + snprintf(buffer, LUXIO_TIME_BUFLEN, "timeval: %ld.%06ld", (long)a->tv_sec, a->tv_usec); lua_pushstring(L, buffer); - + return 1; } @@ -2825,19 +2825,19 @@ luxio_timeval_index(lua_State *L) { struct timeval *a = luaL_checkudata(L, 1, LUXIO_TIMEVAL_METATABLE); const char *s = luaL_checkstring(L, 2); - + if (strcmp(s, "tv_sec") == 0) lua_pushinteger(L, a->tv_sec); else if (strcmp(s, "tv_usec") == 0) lua_pushinteger(L, a->tv_usec); else if (strcmp(s, "seconds") == 0) - lua_pushnumber(L, (lua_Number)(a->tv_sec) + + lua_pushnumber(L, (lua_Number)(a->tv_sec) + ((lua_Number)(a->tv_usec) / 1000000)); else if (strcmp(s, "useconds") == 0) lua_pushinteger(L, a->tv_usec + (a->tv_sec * 1000000)); else luaL_error(L, "Unknown field %s in timeval", s); - + return 1; } @@ -2846,7 +2846,7 @@ luxio_timeval_newindex(lua_State *L) { struct timeval *a = luaL_checkudata(L, 1, LUXIO_TIMEVAL_METATABLE); const char *s = luaL_checkstring(L, 2); - + if (strcmp(s, "tv_sec") == 0) a->tv_sec = luaL_checkinteger(L, 3); else if (strcmp(s, "tv_usec") == 0) @@ -2861,7 +2861,7 @@ luxio_timeval_newindex(lua_State *L) a->tv_usec = (suseconds_t)v % 1000000; } else luaL_error(L, "Unknown field %s in timeval", s); - + return 0; } @@ -2873,11 +2873,11 @@ luxio_timeval_add(lua_State *L) struct timeval *a = luaL_checkudata(L, 1, LUXIO_TIMEVAL_METATABLE); struct timeval *b = luaL_checkudata(L, 2, LUXIO_TIMEVAL_METATABLE); struct timeval *ret = lua_newuserdata(L, sizeof(*ret)); - + timeradd(a, b, ret); - + luxio__bless_timeval(L); - + return 1; } @@ -2887,11 +2887,11 @@ luxio_timeval_sub(lua_State *L) struct timeval *a = luaL_checkudata(L, 1, LUXIO_TIMEVAL_METATABLE); struct timeval *b = luaL_checkudata(L, 2, LUXIO_TIMEVAL_METATABLE); struct timeval *ret = lua_newuserdata(L, sizeof(*ret)); - + timersub(a, b, ret); - + luxio__bless_timeval(L); - + return 1; } @@ -2899,7 +2899,7 @@ static void luxio__bless_timeval(lua_State *L) { int create = luaL_newmetatable(L, LUXIO_TIMEVAL_METATABLE); - + if (create) { lua_pushcfunction(L, luxio_timeval_le); lua_setfield(L, -2, "__le"); @@ -2918,7 +2918,7 @@ luxio__bless_timeval(lua_State *L) lua_pushcfunction(L, luxio_timeval_sub); lua_setfield(L, -2, "__sub"); } - + lua_setmetatable(L, -2); } @@ -2926,11 +2926,11 @@ static int luxio_timeval_zero(lua_State *L) { struct timeval *r = lua_newuserdata(L, sizeof(*r)); - + timerclear(r); - + luxio__bless_timeval(L); - + return 1; } @@ -2938,17 +2938,17 @@ static int luxio_gettimeofday(lua_State *L) { struct timeval *r = lua_newuserdata(L, sizeof(*r)); - + int ret = gettimeofday(r, NULL); - + if (ret == -1) { lua_pushinteger(L, -1); lua_pushinteger(L, errno); return 2; } - + luxio__bless_timeval(L); - + return 1; } @@ -3046,7 +3046,7 @@ luxio_functions[] = { { "pollfds_setslot", luxio_pollfds_set_slot }, { "pollfds_getslot", luxio_pollfds_get_slot }, { "poll", luxio_poll }, - + { "zero_timeval", luxio_timeval_zero }, { "gettimeofday", luxio_gettimeofday }, @@ -3054,7 +3054,7 @@ luxio_functions[] = { { "exec", luxio_exec }, { "execp", luxio_execp }, { "waitpid", luxio_waitpid }, - + #define WAITPID_STATUS_ENTRY(x) { #x, luxio_##x } WAITPID_STATUS_ENTRY(WIFEXITED), WAITPID_STATUS_ENTRY(WEXITSTATUS), @@ -3074,7 +3074,7 @@ luxio_functions[] = { { "strerror", luxio_strerror }, { "_exit", luxio__exit }, - + { "setenv", luxio_setenv }, { "unsetenv", luxio_unsetenv }, { "getenv", luxio_getenv }, @@ -3091,7 +3091,7 @@ luxio_functions[] = { { "alarm", luxio_alarm }, { "pause", luxio_pause }, { "sleep", luxio_sleep }, - + { "getpid", luxio_getpid }, { "getppid", luxio_getppid }, @@ -3138,7 +3138,7 @@ luxio_bitop_functions[] = { { "binvert", luxio_bitop_invert }, { "btest", luxio_bitop_test }, { "bclear", luxio_bitop_clear }, - + { NULL, NULL } }; @@ -3160,7 +3160,7 @@ luaopen_luxio(lua_State *L) luaL_newlib(L, luxio_bitop_functions); #else luaL_register(L, "luxio", luxio_functions); - lua_createtable(L, 0, (sizeof(luxio_bitop_functions) / + lua_createtable(L, 0, (sizeof(luxio_bitop_functions) / sizeof(struct luaL_Reg)) - 1); luaL_register(L, NULL, luxio_bitop_functions); #endif |