#include #include #include /* #define OLD_NAMES */ #ifdef OLD_NAMES /* Define this on Solaris */ #define FIRST_NAME "US/Eastern" #define SECOND_NAME "US/Pacific" #else /* Proper Olson tzdata names. */ #define FIRST_NAME "America/New_York" #define SECOND_NAME "America/Los_Angeles" #endif int main() { struct tm* test_tm; time_t then = 988989060; char buf[256]; /* Compatibility names are used, rather than new Olson names, so as to * test on Solaris. */ if (putenv("TZ=" FIRST_NAME) != 0) { fprintf(stderr, "putenv failed (1)\n"); exit(1); } if ((test_tm = localtime(&then)) == NULL) { fprintf(stderr, "localtime failed\n"); exit(1); } if (strftime(buf, sizeof(buf), "%a %d %h %H:%M:%S %Y %Z", test_tm) == 0) { fprintf(stderr, "strftime failed (1)\n"); exit(1); } printf("%s\n", buf); if (putenv("TZ=" SECOND_NAME) != 0) { fprintf(stderr, "putenv failed (2)\n"); exit(1); } tzset(); if (strftime(buf, sizeof(buf), "%a %d %h %H:%M:%S %Y %Z", test_tm) == 0) { fprintf(stderr, "strftime failed (2)\n"); exit(1); } printf("%s\n", buf); test_tm->tm_isdst = -1; if (mktime(test_tm) == -1) { fprintf(stderr, "mktime failed\n"); exit(1); } if (strftime(buf, sizeof(buf), "%a %d %h %H:%M:%S %Y %Z", test_tm) == 0) { fprintf(stderr, "strftime failed (3)\n"); exit(1); } printf("%s\n", buf); exit(0); }