On 31/12/19(Tue) 17:44, Alexander Bluhm wrote:
> On Tue, Dec 31, 2019 at 04:35:59PM +0100, Martin Pieuchot wrote:
> > Since I don't know C I'd appreciate any pointer about the checks that
> > should be added to TIMESPEC_TO_NSEC().
>
> Perhaps this way?
Thanks.
> static inline uint64_t
> TIMESPEC_TO_NSEC(const struct timespec *ts)
> {
> if (ts->tv_sec > (UINT64_MAX - ts->tv_nsec) / 1000000000ULL)
> return UINT64_MAX;
> return ts->tv_sec * 1000000000ULL + ts->tv_nsec;
> }
>
> Should we use inline instead of __inline for new code?
ok mpi@
> Index: sys/time.h
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/sys/sys/time.h,v
> retrieving revision 1.47
> diff -u -p -r1.47 time.h
> --- sys/time.h 22 Oct 2019 20:19:41 -0000 1.47
> +++ sys/time.h 31 Dec 2019 16:38:20 -0000
> @@ -177,7 +177,7 @@ struct bintime {
> (btp)->frac cmp (ctp)->frac : \
> (btp)->sec cmp (ctp)->sec)
>
> -static __inline void
> +static inline void
> bintimeaddfrac(const struct bintime *bt, uint64_t x, struct bintime *ct)
> {
> ct->sec = bt->sec;
> @@ -186,7 +186,7 @@ bintimeaddfrac(const struct bintime *bt,
> ct->frac = bt->frac + x;
> }
>
> -static __inline void
> +static inline void
> bintimeadd(const struct bintime *bt, const struct bintime *ct,
> struct bintime *dt)
> {
> @@ -196,7 +196,7 @@ bintimeadd(const struct bintime *bt, con
> dt->frac = bt->frac + ct->frac;
> }
>
> -static __inline void
> +static inline void
> bintimesub(const struct bintime *bt, const struct bintime *ct,
> struct bintime *dt)
> {
> @@ -220,14 +220,14 @@ bintimesub(const struct bintime *bt, con
> * time_second ticks after N.999999999 not after N.4999999999
> */
>
> -static __inline void
> +static inline void
> BINTIME_TO_TIMESPEC(const struct bintime *bt, struct timespec *ts)
> {
> ts->tv_sec = bt->sec;
> ts->tv_nsec = (long)(((uint64_t)1000000000 * (uint32_t)(bt->frac >>
> 32)) >> 32);
> }
>
> -static __inline void
> +static inline void
> TIMESPEC_TO_BINTIME(const struct timespec *ts, struct bintime *bt)
> {
> bt->sec = ts->tv_sec;
> @@ -235,14 +235,14 @@ TIMESPEC_TO_BINTIME(const struct timespe
> bt->frac = (uint64_t)ts->tv_nsec * (uint64_t)18446744073ULL;
> }
>
> -static __inline void
> +static inline void
> BINTIME_TO_TIMEVAL(const struct bintime *bt, struct timeval *tv)
> {
> tv->tv_sec = bt->sec;
> tv->tv_usec = (long)(((uint64_t)1000000 * (uint32_t)(bt->frac >> 32))
> >> 32);
> }
>
> -static __inline void
> +static inline void
> TIMEVAL_TO_BINTIME(const struct timeval *tv, struct bintime *bt)
> {
> bt->sec = (time_t)tv->tv_sec;
> @@ -332,14 +332,14 @@ void clock_secs_to_ymdhms(time_t, struct
> /* Traditional POSIX base year */
> #define POSIX_BASE_YEAR 1970
>
> -static __inline void
> +static inline void
> NSEC_TO_TIMEVAL(uint64_t ns, struct timeval *tv)
> {
> tv->tv_sec = ns / 1000000000L;
> tv->tv_usec = (ns % 1000000000L) / 1000;
> }
>
> -static __inline void
> +static inline void
> NSEC_TO_TIMESPEC(uint64_t ns, struct timespec *ts)
> {
> ts->tv_sec = ns / 1000000000L;
> @@ -348,7 +348,7 @@ NSEC_TO_TIMESPEC(uint64_t ns, struct tim
>
> #include <sys/stdint.h>
>
> -static __inline uint64_t
> +static inline uint64_t
> SEC_TO_NSEC(uint64_t seconds)
> {
> if (seconds > UINT64_MAX / 1000000000ULL)
> @@ -356,7 +356,7 @@ SEC_TO_NSEC(uint64_t seconds)
> return seconds * 1000000000ULL;
> }
>
> -static __inline uint64_t
> +static inline uint64_t
> MSEC_TO_NSEC(uint64_t milliseconds)
> {
> if (milliseconds > UINT64_MAX / 1000000ULL)
> @@ -364,7 +364,7 @@ MSEC_TO_NSEC(uint64_t milliseconds)
> return milliseconds * 1000000ULL;
> }
>
> -static __inline uint64_t
> +static inline uint64_t
> USEC_TO_NSEC(uint64_t microseconds)
> {
> if (microseconds > UINT64_MAX / 1000ULL)
>