[klibc] [klibc:time64] time: Use 64-bit time types on all architectures
Arnd Bergmann
arnd at arndb.de
Sat Jan 14 14:36:54 PST 2023
On Sat, Jan 14, 2023, at 23:03, klibc-bot for Ben Hutchings wrote:
>
> #include <klibc/extern.h>
> +#include <klibc/endian.h>
> #include <stddef.h>
> #include <sys/types.h>
> -#include <linux/time.h>
> +
> +struct timespec {
> + __kernel_time64_t tv_sec;
> +#if __BYTE_ORDER == __BIG_ENDIAN && __BITS_PER_LONG == 32
> + long __tv_pad;
> +#endif
> + long tv_nsec;
> +#if __BYTE_ORDER == __LITTLE_ENDIAN && __BITS_PER_LONG == 32
> + long __tv_pad;
> +#endif
> +};
The problem with this definition is applications doing things like
struct timespec ts = { 0, 5000 }; /* 5 µs */
which on big-endian architectures ends up leaving tv_nsec
set to zero and the padding set to an invalid number.
This could either use the definition from glibc with an
unnamed bitfield, or the __kernel_timespec definition using
a 64-bit tv_nsec that is not C99 compliant but should just
work.
Arnd
More information about the klibc
mailing list