According to this overview in order to compile Y2038 conform old code, we just need to add the preprocessor macro __USE_TIME_BITS64
to gcc
, but that does not seem to work on an ARMv7 board with Debian 12 (bookworm):
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
int main(void)
{
struct stat sb;
printf("sizeof time_t: %zu\n", sizeof(time_t));
printf("sizeof stat timestamp: %zu\n", sizeof(sb.st_atime));
return 0;
}
time_t is still 4 bytes:
root@debian:~# gcc -D__USE_TIME_BITS64 time.c -o time
root@debian:~# ./time
sizeof time_t: 4
sizeof stat timestamp: 4
root@debian:~#
glibc is 2.33, what am I doing wrong here?
CodePudding user response:
According to this post (which is getting a little old now, and some parts of which are probably no longer relevant):
... defining
_TIME_BITS=64
would cause all time functions to use 64-bit times by default. The_TIME_BITS=64
option is implemented by transparently mapping the standard functions and types to their internal 64-bit variants. Glibc would also set__USE_TIME_BITS64
, which user code can test for to determine if the 64-bit variants are available.
Presumably, this includes making time_t
64 bit.
So if your version of glibc supports this at all, it looks like you're setting the wrong macro. You want:
-D_TIME_BITS=64