| 281 | |
| 282 | |
| 283 | static int os_date (lua_State *L) { |
| 284 | size_t slen; |
| 285 | const char *s = luaL_optlstring(L, 1, "%c", &slen); |
| 286 | time_t t = luaL_opt(L, l_checktime, 2, time(NULL)); |
| 287 | const char *se = s + slen; /* 's' end */ |
| 288 | struct tm tmr, *stm; |
| 289 | if (*s == '!') { /* UTC? */ |
| 290 | stm = l_gmtime(&t, &tmr); |
| 291 | s++; /* skip '!' */ |
| 292 | } |
| 293 | else |
| 294 | stm = l_localtime(&t, &tmr); |
| 295 | if (stm == NULL) /* invalid date? */ |
| 296 | return luaL_error(L, |
| 297 | "time result cannot be represented in this installation"); |
| 298 | if (strcmp(s, "*t") == 0) { |
| 299 | lua_createtable(L, 0, 9); /* 9 = number of fields */ |
| 300 | setallfields(L, stm); |
| 301 | } |
| 302 | else { |
| 303 | char cc[4]; /* buffer for individual conversion specifiers */ |
| 304 | luaL_Buffer b; |
| 305 | cc[0] = '%'; |
| 306 | luaL_buffinit(L, &b); |
| 307 | while (s < se) { |
| 308 | if (*s != '%') /* not a conversion specifier? */ |
| 309 | luaL_addchar(&b, *s++); |
| 310 | else { |
| 311 | size_t reslen; |
| 312 | char *buff = luaL_prepbuffsize(&b, SIZETIMEFMT); |
| 313 | s++; /* skip '%' */ |
| 314 | s = checkoption(L, s, se - s, cc + 1); /* copy specifier to 'cc' */ |
| 315 | reslen = strftime(buff, SIZETIMEFMT, cc, stm); |
| 316 | luaL_addsize(&b, reslen); |
| 317 | } |
| 318 | } |
| 319 | luaL_pushresult(&b); |
| 320 | } |
| 321 | return 1; |
| 322 | } |
| 323 | |
| 324 | |
| 325 | static int os_time (lua_State *L) { |
nothing calls this directly
no test coverage detected