💾 Archived View for thrig.me › blog › 1901 › 12 › 13 › rollover.c captured on 2023-05-24 at 19:04:18.
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
// rollover - emit dates across the 32-bit unix epoch rollover #include <sys/types.h> #include <limits.h> #include <stdint.h> #include <stdio.h> #include <time.h> char buf[80]; void showtime(struct tm *tm) { strftime(buf, 79, "%Y-%m-%d %H:%M:%S", tm); printf("%s\n", buf); } int main(void) { struct tm *when; // OpenBSD already has a 64-bit epoch counter so we instead // force the use of a 32-bit counter int32_t nau = INT_MAX; time_t epoch = nau; when = gmtime(&epoch); showtime(when); nau++; epoch = nau; when = gmtime(&epoch); showtime(when); return 0; }