X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fstrftime.c;h=6d8ca0c53e8b57995a32fa5ea06533a048bcd90e;hb=b4e2cc126eeaa01f81c71bf233f7b69dba38d998;hp=569a3d448e504bca02e6b5db42721eaf747bb82b;hpb=10074829b405d5ada97315d30d400e6dd42d48ae;p=gnulib.git diff --git a/lib/strftime.c b/lib/strftime.c index 569a3d448..6d8ca0c53 100644 --- a/lib/strftime.c +++ b/lib/strftime.c @@ -46,6 +46,7 @@ %p locale's AM or PM %r time, 12-hour (hh:mm:ss [AP]M) %R time, 24-hour (hh:mm) + %s time in seconds since 00:00:00, Jan 1, 1970 (a nonstandard extension) %S second (00..61) %T time, 24-hour (hh:mm:ss) %X locale's time representation (%H:%M:%S) @@ -84,6 +85,7 @@ #endif #endif +#include #include #if defined(TM_IN_SYS_TIME) || (!defined(HAVE_TM_ZONE) && !defined(HAVE_TZNAME)) #include @@ -91,6 +93,10 @@ #include #endif +#ifndef STDC_HEADERS +time_t mktime (); +#endif + #if defined(HAVE_TZNAME) extern char *tzname[2]; #endif @@ -175,7 +181,7 @@ add_num3 (string, num, max, pad) static int add_str (to, from, max) char *to; - char *from; + const char *from; int max; { int i; @@ -185,6 +191,25 @@ add_str (to, from, max) return i; } +static int +add_num_time_t (string, max, num) + char *string; + int max; + time_t num; +{ + /* This buffer is large enough to hold the character representation + (including the trailing NUL) of any unsigned decimal quantity + whose binary representation fits in 128 bits. */ + char buf[40]; + int length; + + if (sizeof (num) > 16) + abort (); + sprintf (buf, "%lu", (unsigned long) num); + length = add_str (string, buf, max); + return length; +} + /* Return the week in the year of the time in TM, with the weeks starting on Sundays. */ @@ -330,6 +355,16 @@ strftime (string, max, format, tm) length += strftime (&string[length], max - length, "%H:%M", tm); break; + + case 's': + { + struct tm writable_tm; + writable_tm = *tm; + length += add_num_time_t (&string[length], max - length, + mktime (&writable_tm)); + } + break; + case 'S': length += add_num2 (&string[length], tm->tm_sec, max - length, pad);