1 --- lposix.c.orig Thu Nov 6 03:23:48 2003
2 +++ lposix.c Mon Apr 4 17:30:55 2005
14 #define MYNAME "posix"
15 -#define MYVERSION MYNAME " library for " LUA_VERSION " / Nov 2003"
16 +#define MYVERSION "2005.0327"
20 +#include "lua50/lua.h"
21 +#include "lua50/lauxlib.h"
26 return pusherror(L, info);
30 + * This function is adapted from liolib.c: push a FILE * onto the
31 + * Lua stack as a file object that Lua's file module understands.
33 +static void pushfileptr(lua_State *L, FILE *f)
37 + pf = (FILE **)lua_newuserdata(L, sizeof(FILE *));
39 + luaL_getmetatable(L, "FILE*");
40 + lua_setmetatable(L, -2);
43 static void badoption(lua_State *L, int i, const char *what, int option)
50 +static int Pmkstemp(lua_State *L) /** mkstemp(template) */
56 + if ((tpl = strdup(luaL_checkstring(L, 1))) == NULL) {
58 + lua_pushnumber(L, ENOMEM);
62 + f = fdopen(fd, "w+");
65 + lua_pushnumber(L, errno);
71 + lua_pushstring(L, tpl);
77 static int Pexec(lua_State *L) /** exec(path,[args]) */
79 const char *path = luaL_checkstring(L, 1);
84 +static int Pnanosleep(lua_State *L) /** nanosleep(secs,[nanosecs]) */
89 + sec = lua_tonumber(L, 1);
90 + nsec = lua_tonumber(L, 2);
93 + * Any fractional part of the seconds value should
94 + * slide over into the nanoseconds value.
96 + nsec += (sec - floor(sec)) * 1000000000.0;
99 + * Don't allow overflow.
101 + if (sec > 1000000000.0) {
102 + sec = 1000000000.0;
104 + while (nsec > 1000000000.0) {
105 + nsec -= 1000000000.0;
112 + lua_pushnumber(L, nanosleep(&ts, NULL));
118 static int Pputenv(lua_State *L) /** putenv(string) */
125 + {"mkstemp", Pmkstemp},
126 + {"nanosleep", Pnanosleep},
127 {"pathconf", Ppathconf},
129 {"readlink", Preadlink},
131 lua_pushliteral(L,MYVERSION);
136 +LUALIB_API int luaopen_lposix (lua_State *L)
138 + return luaopen_posix(L);