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]

Re: [PATCH v9] y2038: Provide conversion helpers for struct __timespec64


Hi Joseph,

> On Thu, 26 Sep 2019, Lukasz Majewski wrote:
> 
> > Those functions allow easy conversion between Y2038 safe struct
> > __timespec64 and other time related data structures (like struct
> > timeval).
> > 
> > * include/time.h (valid_timeval_to_timespec64): Add.
> > * include/time.h (valid_timespec_to_timespec64): Likewise.
> > * include/time.h (valid_timespec64_to_timespec): Likewise.
> > * include/time.h (valid_timespec64_to_timeval): Likewise.
> > * include/time.h (IS_VALID_NANOSECONDS): Likewise.
> > * include/time.h (timespec_to_timespec64): Likewise.
> > * include/time.h (timespec64_to_timespec): Likewise.
> > * include/time.h (timespec64_to_timeval): Likewise.  
> 
> OK, though we'll need to watch users of these interfaces carefully to
> see if timespec64_to_timespec and timespec64_to_timeval are the best 
> interfaces for the contexts in which they are used.  (The issue is
> that they return false in two different cases, invalid nanoseconds
> which would typically be an EINVAL error and out-of-range seconds
> which would be EOVERFLOW.  So in any case where the caller needs to
> distinguish those conditions to determine what value to use for
> errno, it would need to repeat one of the checks from those
> functions.  But maybe the compiler could optimize the code generated
> so it doesn't actually end up with a duplicate of the nanoseconds
> range test.)
> 

So then maybe it would be more natural and practical to just return the
error code when the proper error condition is detected (so the return
would be int instead of bool)?


If everything is OK, return 0.

If we have nanoseconds error, return -EINVAL, and if out-of-range
seconds are detected the helper shall return -EOVERFLOW.

In that way we could avoid the extra error condition check.


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: pgpOP02_e1_xV.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]