diff options
Diffstat (limited to 'loslib.c')
-rw-r--r-- | loslib.c | 25 |
1 files changed, 21 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: loslib.c,v 1.35 2011/06/20 16:50:59 roberto Exp roberto $ | 2 | ** $Id: loslib.c,v 1.36 2011/11/29 15:55:51 roberto Exp roberto $ |
3 | ** Standard Operating System library | 3 | ** Standard Operating System library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -58,6 +58,23 @@ | |||
58 | #endif | 58 | #endif |
59 | 59 | ||
60 | 60 | ||
61 | /* | ||
62 | ** By default, Lua uses gmtime/localtime, except when POSIX is available, | ||
63 | ** where it uses gmtime_r/localtime_r | ||
64 | */ | ||
65 | #if defined(lUA_USE_GMTIME_R) | ||
66 | |||
67 | #define l_gmtime(t,r) gmtime_r(t,r) | ||
68 | #define l_localtime(t,r) localtime_r(t,r) | ||
69 | |||
70 | #elif !defined(l_gmtime) | ||
71 | |||
72 | #define l_gmtime(t,r) ((void)r, gmtime(t)) | ||
73 | #define l_localtime(t,r) ((void)r, localtime(t)) | ||
74 | |||
75 | #endif | ||
76 | |||
77 | |||
61 | 78 | ||
62 | static int os_execute (lua_State *L) { | 79 | static int os_execute (lua_State *L) { |
63 | const char *cmd = luaL_optstring(L, 1, NULL); | 80 | const char *cmd = luaL_optstring(L, 1, NULL); |
@@ -177,13 +194,13 @@ static const char *checkoption (lua_State *L, const char *conv, char *buff) { | |||
177 | static int os_date (lua_State *L) { | 194 | static int os_date (lua_State *L) { |
178 | const char *s = luaL_optstring(L, 1, "%c"); | 195 | const char *s = luaL_optstring(L, 1, "%c"); |
179 | time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); | 196 | time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); |
180 | struct tm *stm; | 197 | struct tm tmr, *stm; |
181 | if (*s == '!') { /* UTC? */ | 198 | if (*s == '!') { /* UTC? */ |
182 | stm = gmtime(&t); | 199 | stm = l_gmtime(&t, &tmr); |
183 | s++; /* skip `!' */ | 200 | s++; /* skip `!' */ |
184 | } | 201 | } |
185 | else | 202 | else |
186 | stm = localtime(&t); | 203 | stm = l_localtime(&t, &tmr); |
187 | if (stm == NULL) /* invalid date? */ | 204 | if (stm == NULL) /* invalid date? */ |
188 | lua_pushnil(L); | 205 | lua_pushnil(L); |
189 | else if (strcmp(s, "*t") == 0) { | 206 | else if (strcmp(s, "*t") == 0) { |