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 February 5, 2003 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 63The 64.Fa clock_id 65argument 66can be one of four values: CLOCK_REALTIME for time that increments as 67a wall clock should, CLOCK_MONOTONIC which increments in SI seconds, 68CLOCK_VIRTUAL for time that increments only when 69the CPU is running in user mode on behalf of the calling process, or 70CLOCK_PROF for time that increments when the CPU is running in user or 71kernel mode. 72.Pp 73The structure pointed to by 74.Fa tp 75is defined in 76.Ao Pa sys/time.h Ac 77as: 78.Pp 79.Bd -literal 80struct timespec { 81 time_t tv_sec; /* seconds */ 82 long tv_nsec; /* and nanoseconds */ 83}; 84.Ed 85.Pp 86Only the super-user may set the time of day. 87If the system securelevel is greater than 1 (see 88.Xr init 8 ) , 89the time may only be advanced. 90This limitation is imposed to prevent a malicious super-user 91from setting arbitrary time stamps on files. 92The system time can still be adjusted backwards using the 93.Xr adjtime 2 94system call even when the system is secure. 95.Pp 96The resolution (granularity) of a clock is returned by the 97.Fn clock_getres 98system call. This value is placed in a (non-NULL) 99.Fa *tp . 100.Sh RETURN VALUES 101.Rv -std 102.Sh ERRORS 103The following error codes may be set in 104.Va errno : 105.Bl -tag -width Er 106.It Bq Er EINVAL 107The 108.Fa clock_id 109argument 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 super-user 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_getres 129system calls conform to 130.St -p1003.1b-93 . 131.Sh BUGS 132The 133.Dv CLOCK_VIRTUAL 134and 135.Dv CLOCK_PROF 136timers are not yet implemented. 137