This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: PATCH [3/n]: Add __snseconds_t and __SNSECONDS_T_TYPE
On Thu, Mar 15, 2012 at 1:47 PM, Paul Eggert <eggert@cs.ucla.edu> wrote:
> On 03/15/2012 01:26 PM, H.J. Lu wrote:
>> ?struct timespec
>> ? ?{
>> ? ? ?__time_t tv_sec; ? ? ? ? /* Seconds. ?*/
>> - ? ?long int tv_nsec; ? ? ? ? ? ? ? ?/* Nanoseconds. ?*/
>> + ? ?__snseconds_t tv_nsec; ? /* Nanoseconds. ?*/
>> ? ?};
>
> This patch does not look right. ?POSIX says that tv_nsec must
> be of type 'long'; it cannot be of type 'long long'. ?See
> <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/time.h.html>.
>
> Instead, I suggest redoing the patch so that there is a 4-byte
> filler in the data structure on x32. ?There should be no need
> to introduce __snseconds_t or __SNSECONDS_T_TYPE; just use
> 'long'. ?When passing the data structure to the kernel, you can
> sign-extend tv_nsec into the filler. ?You can ignore the filler
> when getting the data structure back from the kernel, since it
> should always be appropriately sign-extended.
timespec is used in quite a few system calls. Checking all places
which need to sign-extend is quite complex. What is the real
consequence of using long long on tv_nsec, except for not POSIX
compliant? Will it lead to wrong code?
--
H.J.