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. 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 specified by 61.Fa clock_id . 62.Pp 63.Fa clock_id 64can be one of two values: 65.Dv CLOCK_REALTIME 66for time that increments as a wall clock should and 67.Dv CLOCK_MONOTONIC 68for time that increments at a static rate in SI seconds. 69.Pp 70The structure pointed to by 71.Fa tp 72is defined in 73.In sys/time.h 74as: 75.Bd -literal 76struct timespec { 77 time_t tv_sec; /* seconds */ 78 long tv_nsec; /* and nanoseconds */ 79}; 80.Ed 81.Pp 82Only the super-user may set the time of day. 83If the system securelevel is greater than 1 (see 84.Xr init 8 ) , 85the time may only be advanced. 86This limitation is imposed to prevent a malicious super-user 87from setting arbitrary time stamps on files. 88The system time can still be adjusted backwards using the 89.Xr adjtime 2 90system call even when the system is secure. 91.Pp 92The resolution (granularity) of a clock is returned by the 93.Fn clock_getres 94call. This value is placed in a (non-NULL) 95.Fa *tp . 96.Sh RETURN VALUES 97.Rv -std 98.Sh ERRORS 99The following error codes may be set in 100.Va errno : 101.Bl -tag -width Er 102.It Bq Er EINVAL 103The 104.Fa clock_id 105was not a valid value. 106.It Bq Er EFAULT 107The 108.Fa *tp 109argument address referenced invalid memory. 110.It Bq Er EPERM 111A 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 119The 120.Fn clock_gettime , 121etc.\& 122functions conform to 123.St -p1003.1b-93 . 124