summaryrefslogtreecommitdiff
path: root/src/loslib.c
diff options
context:
space:
mode:
authorLua Team <team@lua.org>2007-03-23 12:00:00 +0000
committerrepogen <>2007-03-23 12:00:00 +0000
commit7e7bc7c7c7f3301a5f837579b81bcac4a2f9cccc (patch)
tree1038a02147bfbda052210f2b53fa1801b63254eb /src/loslib.c
parent72847ae02f73ea86c1a0d5778a9bc982cdccb821 (diff)
downloadlua-github-7e7bc7c7c7f3301a5f837579b81bcac4a2f9cccc.tar.gz
Lua 5.1.2-rc15.1.2-rc1
Diffstat (limited to 'src/loslib.c')
-rw-r--r--src/loslib.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/loslib.c b/src/loslib.c
index 7c6c5d61..fdda4741 100644
--- a/src/loslib.c
+++ b/src/loslib.c
@@ -1,5 +1,5 @@
/*
-** $Id: loslib.c,v 1.19 2006/04/26 18:19:49 roberto Exp $
+** $Id: loslib.c,v 1.20 2006/09/19 13:57:08 roberto Exp $
** Standard Operating System library
** See Copyright Notice in lua.h
*/
@@ -146,11 +146,22 @@ static int os_date (lua_State *L) {
setboolfield(L, "isdst", stm->tm_isdst);
}
else {
- char b[256];
- if (strftime(b, sizeof(b), s, stm))
- lua_pushstring(L, b);
- else
- return luaL_error(L, LUA_QL("date") " format too long");
+ char cc[3];
+ luaL_Buffer b;
+ cc[0] = '%'; cc[2] = '\0';
+ luaL_buffinit(L, &b);
+ for (; *s; s++) {
+ if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */
+ luaL_addchar(&b, *s);
+ else {
+ size_t reslen;
+ char buff[200]; /* should be big enough for any conversion result */
+ cc[1] = *(++s);
+ reslen = strftime(buff, sizeof(buff), cc, stm);
+ luaL_addlstring(&b, buff, reslen);
+ }
+ }
+ luaL_pushresult(&b);
}
return 1;
}