diff options
| -rw-r--r-- | bugs | 9 | ||||
| -rw-r--r-- | loslib.c | 23 |
2 files changed, 26 insertions, 6 deletions
| @@ -1143,6 +1143,15 @@ patch = [[ | |||
| 1143 | 1143 | ||
| 1144 | 1144 | ||
| 1145 | Bug{ | 1145 | Bug{ |
| 1146 | what = [[os.date throws an error when result is the empty string]], | ||
| 1147 | report = [[ ]], | ||
| 1148 | since = [[4.0]], | ||
| 1149 | example = [[print(os.date(""))]], | ||
| 1150 | patch = [[ ]], | ||
| 1151 | } | ||
| 1152 | |||
| 1153 | |||
| 1154 | Bug{ | ||
| 1146 | what = [[ ]], | 1155 | what = [[ ]], |
| 1147 | report = [[ ]], | 1156 | report = [[ ]], |
| 1148 | since = [[ ]], | 1157 | since = [[ ]], |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: loslib.c,v 1.18 2006/03/09 18:08:22 roberto Exp roberto $ | 2 | ** $Id: loslib.c,v 1.19 2006/04/26 18:19:49 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 | */ |
| @@ -146,11 +146,22 @@ static int os_date (lua_State *L) { | |||
| 146 | setboolfield(L, "isdst", stm->tm_isdst); | 146 | setboolfield(L, "isdst", stm->tm_isdst); |
| 147 | } | 147 | } |
| 148 | else { | 148 | else { |
| 149 | char b[256]; | 149 | char cc[3]; |
| 150 | if (strftime(b, sizeof(b), s, stm)) | 150 | luaL_Buffer b; |
| 151 | lua_pushstring(L, b); | 151 | cc[0] = '%'; cc[2] = '\0'; |
| 152 | else | 152 | luaL_buffinit(L, &b); |
| 153 | return luaL_error(L, LUA_QL("date") " format too long"); | 153 | for (; *s; s++) { |
| 154 | if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */ | ||
| 155 | luaL_addchar(&b, *s); | ||
| 156 | else { | ||
| 157 | size_t reslen; | ||
| 158 | char buff[200]; /* should be big enough for any conversion result */ | ||
| 159 | cc[1] = *(++s); | ||
| 160 | reslen = strftime(buff, sizeof(buff), cc, stm); | ||
| 161 | luaL_addlstring(&b, buff, reslen); | ||
| 162 | } | ||
| 163 | } | ||
| 164 | luaL_pushresult(&b); | ||
| 154 | } | 165 | } |
| 155 | return 1; | 166 | return 1; |
| 156 | } | 167 | } |
