| 302 | |
| 303 | |
| 304 | static int os_date (lua_State *L) { |
| 305 | size_t slen; |
| 306 | const char *s = luaL_optlstring(L, 1, "%c", &slen); |
| 307 | time_t t = luaL_opt(L, l_checktime, 2, time(NULL)); |
| 308 | const char *se = s + slen; /* 's' end */ |
| 309 | struct tm tmr, *stm; |
| 310 | if (*s == '!') { /* UTC? */ |
| 311 | stm = l_gmtime(&t, &tmr); |
| 312 | s++; /* skip '!' */ |
| 313 | } |
| 314 | else |
| 315 | stm = l_localtime(&t, &tmr); |
| 316 | if (stm == NULL) /* invalid date? */ |
| 317 | return luaL_error(L, |
| 318 | "date result cannot be represented in this installation"); |
| 319 | if (strcmp(s, "*t") == 0) { |
| 320 | lua_createtable(L, 0, 9); /* 9 = number of fields */ |
| 321 | setallfields(L, stm); |
| 322 | } |
| 323 | else { |
| 324 | char cc[4]; /* buffer for individual conversion specifiers */ |
| 325 | luaL_Buffer b; |
| 326 | cc[0] = '%'; |
| 327 | luaL_buffinit(L, &b); |
| 328 | while (s < se) { |
| 329 | if (*s != '%') /* not a conversion specifier? */ |
| 330 | luaL_addchar(&b, *s++); |
| 331 | else { |
| 332 | size_t reslen; |
| 333 | char *buff = luaL_prepbuffsize(&b, SIZETIMEFMT); |
| 334 | s++; /* skip '%' */ |
| 335 | s = checkoption(L, s, se - s, cc + 1); /* copy specifier to 'cc' */ |
| 336 | reslen = strftime(buff, SIZETIMEFMT, cc, stm); |
| 337 | luaL_addsize(&b, reslen); |
| 338 | } |
| 339 | } |
| 340 | luaL_pushresult(&b); |
| 341 | } |
| 342 | return 1; |
| 343 | } |
| 344 | |
| 345 | |
| 346 | static int os_time (lua_State *L) { |
nothing calls this directly
no test coverage detected