diff options
Diffstat (limited to 'loslib.c')
-rw-r--r-- | loslib.c | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: loslib.c,v 1.19 2006/04/26 18:19:49 roberto Exp roberto $ | 2 | ** $Id: loslib.c,v 1.20 2006/09/19 13:57:08 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 | */ |
@@ -148,15 +148,25 @@ static int os_date (lua_State *L) { | |||
148 | else { | 148 | else { |
149 | char cc[3]; | 149 | char cc[3]; |
150 | luaL_Buffer b; | 150 | luaL_Buffer b; |
151 | cc[0] = '%'; cc[2] = '\0'; | 151 | cc[0] = '%'; |
152 | luaL_buffinit(L, &b); | 152 | luaL_buffinit(L, &b); |
153 | for (; *s; s++) { | 153 | for (; *s; s++) { |
154 | if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */ | 154 | if (*s != '%') /* no conversion specifier? */ |
155 | luaL_addchar(&b, *s); | 155 | luaL_addchar(&b, *s); |
156 | else { | 156 | else { |
157 | size_t reslen; | 157 | size_t reslen; |
158 | int i = 1; | ||
158 | char buff[200]; /* should be big enough for any conversion result */ | 159 | char buff[200]; /* should be big enough for any conversion result */ |
159 | cc[1] = *(++s); | 160 | if (*(++s) != '\0' && strchr(LUA_STRFTIMEPREFIX, *s)) |
161 | cc[i++] = *(s++); | ||
162 | if (*s != '\0' && strchr(LUA_STRFTIMEOPTIONS, *s)) | ||
163 | cc[i++] = *s; | ||
164 | else { | ||
165 | const char *msg = lua_pushfstring(L, | ||
166 | "invalid conversion specifier '%%%c'", *s); | ||
167 | return luaL_argerror(L, 1, msg); | ||
168 | } | ||
169 | cc[i] = '\0'; | ||
160 | reslen = strftime(buff, sizeof(buff), cc, stm); | 170 | reslen = strftime(buff, sizeof(buff), cc, stm); |
161 | luaL_addlstring(&b, buff, reslen); | 171 | luaL_addlstring(&b, buff, reslen); |
162 | } | 172 | } |