This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hi Joseph, > On Wed, 18 Sep 2019, Alistair Francis wrote: > > > +#include <endian.h> > > > > /* POSIX.1b structure for a time value. This is like a `struct > > timeval' but has nanoseconds instead of microseconds. */ > > struct timespec > > { > > __time_t tv_sec; /* Seconds. */ > > +#if __WORDSIZE == 64 \ > > + || (defined __SYSCALL_WORDSIZE && __SYSCALL_WORDSIZE == 64) > > __syscall_slong_t tv_nsec; /* Nanoseconds. */ > > +#else > > +# if BYTE_ORDER == BIG_ENDIAN > > + __int32_t tv_pad; /* Padding */ > > + __syscall_slong_t tv_nsec; /* Nanoseconds */ > > +# else > > + __int32_t tv_nsec; /* Nanoseconds */ > > + __syscall_slong_t tv_pad; /* Padding */ > > +# endif > > +#endif > Just one more question - am I correct that the above code will increase the overall sizeof(struct timespec) to 12 for machines with __WORDSIZE == 32 ? I guess that now such machine have sizeof(struct timespec) = 8 ? However, this shouldn't be a problem (unless some user space SW uses this data in an unusual way...). > The padding must be an *unnamed bit-field* so that { tv_sec, tv_nsec > } initializers (common in practice even if not officially supported > by the standards) continue to work. Also, I think you should just > use "long int" for tv_nsec in the case where there is padding, as the > standard-defined type (and then the padding can be "int: 32", so > avoiding any dependence on whether compilers support non-int > bit-fields). Certainly the choice of types for tv_nsec and padding > should not depend on the endianness (the patch above is using > __int32_t for the first field and __syscall_slong_t for the second, > regardless of which is tv_nsec and which is padding). > > There are namespace issues when changing installed headers. You > can't use macros such as BYTE_ORDER or BIG_ENDIAN because they aren't > in the standard-reserved namespaces. > > Unfortunately the definitions of __LITTLE_ENDIAN and __BIG_ENDIAN are > in <endian.h> (__BYTE_ORDER is in the architecture-specific > <bits/endian.h>), and while the non-reserved names therein are all > conditional on __USE_MISC, I don't think we really want to start > exporting them from every header that uses struct timespec. My > inclination would be to have a separate bits/ header that only > defines the __LITTLE_ENDIAN / __BIG_ENDIAN / __PDP_ENDIAN macros (or > that defines those and includes the architecture-specific header for > __BYTE_ORDER), so that other headers can test endianness without > bringing in all the other __USE_MISC endian-related macros from > <endian.h>, but Zack might advise on how such changes would fit into > his header cleanups. > Best regards, Lukasz Majewski -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
Attachment:
pgpFnwmzGN6B1.pgp
Description: OpenPGP digital signature
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |