]> git.sur5r.net Git - cc65/commitdiff
Call strftime instead of formatting the time manually
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Wed, 13 Nov 2002 13:28:45 +0000 (13:28 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Wed, 13 Nov 2002 13:28:45 +0000 (13:28 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@1515 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/common/asctime.c

index 3590e2462c58ffa9c7c8aa56292d3972375d2180..15450425ecda96a710797939300e99b21732014e 100644 (file)
 
 char* __fastcall__ asctime (const struct tm* timep)
 {
-    static const char days[7][4]  = {
-        "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
-    };
-    static const char months[12][4] = {
-        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-    };
     static char buf[26];
 
-    /* Create a copy of the given data and make sure it is valid */
-    struct tm t;
-    t = *timep;
-    mktime (&t);
-
-    /* Format into given buffer */
-    sprintf(buf,
-            "%s %s%3d %02d:%02d:%02d %d\n",
-           days[t.tm_wday],
-            months[t.tm_mon],
-            t.tm_mday,
-           t.tm_hour,
-            t.tm_min,
-            t.tm_sec,
-            t.tm_year + 1900);
-
-    /* Return the result */
-    return buf;
+    /* Format into given buffer and return the result */
+    return strftime (buf, sizeof (buf), "%c\n", timep)? buf : 0;
 }