1.\" $OpenBSD: clock_gettime.2,v 1.4 1997/05/08 20:21:16 kstailey 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.\" $FreeBSD$ 35.\" 36.Dd November 18, 2005 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 specified by 61.Fa clock_id . 62.Pp 63The 64.Fa clock_id 65argument 66can be one of five values: 67.Dv CLOCK_REALTIME 68for time that increments as 69a wall clock should, 70.Dv CLOCK_MONOTONIC 71which increments in SI seconds, 72.Dv CLOCK_UPTIME 73which starts at zero when the kernel boots and increments 74monotonically in SI seconds while the machine is running, 75.Dv CLOCK_VIRTUAL 76for time that increments only when 77the CPU is running in user mode on behalf of the calling process, or 78.Dv CLOCK_PROF 79for time that increments when the CPU is running in user or 80kernel mode. 81.Pp 82The structure pointed to by 83.Fa tp 84is defined in 85.In sys/time.h 86as: 87.Pp 88.Bd -literal 89struct timespec { 90 time_t tv_sec; /* seconds */ 91 long tv_nsec; /* and nanoseconds */ 92}; 93.Ed 94.Pp 95Only the super-user may set the time of day. 96If the system securelevel is greater than 1 (see 97.Xr init 8 ) , 98the time may only be advanced. 99This limitation is imposed to prevent a malicious super-user 100from setting arbitrary time stamps on files. 101The system time can still be adjusted backwards using the 102.Xr adjtime 2 103system call even when the system is secure. 104.Pp 105The resolution (granularity) of a clock is returned by the 106.Fn clock_getres 107system call. 108This value is placed in a (non-NULL) 109.Fa *tp . 110.Sh RETURN VALUES 111.Rv -std 112.Sh ERRORS 113The following error codes may be set in 114.Va errno : 115.Bl -tag -width Er 116.It Bq Er EINVAL 117The 118.Fa clock_id 119argument 120was not a valid value. 121.It Bq Er EFAULT 122The 123.Fa *tp 124argument address referenced invalid memory. 125.It Bq Er EPERM 126A user other than the super-user attempted to set the time. 127.El 128.Sh SEE ALSO 129.Xr date 1 , 130.Xr adjtime 2 , 131.Xr ctime 3 , 132.Xr timed 8 133.Sh STANDARDS 134The 135.Fn clock_gettime , 136.Fn clock_settime , 137and 138.Fn clock_getres 139system calls conform to 140.St -p1003.1b-93 . 141