/* * File to document bug with localtime() setting errno despite succeeding * in Cygwin 1.3.2. * Compile on Windows NT 4 with shell command: * gcc -Wall -ansi time_bug_report.c -o time_bug_report.exe */ #include #include #include #include int main (int argc, char *argv[]) { time_t now; struct tm *tmp = (struct tm *)NULL; char *timestring = (char *)NULL; printf("Before I call anything, errno = 0x%x\n", errno); printf("(I'll reset errno to 0 before each time library call.)\n"); errno = 0; now = time(NULL); printf("time() returned 0x%x and set errno to 0x%x\n", (unsigned)now, errno); errno = 0; timestring = ctime(&now); printf("timestring() returned 0x%x and set errno to 0x%x\n", (unsigned)timestring, errno); if (timestring != (char *)NULL) { printf("Hello, it's %s", timestring); } errno = 0; tmp = localtime(&now); printf("localtime() returned 0x%x and set errno to 0x%x\n", (unsigned)tmp, errno); exit(errno); }