2004-05-13 14:20:57 +04:00
|
|
|
.\" $NetBSD: clock_settime.2,v 1.17 2004/05/13 10:20:57 wiz Exp $
|
1999-02-11 18:20:47 +03:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
.\" by Klaus Klein.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the NetBSD
|
|
|
|
.\" Foundation, Inc. and its contributors.
|
|
|
|
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
.\" contributors may be used to endorse or promote products derived
|
|
|
|
.\" from this software without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
2001-09-16 05:38:59 +04:00
|
|
|
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
1999-02-11 18:20:47 +03:00
|
|
|
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.Dd February 11, 1999
|
|
|
|
.Dt CLOCK_SETTIME 2
|
1999-03-22 22:44:33 +03:00
|
|
|
.Os
|
1999-02-11 18:20:47 +03:00
|
|
|
.Sh NAME
|
|
|
|
.Nm clock_settime ,
|
|
|
|
.Nm clock_gettime ,
|
|
|
|
.Nm clock_getres
|
|
|
|
.Nd clock and timer functions
|
1999-12-03 00:42:35 +03:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libc
|
1999-02-11 18:20:47 +03:00
|
|
|
.Sh SYNOPSIS
|
2003-04-16 17:34:34 +04:00
|
|
|
.In time.h
|
1999-02-11 18:20:47 +03:00
|
|
|
.Ft int
|
|
|
|
.Fn clock_settime "clockid_t clock_id" "const struct timespec *tp"
|
|
|
|
.Ft int
|
|
|
|
.Fn clock_gettime "clockid_t clock_id" "struct timespec *tp"
|
|
|
|
.Ft int
|
|
|
|
.Fn clock_getres "clockid_t clock_id" "struct timespec *res"
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Fn clock_settime
|
|
|
|
function sets the clock identified by
|
|
|
|
.Fa clock_id
|
|
|
|
to the absolute time specified by
|
|
|
|
.Fa tp .
|
|
|
|
If the time specified by
|
|
|
|
.Fa tp
|
|
|
|
is not a multiple of the resolution of the clock,
|
|
|
|
.Fa tp
|
|
|
|
is truncated to a multiple of the resolution.
|
|
|
|
.Pp
|
|
|
|
.The
|
|
|
|
.Fn clock_gettime
|
|
|
|
function stores the time of the clock identified by
|
|
|
|
.Fa clock_id
|
|
|
|
into the location specified by
|
2001-09-16 06:13:26 +04:00
|
|
|
.Fa tp .
|
1999-02-11 18:20:47 +03:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn clock_getres
|
|
|
|
function stores the resolution of the clock identified by
|
|
|
|
.Fa clock_id
|
|
|
|
into the location specified by
|
|
|
|
.Fa res ,
|
|
|
|
unless
|
|
|
|
.Fa res
|
|
|
|
is
|
|
|
|
.Dv NULL .
|
|
|
|
.Pp
|
|
|
|
A
|
|
|
|
.Fa clock_id
|
|
|
|
of
|
|
|
|
.Dv CLOCK_REALTIME
|
|
|
|
identifies the realtime clock for the system.
|
|
|
|
For this clock, the values specified by
|
|
|
|
.Fn clock_settime
|
|
|
|
and obtained by
|
|
|
|
.Fn clock_gettime
|
|
|
|
represent the amount of time (in seconds and nanoseconds)
|
|
|
|
since 00:00 Universal Coordinated Time, January 1, 1970.
|
2001-09-16 11:41:56 +04:00
|
|
|
.Pp
|
2002-01-31 03:13:07 +03:00
|
|
|
A
|
|
|
|
.Fa clock_id
|
|
|
|
of
|
|
|
|
.Dv CLOCK_MONOTONIC
|
|
|
|
identifies a clock that increases at a steady rate (monotonically).
|
|
|
|
This clock
|
|
|
|
is not affected by calls to
|
|
|
|
.Xr adjtime 2
|
|
|
|
and
|
|
|
|
.Xr settimeofday 2
|
2002-01-31 03:21:31 +03:00
|
|
|
and will
|
2002-01-31 03:13:07 +03:00
|
|
|
fail with an
|
|
|
|
.Er EINVAL
|
|
|
|
error if it the clock specified in a call to
|
|
|
|
.Fn clock_settime .
|
|
|
|
The origin of the clock is unspecified.
|
|
|
|
.Pp
|
2002-01-26 18:04:16 +03:00
|
|
|
If the calling user is not the super-user, then the
|
2001-09-16 11:41:56 +04:00
|
|
|
.Fn clock_settime
|
|
|
|
function in the standard C library will try to use the
|
|
|
|
.Xr clockctl 4
|
|
|
|
device if present, thus making possible for non privileged users to
|
2002-10-01 22:10:43 +04:00
|
|
|
set the system time.
|
|
|
|
If
|
2001-09-16 11:41:56 +04:00
|
|
|
.Xr clockctl 4
|
|
|
|
is not present or not accessible, then
|
|
|
|
.Fn clock_settime
|
|
|
|
reverts to the
|
|
|
|
.Fn clock_settime
|
|
|
|
system call, which is restricted to the super user.
|
1999-02-11 18:20:47 +03:00
|
|
|
.Sh RETURN VALUES
|
2002-10-01 22:10:43 +04:00
|
|
|
A value of 0 is returned on success.
|
2004-05-13 14:20:57 +04:00
|
|
|
Otherwise, a value of \-1 is returned and
|
1999-02-16 22:36:52 +03:00
|
|
|
.Va errno
|
1999-02-11 18:20:47 +03:00
|
|
|
is set to indicate the error.
|
|
|
|
.Sh ERRORS
|
|
|
|
The
|
|
|
|
.Fn clock_settime ,
|
|
|
|
.Fn clock_gettime
|
|
|
|
and
|
|
|
|
.Fn clock_getres
|
|
|
|
functions will fail if:
|
|
|
|
.Bl -tag -width Er
|
|
|
|
.It Bq Er EINVAL
|
|
|
|
The
|
|
|
|
.Fa clock_id
|
|
|
|
argument does not specify a known clock.
|
|
|
|
.It Bq Er ENOSYS
|
|
|
|
The function is not supported by this implementation.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn clock_settime
|
|
|
|
function will fail if:
|
|
|
|
.Bl -tag -width Er
|
|
|
|
.It Bq Er EINVAL
|
|
|
|
The
|
|
|
|
.Fa tp
|
|
|
|
argument is outside the range for the specified clock,
|
|
|
|
.Fa clock_id .
|
|
|
|
.It Bq Er EINVAL
|
|
|
|
The
|
|
|
|
.Fa tp
|
|
|
|
argument specified a nanosecond value less than zero of greater than or equal
|
|
|
|
1000 million.
|
2002-01-31 03:13:07 +03:00
|
|
|
.It Bq Er EINVAL
|
|
|
|
The
|
|
|
|
.Fa clock_id
|
|
|
|
argument is a clock that can not be adjusted.
|
1999-02-11 18:20:47 +03:00
|
|
|
.It Bq Er EPERM
|
|
|
|
The
|
|
|
|
calling process does not have the appropriate privilege to set the specified
|
|
|
|
clock,
|
|
|
|
.Fa clock_id .
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn clock_gettime
|
|
|
|
function will fail if:
|
|
|
|
.Bl -tag -width Er
|
|
|
|
.It Bq Er EFAULT
|
|
|
|
The
|
|
|
|
.Fa tp
|
|
|
|
argument specifies an address that is not a valid part of the process address
|
|
|
|
space.
|
|
|
|
.El
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr ctime 3 ,
|
2001-09-16 11:41:56 +04:00
|
|
|
.Xr time 3 ,
|
|
|
|
.\" .Xr timer_gettime 3 ,
|
2001-10-16 20:08:55 +04:00
|
|
|
.Xr clockctl 4
|
1999-02-11 18:20:47 +03:00
|
|
|
.Sh STANDARDS
|
|
|
|
The
|
|
|
|
.Fn clock_settime ,
|
|
|
|
.Fn clock_gettime
|
|
|
|
and
|
|
|
|
.Fn clock_getres
|
|
|
|
functions conform to
|
|
|
|
.St -p1003.1b-93 .
|