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.Fd #include <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 54The 55.Fn clock_gettime 56and 57.Fn clock_settime 58allow the calling process to retrieve or set the value used by a clock 59which is specifed by 60.Fa clock_id . 61.Pp 62.Fa clock_id 63can be one of three values: CLOCK_REALTIME for time that increments as 64a wall clock should, CLOCK_VIRTUAL for time that increments only when 65the CPU is running in user mode on behalf of the calling process, or 66CLOCK_PROF for time that increments when the CPU is running in user or 67kernel mode. 68.Pp 69The structure pointed to by 70.Fa tp 71is defined in 72.Ao Pa sys/time.h Ac 73as: 74.Pp 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 97A 0 return value indicates that the call succeeded. 98A -1 return value indicates an error occurred, and in this 99case an error code is stored into the global variable 100.Va errno . 101.Sh ERRORS 102The following error codes may be set in 103.Va errno : 104.Bl -tag -width Er 105.It Bq Er EINVAL 106The 107.Fa clock_id 108was not a valid value. 109.It Bq Er EFAULT 110The 111.Fa *tp 112argument address referenced invalid memory. 113.It Bq Er EPERM 114A user other than the super-user attempted to set the time. 115.El 116.Sh SEE ALSO 117.Xr date 1 , 118.Xr adjtime 2 , 119.Xr ctime 3 , 120.Xr timed 8 121.Sh STANDARDS 122The 123.Fn clock_gettime ,
|