xref: /openbsd/lib/libc/sys/clock_gettime.2 (revision 133306f0)
1.\"	$OpenBSD: clock_gettime.2,v 1.12 2000/10/18 05:12:08 aaron Exp $
2.\"
3.\" Copyright (c) 1980, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"	This product includes software developed by the University of
17.\"	California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd May 8, 1997
35.Dt CLOCK_GETTIME 2
36.Os
37.Sh NAME
38.Nm clock_gettime ,
39.Nm clock_settime ,
40.Nm clock_getres
41.Nd get/set/calibrate date and time
42.Sh SYNOPSIS
43.Fd #include <sys/time.h>
44.Ft int
45.Fn clock_gettime "clockid_t clock_id" "struct timespec *tp"
46.Ft int
47.Fn clock_settime "clockid_t clock_id" "const struct timespec *tp"
48.Ft int
49.Fn clock_getres "clockid_t clock_id" "struct timespec *tp"
50.Sh DESCRIPTION
51The
52.Fn clock_gettime
53and
54.Fn clock_settime
55allow the calling process to retrieve or set the value used by a clock
56which is specified by
57.Fa clock_id .
58.Pp
59.Fa clock_id
60can be one of three values:
61.Dv CLOCK_REALTIME
62for time that increments as
63a wall clock should,
64.Dv CLOCK_VIRTUAL
65for time that increments only when
66the CPU is running in user mode on behalf of the calling process, or
67.Dv CLOCK_PROF
68for time that increments when the CPU is running in user or kernel mode.
69.Pp
70The structure pointed to by
71.Fa tp
72is defined in
73.Ao Pa sys/time.h Ac
74as:
75.Pp
76.Bd -literal
77struct timespec {
78	time_t	tv_sec;		/* seconds */
79	long	tv_nsec;	/* and nanoseconds */
80};
81.Ed
82.Pp
83Only the superuser may set the time of day.
84If the system securelevel is greater than 1 (see
85.Xr init 8 ) ,
86the time may only be advanced.
87This limitation is imposed to prevent a malicious superuser
88from setting arbitrary time stamps on files.
89The system time can still be adjusted backwards using the
90.Xr adjtime 2
91system call even when the system is secure.
92.Pp
93The resolution (granularity) of a clock is returned by the
94.Fn clock_getres
95call.
96This value is placed in a (non-null)
97.Fa *tp .
98.Sh RETURN VALUES
99A 0 return value indicates that the call succeeded.
100A \-1 return value indicates an error occurred, and in this
101case an error code is stored into the global variable
102.Va errno .
103.Sh ERRORS
104The following error codes may be set in
105.Va errno :
106.Bl -tag -width [EFAULT]
107.It Bq Er EINVAL
108The
109.Fa clock_id
110was not a valid value.
111.It Bq Er EFAULT
112The
113.Fa *tp
114argument address referenced invalid memory.
115.It Bq Er EPERM
116A user other than the superuser attempted to set the time.
117.El
118.Sh SEE ALSO
119.Xr date 1 ,
120.Xr adjtime 2 ,
121.Xr ctime 3 ,
122.Xr timed 8
123.Sh STANDARDS
124The
125.Fn clock_gettime ,
126.Fn clock_settime ,
127and
128.Fn clock_setres
129functions conform to
130.St -p1003.1b-93 .
131