diff options
author | Lua Team <team@lua.org> | 2011-11-30 12:00:00 +0000 |
---|---|---|
committer | repogen <> | 2011-11-30 12:00:00 +0000 |
commit | ac1beaea25f1fec341e1edb168c63ac7131a6bdd (patch) | |
tree | 07b408b92516a459a685fdc1aca30694663051f3 /src/loslib.c | |
parent | dfa489618335f21b74e1b2040a64b28dcbe048a6 (diff) | |
download | lua-github-5.2.0-rc3.tar.gz |
Lua 5.2.0-rc35.2.0-rc3
Diffstat (limited to 'src/loslib.c')
-rw-r--r-- | src/loslib.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/loslib.c b/src/loslib.c index 585ba781..69d33e3a 100644 --- a/src/loslib.c +++ b/src/loslib.c @@ -1,5 +1,5 @@ /* -** $Id: loslib.c,v 1.35 2011/06/20 16:50:59 roberto Exp $ +** $Id: loslib.c,v 1.37 2011/11/29 17:15:42 roberto Exp $ ** Standard Operating System library ** See Copyright Notice in lua.h */ @@ -58,6 +58,23 @@ #endif +/* +** By default, Lua uses gmtime/localtime, except when POSIX is available, +** where it uses gmtime_r/localtime_r +*/ +#if defined(lUA_USE_GMTIME_R) + +#define l_gmtime(t,r) gmtime_r(t,r) +#define l_localtime(t,r) localtime_r(t,r) + +#elif !defined(l_gmtime) + +#define l_gmtime(t,r) ((void)r, gmtime(t)) +#define l_localtime(t,r) ((void)r, localtime(t)) + +#endif + + static int os_execute (lua_State *L) { const char *cmd = luaL_optstring(L, 1, NULL); @@ -177,13 +194,13 @@ static const char *checkoption (lua_State *L, const char *conv, char *buff) { static int os_date (lua_State *L) { const char *s = luaL_optstring(L, 1, "%c"); time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); - struct tm *stm; + struct tm tmr, *stm; if (*s == '!') { /* UTC? */ - stm = gmtime(&t); + stm = l_gmtime(&t, &tmr); s++; /* skip `!' */ } else - stm = localtime(&t); + stm = l_localtime(&t, &tmr); if (stm == NULL) /* invalid date? */ lua_pushnil(L); else if (strcmp(s, "*t") == 0) { @@ -274,7 +291,8 @@ static int os_exit (lua_State *L) { status = luaL_optint(L, 1, EXIT_SUCCESS); if (lua_toboolean(L, 2)) lua_close(L); - exit(status); + if (L) exit(status); /* 'if' to avoid warnings for unreachable 'return' */ + return 0; } |