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 Paul, Joseph,

> On 9/26/19 2:55 PM, Lukasz Majewski wrote:
> > +/* Convert a known valid struct timeval into a struct
> > __timespec64.  */ +static inline void
> > +valid_timeval_to_timespec64 (const struct timeval *tv32,
> > +			     struct __timespec64 *ts64)
> > +{
> > +  ts64->tv_sec = tv32->tv_sec;
> > +  ts64->tv_nsec = tv32->tv_usec * 1000;
> > +}  
> 
> I suggest using values rather than pointers. That is, this function
> can accept a struct timeval and return a struct __timespec64. The *s
> and the consts just get in the way for something simple like this,
> and using values will simplify the source code.
> 

Then I will trim the patch to:

1. Only provide:
	valid_timeval_to_timespec64 ()
	valid_timespec_to_timespec64 ()
	valid_timespec64_to_timespec ()
	valid_timespec64_to_timeval ()

As those functions are needed for RISC-V 32 glibc port patch series as
well.

2. Above "valid" functions will use values instead of pointers:

static inline struct __timespec64
valid_timespec_to_timespec64 (const struct timespec tp)
{
  struct __timespec64 ts64;

  ts64.tv_sec = ts32.tv_sec;
  ts64.tv_nsec = ts32.tv_nsec;

  return ts64;
}

> For the fancier functions that do range checking, you can simply
> return an invalid result (with tv_nsec < 0, say). So you don't need a
> separate boolean there. Some GNU apps do this sort of thing.

In glibc I've already found function which returns struct with all
fields set to 0 (./support/blob_repeat.c - support blob repeat
allocate) and also sets explicitly errno.

In our case we could return -1 in tv_nsec as you suggested.


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