.\" $OpenBSD: clock_gettime.2,v 1.4 1997/05/08 20:21:16 kstailey Exp $ .\" %FreeBSD: src/lib/libc/sys/clock_gettime.2,v 1.3.2.7 2001/08/31 10:15:15 ru Exp % .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" 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 University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University 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 REGENTS 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 PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 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. .\" .\" $FreeBSD: doc/ja_JP.eucJP/man/man2/clock_gettime.2,v 1.6 2001/08/19 07:14:26 horikawa Exp $ .Dd May 8, 1997 .Dt CLOCK_GETTIME 2 .Os .Sh 名称 .Nm clock_gettime , .Nm clock_settime , .Nm clock_getres .Nd 日付と時刻の取得/設定/精度の取得をする .Sh ライブラリ .Lb libc .Sh 書式 .Fd #include .Ft int .Fn clock_gettime "clockid_t clock_id" "struct timespec *tp" .Ft int .Fn clock_settime "clockid_t clock_id" "const struct timespec *tp" .Ft int .Fn clock_getres "clockid_t clock_id" "struct timespec *tp" .Sh 解説 .Fn clock_gettime と .Fn clock_settime は .Fa clock_id で指定するクロックの値を取得、設定します。 .Pp .Fa clock_id には、次の 3 つの値のうちの 1 つを指定します。 CLOCK_REALTIME は普通の時計のように進む時間、 CLOCK_VIRTUAL は呼び出しプロセスのために CPU がユーザモードで 実行されているときにだけ進む時間、 CLOCK_PROF は、CPU がユーザモードまたはカーネルモードで実行されている ときに進む時間です。 .Pp .Fa tp によって指される構造体は .Ao Pa sys/time.h Ac 内で次のように定義されています。 .Pp .Bd -literal struct timespec { time_t tv_sec; /* 秒 */ long tv_nsec; /* ナノ秒 */ }; .Ed .Pp 時刻を設定できるのはスーパーユーザだけです。 システムの安全性レベル (securelevel) が 1 より大きい場合 .Pf ( Xr init 8 を参照)、 時間は進めることだけができます。この制限は、 悪意のあるスーパーユーザがファイルに 任意のタイムスタンプを設定するのを防止するためのものです。 しかし、システムが安全なモードの時でも、 .Xr adjtime 2 システムコールを使用すれば システム時間を遅らせることができてしまいます。 .Pp クロックの精度 (細かさ) は、 .Fn clock_getres 呼び出しによって返されます。この値は、 (非 NULL ポインタ) .Fa *tp 内に格納されます。 .Sh 戻り値 戻り値 0 は呼び出しが正常に完了したことを示します。 戻り値 -1 はエラーが起こったことを示し、 エラーコードはグローバル変数 .Va errno に保存されます。 .Sh エラー 次のエラーコードが .Va errno に設定されます。 .Bl -tag -width Er .It Bq Er EINVAL .Fa clock_id が有効な値ではありませんでした。 .It Bq Er EFAULT .Fa *tp 引数アドレスが無効なメモリを参照しています。 .It Bq Er EPERM スーパユーザ以外のユーザが時刻を設定しようとしました。 .El .Sh 関連項目 .Xr date 1 , .Xr adjtime 2 , .Xr ctime 3 , .Xr timed 8 etc.\& .Fn clock_gettime 等の関数は .St -p1003.1b-93 に準拠しています。