2024-01-24 16:45:32 +00:00
|
|
|
/* 2038 test
|
|
|
|
This is OK on 64-bit systems and mingw64
|
|
|
|
Does fail when compiled with gcc -m32 -o 2038 2038.c
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2024-01-24 22:13:54 +00:00
|
|
|
int test2038(void)
|
2024-01-24 16:45:32 +00:00
|
|
|
{
|
|
|
|
time_t x;
|
|
|
|
|
2024-01-24 22:13:54 +00:00
|
|
|
//printf("sizeof(time_t)=%d\n", (int)sizeof(time_t));
|
|
|
|
|
2024-01-24 16:45:32 +00:00
|
|
|
x = (time_t)((1U << 31) - 1);
|
2024-01-24 22:13:54 +00:00
|
|
|
//printf("x=%lu\n", (unsigned long)x);
|
2024-01-24 16:45:32 +00:00
|
|
|
char *s = ctime(&x);
|
|
|
|
|
2024-01-24 22:13:54 +00:00
|
|
|
//printf("%s\n", s);
|
|
|
|
//printf("x=%lu\n", (unsigned long)x);
|
2024-01-24 16:45:32 +00:00
|
|
|
if (!strstr(s, "2038")) { return 1; }
|
|
|
|
|
|
|
|
x += 1;
|
|
|
|
s = ctime(&x);
|
|
|
|
|
2024-01-24 22:13:54 +00:00
|
|
|
//printf("x=%lu\n", (unsigned long)x);
|
|
|
|
//printf("%s\n", s);
|
2024-01-24 16:45:32 +00:00
|
|
|
if (!strstr(s, "2038")) { return 1; }
|
|
|
|
|
2024-01-24 22:13:54 +00:00
|
|
|
//printf("x=%lu\n", (unsigned long)x);
|
|
|
|
//printf("%s\n", s);
|
2024-01-24 16:45:32 +00:00
|
|
|
x += 1;
|
|
|
|
s = ctime(&x);
|
|
|
|
|
|
|
|
if (!strstr(s, "2038")) { return 1; }
|
|
|
|
|
2024-01-24 22:13:54 +00:00
|
|
|
//printf("%s\n", s);
|
2024-01-24 16:45:32 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2024-01-24 22:13:54 +00:00
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
return test2038();
|
|
|
|
}
|