.\" 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. .\" .\" @(#)gettimeofday.2 8.2 (Berkeley) 5/26/95 .\" %FreeBSD: src/lib/libc/sys/gettimeofday.2,v 1.25 2004/07/02 23:52:13 ru Exp % .\" .\" $FreeBSD$ .Dd May 26, 1995 .Dt GETTIMEOFDAY 2 .Os .Sh 名称 .Nm gettimeofday , .Nm settimeofday .Nd 日付と時刻の取得 / 設定 .Sh ライブラリ .Lb libc .Sh 書式 .In sys/time.h .Ft int .Fn gettimeofday "struct timeval *tp" "struct timezone *tzp" .Ft int .Fn settimeofday "const struct timeval *tp" "const struct timezone *tzp" .Sh 解説 .Bf -symbolic 注記: timezone はもはや使用されません。 この情報はカーネルの外側に保持されます。 .Ef .Pp システムが保持している現在のグリニッジ時刻と現在の時間帯は .Fn gettimeofday システムコールから得られ、 .Fn settimeofday システムコールで設定されます。 時刻は 1970 年 1 月 1 日の深夜 (0 時) からの秒数とマイクロ秒数で表現されます。 システムクロックの分解能はハードウェアで決まり、 時刻は継続的または .Dq チック 単位で更新されます。 .Fa tp または .Fa tzp が NULL の場合、対応する時刻情報は返されず、また設定されません。 .Pp .Fa tp と .Fa tzp の指す構造体は .In sys/time.h 内に次のように定義されています: .Pp .Bd -literal struct timeval { long tv_sec; /* 1970 年 1 月 1 日からの秒数 */ long tv_usec; /* およびマイクロ秒数 */ }; struct timezone { int tz_minuteswest; /* グリニッジから西方向への偏差 */ int tz_dsttime; /* 夏時間補正のタイプ */ }; .Ed .Pp .Vt timezone 構造体は、ローカル時間帯 (グリニッジから西向きに分単位で測定) と フラグを含みます。 フラグが 0 でない場合は、1 年の適切な時期に 夏時間がその地域に適用されることを示します。 .Pp スーパユーザだけが時刻または時間帯を設定できます。 システムが securelevel >= 2 .Pf ( Xr init 8 を参照) で実行される場合は、 最大 1 秒のみ時刻を進めるか遅らせることしかできません。 この制限が課されるのは、悪意のあるスーパユーザがファイルに任意の タイムスタンプを設定するのを防止するためです。 システム時刻は、システムが安全モードにあっても .Xr adjtime 2 システムコールを使用して制限なしに後方に調整できます。 .Sh 戻り値 .Rv -std .Sh エラー 次のエラーコードが .Va errno に設定されます: .Bl -tag -width Er .It Bq Er EFAULT 引数アドレスが無効なメモリを参照しました。 .It Bq Er EPERM スーパユーザ以外のユーザが時刻を設定しようとしました。 .El .Sh 関連項目 .Xr date 1 , .Xr adjtime 2 , .Xr clock_gettime 2 , .Xr ctime 3 , .Xr timeradd 3 , .Xr clocks 7 , .Xr timed 8 .Sh 歴史 .Fn gettimeofday システムコールは .Bx 4.2 ではじめて登場しました。