[klibc] [klibc:time64] time: Use 64-bit time types on all architectures

Ben Hutchings ben at decadent.org.uk
Sun Jan 15 11:47:55 PST 2023


On Sat, 2023-01-14 at 23:36 +0100, Arnd Bergmann wrote:
> 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.

Thanks.  I'll follow what glibc does.

Ben.

-- 
Ben Hutchings
One of the nice things about standards is that
there are so many of them.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <https://lists.zytor.com/archives/klibc/attachments/20230115/31fff930/attachment.sig>


More information about the klibc mailing list