summaryrefslogtreecommitdiff
path: root/src/loslib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/loslib.c')
-rw-r--r--[-rwxr-xr-x]src/loslib.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/loslib.c b/src/loslib.c
index 585ba78..881667d 100755..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.38 2011/11/30 12:35:05 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;
}