aboutsummaryrefslogtreecommitdiff
path: root/ja_JP.eucJP/man/man2/gettimeofday.2
blob: c126d5c5d1e12a0354f2616fb9b46a085fd9fc12 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
.\" 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.9.2.4 2001/01/16 10:33:28 ru Exp %
.\"
.\" $FreeBSD$
.Dd May 26, 1995
.Dt GETTIMEOFDAY 2
.Os BSD 4
.Sh 名称
.Nm gettimeofday ,
.Nm settimeofday
.Nd 日付と時刻の取得 / 設定
.Sh ライブラリ
.Lb libc
.Sh 書式
.Fd #include <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
の指す構造体は
.Ao Pa sys/time.h Ac
内に次のように定義されています。
.Pp
.Bd -literal
struct timeval {
	long	tv_sec;		/* 1970年1月1日からの秒数 */
	long	tv_usec;	/* およびマイクロ秒数 */
};

struct timezone {
	int	tz_minuteswest; /* グリニッジから西方向への偏差 */
	int	tz_dsttime;	/* 夏時間補正のタイプ */
};
.Ed
.Pp
.Fa timezone
構造体は、ローカル時間帯 (グリニッジから西向きに分単位で測定) と
フラグを含みます。フラグが 0 でない場合は、一年の適切な時期に
夏時間がその地域に適用されることを示します。
.Pp
スーパユーザだけが時刻または時間帯を設定できます。
システムが安全モード
.Pf ( Xr init 8
を参照) で実行される場合は、時刻は進めることしかできません。
この制限が課されるのは、悪意のあるスーパユーザがファイルに任意の
タイムスタンプを設定するのを防止するためです。
システム時刻は、システムが安全モードにあっても
.Xr adjtime 2
システムコールを使用して後方に調整できます。
.Sh 戻り値
戻り値 0 は呼び出しが正常に完了したことを示します。
戻り値 -1 はエラーが起こったことを示し、エラーコードはグローバル変数
.Va errno
に保存されます。
.Sh エラー
次のエラーコードが
.Va errno
に設定されます。
.Bl -tag -width Er
.It Bq Er EFAULT
引数アドレスが無効なメモリを参照しました。
.It Bq Er EPERM
スーパユーザ以外のユーザが時刻を設定しようとしました。
.El
.Sh 関連項目
.Xr date 1 ,
.Xr adjtime 2 ,
.Xr ctime 3 ,
.Xr clocks 7 ,
.Xr timed 8
.Sh 歴史
.Fn gettimeofday
関数は
.Bx 4.2
ではじめて登場しました。