Usermode/libc - Add support for %H and %M in strftime
authorJohn Hodge (sonata) <[email protected]>
Fri, 7 Nov 2014 04:14:52 +0000 (12:14 +0800)
committerJohn Hodge (sonata) <[email protected]>
Fri, 7 Nov 2014 04:14:52 +0000 (12:14 +0800)
Usermode/Libraries/libc.so_src/time.c

index 185af88..611ae9b 100644 (file)
@@ -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;

UCC git Repository :: git.ucc.asn.au