1 /* this tests tries to call strftime() with a date > 2038 2 * to see if it works correctly. 3 */ 4 #include <time.h> 5 #include <stdio.h> 6 #include <stdlib.h> 7 8 int main(void) 9 { 10 char buff[256]; 11 time_t now = time(NULL); 12 struct tm tm = *localtime(&now); 13 14 tm.tm_year = 2039 - 1900; 15 16 /* "%s" is the number of seconds since the epoch */ 17 if (strftime(buff, sizeof buff, "%s", &tm) == 0) { 18 fprintf(stderr, "strftime() returned 0\n"); 19 exit(EXIT_FAILURE); 20 } 21 printf("seconds since epoch: %s\n", buff); 22 23 /* a 32-bit limited implementation will return a negative number */ 24 if (buff[0] == '-') { 25 fprintf(stderr, "FAIL\n"); 26 exit(EXIT_FAILURE); 27 } 28 29 /* "%c" is the usual date string for the current locale */ 30 if (strftime(buff, sizeof buff, "%c", &tm) == 0) { 31 fprintf(stderr, "strftime() returned 0\n"); 32 exit(EXIT_FAILURE); 33 } 34 printf("date string : %s\n", buff); 35 return 0; 36 } 37