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