1
0
Fork 0
forked from len0rd/rockbox

Lua update strftime.c from dietlibc source

Adds %F -- %Y-%m-%d
Fixes possible buffer overflow when writing final \0
Frees a bit of code on NON-RTC targets

Change-Id: I1c2600a68ee88c6c99f411ae6646861578683f90
This commit is contained in:
William Wilgus 2018-10-30 02:39:11 -04:00
parent eab73b3dee
commit 6d8d2422ea

View file

@ -55,6 +55,7 @@ again:
case 'x': src = "%b %a %d"; goto _strf;
case 'X': src = "%k:%M:%S"; goto _strf;
case 'D': src = "%m/%d/%y"; goto _strf;
case 'F': src = "%Y-%m-%d"; goto _strf;
case 'T': src = "%H:%M:%S";
_strf: p += strftime (p, (size_t)(dst+max-p), src, tm); break;
case 'a': src = sweekdays [tm->tm_wday]; goto _str;
@ -80,21 +81,19 @@ again:
case 'U': no = (tm->tm_yday - tm->tm_wday + 7) / 7; goto _no;
case 'W': no = (tm->tm_yday - (tm->tm_wday - 1 + 7) % 7 + 7) / 7; goto _no;
case 's': {
time_t t =
#if CONFIG_RTC
rb->mktime((struct tm*)tm)
#else
0
#endif
;
char buf[101];
time_t t = rb->mktime((struct tm*)tm);
char sbuf[101];
char* c;
buf[100]=0;
for (c=buf+99; c>buf; --c) {
sbuf[100]=0;
for (c=sbuf+99; c>sbuf; --c) {
*c=(t%10)+'0';
t/=10;
if (!t) break;
}
#else
char* c = "0";
#endif
src=c;
goto _str;
}
@ -129,6 +128,9 @@ again:
break;
}
if ((size_t)(p-dst)>=max) {
if (max) p[-1]=0;
} else
*p = '\0';
return p - dst;
}