What is the proper way to handle times in C code for 32-bit embedded Linux (ARMLinux) to ensure that the code continues to work properly after 03:14:07 UTC on 19 January 2038 (when a signed 32-bit time_t
overflows)? Given that time_t
is signed 32-bit on the system I have to use, what are the alternatives?
A considerable amount of googling has uncovered nothing of practical use. Everyone seems to assume that we will all be using 64-bit OSs by then, but this patently isn't true of embedded systems.
On the system I am required to use, __kernel_time_t
is defined as a long
. Which presumably means that there is no kernel facility for 64 bit time. The version of uClibc is 0.9.29.
I can't believe I'm the only one with this problem, and I don't want to reinvent the wheel.
if (timeout_time <= current_time) handle_timeout();
One should use a monotonic clock for all such things, nevertime()
orgettimeofday()
or any such thing. Of course the monotonic clock can wrap around too, unless you reboot. And of course resetting the epoch is very ugly and may break systems. I wish I had a silver bullet but there's none. – Misjudgetime_t
type fortv_sec
and are also sometimes (but not always) just based on the normal time, but without adjustments. Your best bet is a monotonic clock that returns uptime (popular choice), but lots of systems only keep track of uptime as an offset from the wall-clock time (which is quite back-asswards) which may lead to issues with time_t again. – Mundt