Browse Source

when available, use '*_r' versions of 'gmtime' and 'localtime'

pull/9/head
Roberto Ierusalimschy 13 years ago
parent
commit
7948b8568e
  1. 25
      loslib.c
  2. 3
      luaconf.h

25
loslib.c

@ -1,5 +1,5 @@
/*
** $Id: loslib.c,v 1.35 2011/06/20 16:50:59 roberto Exp roberto $
** $Id: loslib.c,v 1.36 2011/11/29 15:55:51 roberto Exp roberto $
** 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) {

3
luaconf.h

@ -1,5 +1,5 @@
/*
** $Id: luaconf.h,v 1.166 2011/11/09 14:47:14 roberto Exp roberto $
** $Id: luaconf.h,v 1.167 2011/11/25 12:52:27 roberto Exp roberto $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
@ -70,6 +70,7 @@
#define LUA_USE_ISATTY
#define LUA_USE_POPEN
#define LUA_USE_ULONGJMP
#define lUA_USE_GMTIME_R
#endif

Loading…
Cancel
Save