Browse code

core: add support for time64 libc

libcs are implementing changes to fix the year 2038 issue on 32 bit
platforms (see [1]). musl libc already went ahead and implemented it,
starting with musl-1.2.0 (see [2]).

This commit adds a new definition to src/core/dprint.h:

TIME_T_INT_FMT

If __USE_TIME_BITS64 is defined (by a time64 libc, see [1]), it is set
to the proper conversion for type int64_t, PRId64. If __USE_TIME_BITS64
is not defined, the status quo remains unchanged ("%ld" is used).

Example warning when not using TIME_T_INT_FMT while compiling for a 32
bit target using a time64 libc:

In file included from auth_identity.c:50:
auth_identity.c: In function 'check_date':
../../core/dprint.h:316:73: warning: format '%ld' expects argument of type 'long int', but argument 11 has type 'time_t' {aka 'long long int'} [-Wformat=]
316 | fprintf(stderr, "%2d(%d) %s: %.*s%s%s%s" fmt, \
| ^~~~~~~~~~~~~~~~~~~~~~~~
../../core/dprint.h:340:25: note: in expansion of macro 'LOG_FX'
340 | LOG_FX(facility, level, lname, prefix, _FUNC_NAME_, fmt, ## args)
| ^~~~~~
../../core/dprint.h:346:25: note: in expansion of macro 'LOG_FL'
346 | LOG_FL(facility, level, NULL, prefix, fmt, ## args)
| ^~~~~~
../../core/dprint.h:349:25: note: in expansion of macro 'LOG_FP'
349 | LOG_FP(DEFAULT_FACILITY, (level), LOC_INFO, fmt, ## args)
| ^~~~~~
auth_identity.c:594:17: note: in expansion of macro 'LOG'
594 | LOG(L_INFO, "AUTH_IDENTITY VERIFIER: Outdated date header value (%ld sec)\n", tnow - tmsg + glb_iauthval);
| ^~~

[1] https://sourceware.org/glibc/wiki/Y2038ProofnessDesign
[2] https://musl.libc.org/time64.html

Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>

Sebastian Kemper authored on 22/10/2021 23:23:40
Showing 1 changed files
... ...
@@ -31,10 +31,18 @@
31 31
 #include <assert.h>
32 32
 #include <syslog.h>
33 33
 #include <stdio.h> /* stderr, fprintf() */
34
+#include <sys/time.h> /* __USE_TIME_BITS64 */
34 35
 
35 36
 #include "compiler_opt.h"
36 37
 #include "cfg_core.h"
37 38
 
39
+#ifndef TIME_T_INT_FMT
40
+#ifdef __USE_TIME_BITS64
41
+#define TIME_T_INT_FMT PRId64
42
+#else
43
+#define TIME_T_INT_FMT "ld"
44
+#endif
45
+#endif
38 46
 
39 47
 /** dicover the function name */
40 48
 /* C >= 99 has __func__, older gcc versions have __FUNCTION__ */