64-bit Unix timestamp conversion

后端 未结 5 1821
野趣味
野趣味 2020-12-16 18:00

Is there any C++ implementation of 64-bit Unix timestamp conversions for 32-bit systems? I need to convert struct tm to 64-bit integer and vice versa, including

5条回答
  •  北海茫月
    2020-12-16 19:02

    64-bit time support on 32-bit Linux was first introduced in the 5.1 kernel with the addition of the new *time64 syscalls (because changing the return type of old system calls breaks old applications). Check this table and you'll see that those syscalls are only available on 32-bit platforms.

    But that's only support from the kernel side. You can call clock_gettime64 directly (from inline assembly, or from C with syscall() function) to get the current time but you'll need Linux-specific code because there's no glibc support yet. For full userspace support you must be on Linux 5.6 or higher along with musl 1.2+ or glibc 2.32+. Just rebuild your code and time_t will become 64-bit long. Now code that uses time_t will become completely portable

    • All user space must be compiled with a 64-bit time_t, which will be supported in the coming musl-1.2 and glibc-2.32 releases, along with installed kernel headers from linux-5.6 or higher.

    • Applications that use the system call interfaces directly need to be ported to use the time64 syscalls added in linux-5.1 in place of the existing system calls. This impacts most users of futex() and seccomp() as well as programming languages that have their own runtime environment not based on libc.

    https://lkml.org/lkml/2020/1/29/355?anz=web

    For more information read

    • Approaching the kernel year-2038 end game
    • Discussion on how to solve Y2038 problem: 2038 is closer than it seems
    • 64-bit time symbol handling in the GNU C Library
    • glibc Y2038 Proofness Design
    • Change time_t and clock_t to 64 bit

提交回复
热议问题