From: John Hodge (sonata) Date: Fri, 7 Nov 2014 04:14:52 +0000 (+0800) Subject: Usermode/libc - Add support for %H and %M in strftime X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=a3533b90b25826cb9db8ceb1ed6448f820bfe18b;p=tpg%2Facess2.git Usermode/libc - Add support for %H and %M in strftime --- diff --git a/Usermode/Libraries/libc.so_src/time.c b/Usermode/Libraries/libc.so_src/time.c index 185af88f..611ae9b0 100644 --- a/Usermode/Libraries/libc.so_src/time.c +++ b/Usermode/Libraries/libc.so_src/time.c @@ -145,11 +145,18 @@ size_t strftime(char*restrict s, size_t maxsize, const char*restrict format, con if( *format == 0 ) break; format ++; + + // If EOS is hit on a '%', break early + if( *format == 0 ) + break; switch(*format++) { - case 0: format--; break; - case '%': ofs += _puts(s, maxsize, ofs, format-1, 1); break; - case 'd': // The day of the month as a decimal number (range 01 to 31). + // Literal '%', + case '%': + ofs += _puts(s, maxsize, ofs, format-1, 1); + break; + // The day of the month as a decimal number (range 01 to 31). + case 'd': { char tmp[2] = {'0','0'}; tmp[0] += (timeptr->tm_mday / 10) % 10; @@ -157,6 +164,24 @@ size_t strftime(char*restrict s, size_t maxsize, const char*restrict format, con ofs += _puts(s, maxsize, ofs, tmp, 2); } break; + // Two-digit 24 hour + case 'H': + { + char tmp[2] = {'0','0'}; + tmp[0] += (timeptr->tm_hour / 10) % 10; + tmp[1] += timeptr->tm_hour % 10; + ofs += _puts(s, maxsize, ofs, tmp, 2); + } + break; + // Two-digit minutes + case 'M': + { + char tmp[2] = {'0','0'}; + tmp[0] += (timeptr->tm_min / 10) % 10; + tmp[1] += timeptr->tm_min % 10; + ofs += _puts(s, maxsize, ofs, tmp, 2); + } + break; default: _SysDebug("TODO: strftime('...%%%c...')", format[-1]); break;