diff options
author | cheloha <cheloha@cvs.openbsd.org> | 2019-01-18 09:36:48 +0000 |
---|---|---|
committer | cheloha <cheloha@cvs.openbsd.org> | 2019-01-18 09:36:48 +0000 |
commit | 3cb87eb23a23eed2a108f30cbba95953415fe808 (patch) | |
tree | 74fd523a5fcdcca6327faa99ba801cdbba1e47a5 | |
parent | d73018db5307861761e822495245ecffaf6c48ed (diff) |
sys/time.h: new macros: timerisvalid() and timespecisvalid().
Make it less likely you miss a zero when typing out 100000 or 100000000.
Document them in getitimer.2 for the masses. These may be of use in
library code as well as the kernel.
Comparable inline functions exist in Linux but are not available to
userspace like these.
"OK." deraadt@
-rw-r--r-- | lib/libc/sys/getitimer.2 | 12 | ||||
-rw-r--r-- | sys/sys/time.h | 6 |
2 files changed, 15 insertions, 3 deletions
diff --git a/lib/libc/sys/getitimer.2 b/lib/libc/sys/getitimer.2 index e569ba53a6a..8dc06adf3cb 100644 --- a/lib/libc/sys/getitimer.2 +++ b/lib/libc/sys/getitimer.2 @@ -1,4 +1,4 @@ -.\" $OpenBSD: getitimer.2,v 1.29 2015/11/10 23:48:18 jmc Exp $ +.\" $OpenBSD: getitimer.2,v 1.30 2019/01/18 09:36:47 cheloha Exp $ .\" $NetBSD: getitimer.2,v 1.6 1995/10/12 15:40:54 jtc Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)getitimer.2 8.2 (Berkeley) 12/11/93 .\" -.Dd $Mdocdate: November 10 2015 $ +.Dd $Mdocdate: January 18 2019 $ .Dt GETITIMER 2 .Os .Sh NAME @@ -38,6 +38,7 @@ .Nm setitimer , .Nm timerclear , .Nm timerisset , +.Nm timerisvalid , .Nm timercmp , .Nm timersub , .Nm timeradd @@ -57,6 +58,8 @@ .Ft int .Fn timerisset "struct timeval *" .Ft int +.Fn timerisvalid "struct timeval *" +.Ft int .Fn timercmp "struct timeval *a" "struct timeval *b" CMP .Ft void .Fn timersub "struct timeval *a" "struct timeval *b" "struct timeval *res" @@ -156,6 +159,11 @@ tests if the time value in .Fa a is non-zero. .Pp +.Fn timerisvalid "a" +tests if the microsecond value in +.Fa a +is greater than or equal to zero and less than 1 million. +.Pp .Fn timercmp a b CMP compares two time values in the form .Fa a diff --git a/sys/sys/time.h b/sys/sys/time.h index 87287590eb4..95738a2364c 100644 --- a/sys/sys/time.h +++ b/sys/sys/time.h @@ -1,4 +1,4 @@ -/* $OpenBSD: time.h,v 1.38 2018/05/28 18:05:42 guenther Exp $ */ +/* $OpenBSD: time.h,v 1.39 2019/01/18 09:36:47 cheloha Exp $ */ /* $NetBSD: time.h,v 1.18 1996/04/23 10:29:33 mycroft Exp $ */ /* @@ -84,6 +84,8 @@ struct timezone { /* Operations on timevals. */ #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#define timerisvalid(tvp) \ + ((tvp)->tv_usec >= 0 && (tvp)->tv_usec < 1000000) #define timercmp(tvp, uvp, cmp) \ (((tvp)->tv_sec == (uvp)->tv_sec) ? \ ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ @@ -110,6 +112,8 @@ struct timezone { /* Operations on timespecs. */ #define timespecclear(tsp) (tsp)->tv_sec = (tsp)->tv_nsec = 0 #define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec) +#define timespecisvalid(tsp) \ + ((tsp)->tv_nsec >= 0 && (tsp)->tv_nsec < 1000000000L) #define timespeccmp(tsp, usp, cmp) \ (((tsp)->tv_sec == (usp)->tv_sec) ? \ ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ |