diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-11-29 15:15:42 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-11-29 15:15:42 -0200 |
| commit | 7948b8568e226f609871918a1d614450a1a565a7 (patch) | |
| tree | e3d240f43aca62e9d9f600bfddbfd86a01453e54 | |
| parent | 61b1d9a4668286dcd43eb8771f4cdda4945d964e (diff) | |
| download | lua-7948b8568e226f609871918a1d614450a1a565a7.tar.gz lua-7948b8568e226f609871918a1d614450a1a565a7.tar.bz2 lua-7948b8568e226f609871918a1d614450a1a565a7.zip | |
when available, use '*_r' versions of 'gmtime' and 'localtime'
| -rw-r--r-- | loslib.c | 25 | ||||
| -rw-r--r-- | luaconf.h | 3 |
2 files changed, 23 insertions, 5 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) { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: luaconf.h,v 1.166 2011/11/09 14:47:14 roberto Exp roberto $ | 2 | ** $Id: luaconf.h,v 1.167 2011/11/25 12:52:27 roberto Exp roberto $ |
| 3 | ** Configuration file for Lua | 3 | ** Configuration file for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -70,6 +70,7 @@ | |||
| 70 | #define LUA_USE_ISATTY | 70 | #define LUA_USE_ISATTY |
| 71 | #define LUA_USE_POPEN | 71 | #define LUA_USE_POPEN |
| 72 | #define LUA_USE_ULONGJMP | 72 | #define LUA_USE_ULONGJMP |
| 73 | #define lUA_USE_GMTIME_R | ||
| 73 | #endif | 74 | #endif |
| 74 | 75 | ||
| 75 | 76 | ||
