X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Ftime%2Fstrftime.c;h=715a321adbde1d8e10edcd73972bc766077a2ad1;hp=2402f8cb82b8963e9c9ddb856142ab09b71c5d56;hb=761281caf431d264d568aec797095ef2c28f3910;hpb=18dee35aba1ae0fcdecb0cd11d4f3c1a0d94b51e diff --git a/functions/time/strftime.c b/functions/time/strftime.c index 2402f8c..715a321 100644 --- a/functions/time/strftime.c +++ b/functions/time/strftime.c @@ -8,8 +8,176 @@ #ifndef REGTEST -size_t strftime( char * restrict s, size_t maxsize, const char * restrict format, const struct tm * restrict timeptr ) +size_t strftime( char * _PDCLIB_restrict s, size_t maxsize, const char * _PDCLIB_restrict format, const struct tm * _PDCLIB_restrict timeptr ) { + /* + If the total number of resulting characters including the terminating null character is not + more than maxsize, the strftime function returns the number of characters placed + into the array pointed to by s not including the terminating null character. + (i.e., < maxsize) + */ + size_t rc = 0; + + while ( rc < maxsize ) + { + if ( *format != '%' ) + { + if ( ( *s++ = *format++ ) == '\0' ) + { + return rc; + } + else + { + ++rc; + } + } + else + { + char flag = 0; + switch ( *++format ) + { + case 'E': + case 'O': + flag = *format++; + break; + default: + /* EMPTY */ + break; + } + switch( *format++ ) + { + case 'a': + /* tm_wday abbreviated */ + break; + case 'A': + /* tm_wday full */ + break; + case 'b': + case 'h': + /* tm_mon abbreviated */ + break; + case 'B': + /* tm_mon full */ + break; + case 'c': + /* locale's date / time representation, %a %b %e %T %Y for C locale */ + /* 'E' for locale's alternative representation */ + break; + case 'C': + /* tm_year divided by 100, truncated to decimal (00-99) */ + /* 'E' for base year (period) in locale's alternative representation */ + break; + case 'd': + /* tm_mday as decimal (01-31) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'D': + /* %m/%d/%y */ + break; + case 'e': + /* tm_mday as decimal ( 1-31) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'F': + /* %Y-%m-%d */ + break; + case 'g': + /* last 2 digits of the week-based year as decimal (00-99) */ + break; + case 'G': + /* week-based year as decimal (e.g. 1997) */ + break; + case 'H': + /* tm_hour as 24h decimal (00-23) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'I': + /* tm_hour as 12h decimal (01-12) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'j': + /* tm_yday as decimal (001-366) */ + break; + case 'm': + /* tm_mon as decimal (01-12) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'M': + /* tm_min as decimal (00-59) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'n': + /* newline */ + break; + case 'p': + /* tm_hour locale's AM/PM designations */ + break; + case 'r': + /* tm_hour / tm_min / tm_sec as locale's 12-hour clock time, %I:%M:%S %p for C locale */ + break; + case 'R': + /* %H:%M */ + break; + case 'S': + /* tm_sec as decimal (00-60) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 't': + /* tabulator */ + break; + case 'T': + /* %H:%M:%S */ + break; + case 'u': + /* tm_wday as decimal (1-7) with Monday == 1 */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'U': + /* week number of the year (first Sunday as the first day of week 1) as decimal (00-53) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'V': + /* week number as decimal (01-53) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'w': + /* tm_wday as decimal number (0-6) with Sunday == 0 */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'W': + /* week number of the year (first Monday as the first day of week 1) as decimal (00-53) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'x': + /* locale's date representation, %m/%d/%y for C locale */ + /* 'E' for locale's alternative representation */ + break; + case 'X': + /* locale's time representation, %T for C locale */ + /* 'E' for locale's alternative representation */ + break; + case 'y': + /* last 2 digits of tm_year as decimal (00-99) */ + /* 'E' for offset from %EC (year only) in locale's alternative representation */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'Y': + /* tm_year as decimal (e.g. 1997) */ + /* 'E' for locale's alternative representation */ + break; + case 'z': + /* tm_isdst / UTC offset in ISO8601 format (e.g. -0430 meaning 4 hours 30 minutes behind Greenwich), or no characters */ + break; + case 'Z': + /* tm_isdst / locale's time zone name or abbreviation, or no characters */ + break; + case '%': + /* '%' character */ + break; + } + } + } + return 0; } @@ -21,7 +189,8 @@ size_t strftime( char * restrict s, size_t maxsize, const char * restrict format int main( void ) { - return NO_TESTDRIVER; + TESTCASE( NO_TESTDRIVER ); + return TEST_RESULTS; } #endif