Merge branch 'vendor/BYACC'
[dragonfly.git] / lib / libc / sys / clock_gettime.2
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.6 2008/05/02 02:05:04 swildner 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. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .Dd May 8, 1997
33 .Dt CLOCK_GETTIME 2
34 .Os
35 .Sh NAME
36 .Nm clock_gettime ,
37 .Nm clock_settime ,
38 .Nm clock_getres
39 .Nd get/set/calibrate date and time
40 .Sh LIBRARY
41 .Lb libc
42 .Sh SYNOPSIS
43 .In 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
51 The
52 .Fn clock_gettime
53 and
54 .Fn clock_settime
55 allow the calling process to retrieve or set the value used by a clock
56 which is specified by
57 .Fa clock_id .
58 .Pp
59 .Fa clock_id
60 can be one of two values:
61 .Dv CLOCK_REALTIME
62 for time that increments as a wall clock should and
63 .Dv CLOCK_MONOTONIC
64 for time that increments at a static rate in SI seconds.
65 .Pp
66 The structure pointed to by
67 .Fa tp
68 is defined in
69 .In sys/time.h
70 as:
71 .Bd -literal
72 struct timespec {
73         time_t  tv_sec;         /* seconds */
74         long    tv_nsec;        /* and nanoseconds */
75 };
76 .Ed
77 .Pp
78 Only the super-user may set the time of day.
79 If the system securelevel is greater than 1 (see
80 .Xr init 8 ) ,
81 the time may only be advanced.
82 This limitation is imposed to prevent a malicious super-user
83 from setting arbitrary time stamps on files.
84 The system time can still be adjusted backwards using the
85 .Xr adjtime 2
86 system call even when the system is secure.
87 .Pp
88 The resolution (granularity) of a clock is returned by the
89 .Fn clock_getres
90 call.  This value is placed in a (non-NULL)
91 .Fa *tp .
92 .Sh RETURN VALUES
93 .Rv -std
94 .Sh ERRORS
95 The following error codes may be set in
96 .Va errno :
97 .Bl -tag -width Er
98 .It Bq Er EINVAL
99 The
100 .Fa clock_id
101 was not a valid value.
102 .It Bq Er EFAULT
103 The
104 .Fa *tp
105 argument address referenced invalid memory.
106 .It Bq Er EPERM
107 A user other than the super-user attempted to set the time.
108 .El
109 .Sh SEE ALSO
110 .Xr date 1 ,
111 .Xr adjtime 2 ,
112 .Xr ctime 3 ,
113 .Xr timed 8
114 .Sh STANDARDS
115 The
116 .Fn clock_gettime ,
117 etc.\&
118 functions conform to
119 .St -p1003.1b-93 .