diff options
author | Dan McDonald <danmcd@joyent.com> | 2020-09-22 10:39:49 -0400 |
---|---|---|
committer | Dan McDonald <danmcd@joyent.com> | 2020-09-22 10:39:49 -0400 |
commit | 267e12a7d9bf6e5fcefb9cc00f46bfff0dc5226e (patch) | |
tree | 19a3941920d0039c35d53a5cbee189b5ca51995a /usr/src/man/man3head/timespec.3head | |
parent | 517abc5c668925e6092495bf332233c3599980d2 (diff) | |
parent | e9faba760cdf80d7dfa110fe0830917ab94668c2 (diff) | |
download | illumos-joyent-vpc.tar.gz |
Merge branch 'master' into vpcvpc
Diffstat (limited to 'usr/src/man/man3head/timespec.3head')
-rw-r--r-- | usr/src/man/man3head/timespec.3head | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/usr/src/man/man3head/timespec.3head b/usr/src/man/man3head/timespec.3head new file mode 100644 index 0000000000..54aaab14f5 --- /dev/null +++ b/usr/src/man/man3head/timespec.3head @@ -0,0 +1,106 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2020 OmniOS Community Edition (OmniOSce) Association. +.\" +.Dd Sep 06, 2020 +.Dt timespec 3HEAD +.Os +.Sh NAME +.Nm timespec , +.Nm timeval , +.Nm TIMESPEC_TO_TIMEVAL , +.Nm TIMEVAL_TO_TIMESPEC +.Nd time structures and conversion +.Sh SYNOPSIS +.In sys/time.h +.Ft void +.Fo TIMESPEC_TO_TIMEVAL +.Fa "struct timeval *tv" +.Fa "const struct timespec *ts" +.Fc +.Ft void +.Fo TIMEVAL_TO_TIMESPEC +.Fa "const struct timeval *tv" +.Fa "struct timespec *ts" +.Fc +.Sh DESCRIPTION +The +.Vt timeval +and +.Vt timespec +structures are declared in the +.In time.h +and +.In sys/time.h +headers respectively: +.Bd -literal -offset indent +typedef struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +} timespec_t; + +struct timeval { + time_t tv_sec; /* seconds */ + suseconds_t tv_usec; /* and microseconds */ +}; +.Ed +.Pp +In both cases, the +.Fa tv_sec +member represents elapsed time in whole seconds. +The +.Fa tv_nsec +and +.Fa tv_usec +members represent the rest of the elapsed time in nanoseconds and +microseconds respectively, depending on the structure. +.Pp +The +.Dv TIMEVAL_TO_TIMESPEC +macro can be used to convert a +.Vt struct timeval +structure to a +.Vt struct timespec +structure, while the +.Dv TIMESPEC_TO_TIMEVAL +macro works in the opposite direction. +.Pp +When converting from a +.Vt struct timespec +to a +.Vt struct timeval +structure, the +.Fa tv_nsec +member is truncated, losing precision. +When converting from a +.Vt struct timeval +to a +.Vt struct timespec +structure, the +.Fa tv_usec +member is multiplied by 1000 to reach the precision of the target +structure. +The +.Fa tv_sec +member is always preserved, no matter which conversion is performed. +.Pp +Note that the +.Dv TIMEVAL_TO_TIMESPEC +and +.Dv TIMESPEC_TO_TIMEVAL +macros are non-standard but are commonly found on UNIX and UNIX-like systems. +.Sh INTERFACE STABILITY +.Sy Committed +.Sh MT-LEVEL +.Sy MT-Safe +.Sh SEE ALSO +.Xr time.h 3HEAD |