xref: /dragonfly/lib/libc/sys/clock_gettime.2 (revision 6e285212)
1.\"	$OpenBSD: clock_gettime.2,v 1.4 1997/05/08 20:21:16 kstailey Exp $
2.\" $FreeBSD: src/lib/libc/sys/clock_gettime.2,v 1.3.2.8 2001/12/14 18:34:00 ru Exp $
3.\" $DragonFly: src/lib/libc/sys/clock_gettime.2,v 1.2 2003/06/17 04:26:47 dillon Exp $
4.\"
5.\" Copyright (c) 1980, 1991, 1993
6.\"	The Regents of the University of California.  All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\"    must display the following acknowledgement:
18.\"	This product includes software developed by the University of
19.\"	California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\"    may be used to endorse or promote products derived from this software
22.\"    without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.Dd May 8, 1997
37.Dt CLOCK_GETTIME 2
38.Os
39.Sh NAME
40.Nm clock_gettime ,
41.Nm clock_settime ,
42.Nm clock_getres
43.Nd get/set/calibrate date and time
44.Sh LIBRARY
45.Lb libc
46.Sh SYNOPSIS
47.In sys/time.h
48.Ft int
49.Fn clock_gettime "clockid_t clock_id" "struct timespec *tp"
50.Ft int
51.Fn clock_settime "clockid_t clock_id" "const struct timespec *tp"
52.Ft int
53.Fn clock_getres "clockid_t clock_id" "struct timespec *tp"
54.Sh DESCRIPTION
55The
56.Fn clock_gettime
57and
58.Fn clock_settime
59allow the calling process to retrieve or set the value used by a clock
60which is specifed by
61.Fa clock_id .
62.Pp
63.Fa clock_id
64can be one of three values: CLOCK_REALTIME for time that increments as
65a wall clock should, CLOCK_VIRTUAL for time that increments only when
66the CPU is running in user mode on behalf of the calling process, or
67CLOCK_PROF for time that increments when the CPU is running in user or
68kernel 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 super-user 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 super-user
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.  This value is placed in a (non-NULL)
96.Fa *tp .
97.Sh RETURN VALUES
98.Rv -std
99.Sh ERRORS
100The following error codes may be set in
101.Va errno :
102.Bl -tag -width Er
103.It Bq Er EINVAL
104The
105.Fa clock_id
106was not a valid value.
107.It Bq Er EFAULT
108The
109.Fa *tp
110argument address referenced invalid memory.
111.It Bq Er EPERM
112A user other than the super-user attempted to set the time.
113.El
114.Sh SEE ALSO
115.Xr date 1 ,
116.Xr adjtime 2 ,
117.Xr ctime 3 ,
118.Xr timed 8
119.Sh STANDARDS
120The
121.Fn clock_gettime ,
122etc.\&
123functions conform to
124.St -p1003.1b-93 .
125