--- lposix.c 2003-11-06 00:23:48 +0000 +++ lposix.c 2003-12-02 22:22:38 +0000 @@ -599,7 +599,7 @@ clock_t elapsed; }; -#define pushtime(L,x) lua_pushnumber(L,((lua_Number)x)/CLK_TCK) +#define pushtime(L,x) lua_pushnumber(L,((lua_Number)x)/CLOCKS_PER_SEC) static int Ftimes(lua_State *L, int i, const void *data) { @@ -620,7 +620,7 @@ "utime", "stime", "cutime", "cstime", "elapsed", NULL }; -#define storetime(L,name,x) storenumber(L,name,(lua_Number)x/CLK_TCK) +#define storetime(L,name,x) storenumber(L,name,(lua_Number)x/CLOCKS_PER_SEC) static int Ptimes(lua_State *L) /** times() */ { @@ -754,6 +754,38 @@ return doselection(L, 1, Ssysconf, Fsysconf, NULL); } +static int Pmkstemp(lua_State *L) +{ + const char *path; + char *dynpath; + int fd; + FILE **f; + + path = luaL_checkstring(L, 1); + if (path == NULL) + return 0; + dynpath = strdup(path); + fd = mkstemp(dynpath); + f = (FILE**)lua_newuserdata(L, sizeof(FILE*)); + if (f == NULL) { + close(fd); + free(dynpath); + return 0; + } + *f = fdopen(fd, "a+"); + lua_pushstring(L, dynpath); + free(dynpath); + luaL_getmetatable(L, "FILE*"); + if (lua_isnil(L, -1)) { + lua_pop(L, 1); + luaL_error(L, "FILE* metatable not available " + "(io not loaded?)"); + } else { + lua_setmetatable(L, -3); + } + return 2; +} + static const luaL_reg R[] = { @@ -794,6 +826,7 @@ {"unlink", Punlink}, {"utime", Putime}, {"wait", Pwait}, + {"mkstemp", Pmkstemp}, #ifdef linux {"setenv", Psetenv},