OSDN Git Service

(split) DP: release pages (catch up to 3.50).
[linuxjm/LDP_man-pages.git] / release / man3 / getdate.3
1 .\" Copyright 2001 walter harms (walter.harms@informatik.uni-oldenburg.de)
2 .\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk
3 .\"     <mtk.manpages@gmail.com>
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
26 .\"
27 .\" Modified, 2001-12-26, aeb
28 .\" 2008-09-07, mtk, Various rewrites; added an example program.
29 .\"
30 .\"*******************************************************************
31 .\"
32 .\" This file was generated with po4a. Translate the source file.
33 .\"
34 .\"*******************************************************************
35 .TH GETDATE 3 2010\-09\-20 "" "Linux Programmer's Manual"
36 .SH 名前
37 getdate, getdate_r \- 日付と時刻の文字列を要素別の時刻に変換する
38 .SH 書式
39 \fB#include <time.h>\fP
40 .sp
41 \fBstruct tm *getdate(const char *\fP\fIstring\fP\fB);\fP
42 .sp
43 \fBextern int getdate_err;\fP
44 .sp
45 \fB#include <time.h>\fP
46 .sp
47 \fBint getdate_r(const char *\fP\fIstring\fP\fB, struct tm *\fP\fIres\fP\fB);\fP
48 .sp
49 .in -4n
50 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
51 .in
52 .sp
53 \fBgetdate\fP():
54 .ad l
55 .RS 4
56 _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
57 .RE
58 .br
59 \fBgetdate_r\fP():
60 .ad l
61 .RS 4
62 _GNU_SOURCE
63 .RE
64 .ad
65 .SH 説明
66 \fBgetdate\fP()  関数は、 \fIstring\fP が指すバッファに格納された文字列表現の日付と時刻を、 要素別の時刻 (broken\-down
67 time) に変換する。 要素別の時刻は \fItm\fP 構造体に格納され、この構造体へのポインタが関数の結果として返される。 この \fItm\fP
68 構造体は静的なメモリ領域にあり、 \fBgetdate\fP()  のそれ以降の呼び出しで上書きされるかもされない。
69
70 (\fIformat\fP 引き数でフォーマットを指定する)  \fBstrptime\fP(3)  とは違い、 \fBgetdate\fP()  は環境変数
71 \fBDATEMSK\fP で指定されたフルパス名のファイルに書いてあるフォーマットを用いる。
72
73 マッチの際には大文字小文字を区別しない。 パターン中でも変換される文字列中でも、余分な空白文字は無視される。
74
75 パターンに指定できる変換指定は、 \fBstrptime\fP(3)  のものと同じである。 POSIX.1\-2001
76 では一つの変換指定が追加で規定されている。
77 .TP 
78 \fB%Z\fP
79 タイムゾーンの名前。 glibc では実装されていない。
80 .LP
81 \fB%Z\fP が指定された場合、要素別の時刻を格納する構造体は、 指定されたタイムゾーンにおける現在時刻に対応する値で初期化される。
82 指定されていない場合、この構造体は現在のローカルタイムに対応する 要素別の時刻で初期化される (\fBlocaltime\fP(3)
83 を呼び出した場合と同じ)。
84 .LP
85 曜日だけが指定された場合、 今日または今日以降で、 その曜日に合致する最初の日が採用される。
86 .LP
87 (年なしで) 月だけが指定された場合、 今月または今月以降で、 その月に合致する最初の月が採用される。
88 .LP
89 時・分・秒がいずれも指定されなかった場合、 現在の時・分・秒が採用される。
90 .LP
91 日付の指定がなかったが、時間 (hour) だけ指定された場合は、 現在の時間またはそれ以降で、その指定に合致する最初の時間が採用される。
92
93 \fBgetdate_r\fP()  は GNU 拡張で \fBgetdate\fP()  のリエントラント版を提供している。 \fBgetdate_r\fP()
94 では、エラーを報告するのにグローバル変数を使用したり、 要素別の時刻を返すのに静的なバッファを使用したりせず、
95 エラーを関数の返り値経由で報告し、要素別の時刻を 引き数 \fIres\fP が指し示す呼び出し側で割り当てたバッファに格納して返す。
96 .SH 返り値
97 成功すると、 \fBgetdate\fP()  は \fIstruct tm\fP へのポインタを返す。 失敗すると NULL を返し、グローバル変数
98 \fIgetdate_err\fP に以下に示すエラー番号のいずれか一つを設定する。 \fIerrno\fP の変更については規定されていない。
99
100 成功すると、 \fBgetdate_r\fP()  は 0 を返す。 失敗すると、以下に示すエラー番号のいずれか一つを返す。
101 .SH エラー
102 以下のエラーが、 (\fBgetdate\fP()  では)  \fIgetdate_err\fP 経由で返され、 (\fBgetdate_r\fP()  では)
103 関数の返り値として返される。
104 .TP  4n
105 \fB1\fP
106 環境変数 \fBDATEMASK\fP が未定義、またはその値が空文字列である。
107 .TP 
108 \fB2\fP
109 \fBDATEMSK\fP で指定されたテンプレートファイルを読み込み用にオープンできない。
110 .TP 
111 \fB3\fP
112 .\" stat()
113 ファイルのステータス情報が取得できない。
114 .TP 
115 \fB4\fP
116 テンプレートファイルが通常のファイルでない。
117 .TP 
118 \fB5\fP
119 テンプレートファイルの読み込み中にエラーが起こった。
120 .TP 
121 \fB6\fP
122 .\" Error 6 doesn't seem to occur in glibc
123 メモリの割り当てに失敗した (メモリが足りない)。
124 .TP 
125 \fB7\fP
126 入力にマッチしたファイルに、行が含まれていない。
127 .TP 
128 \fB8\fP
129 入力指定が正しくない。
130 .SH 環境変数
131 .TP 
132 \fBDATEMSK\fP
133 書式パターンを含むファイル。
134 .TP 
135 \fBTZ\fP, \fBLC_TIME\fP
136 \fBstrptime\fP(3)  が用いる変数。
137 .SH 準拠
138 POSIX.1\-2001.
139 .SH 注意
140 POSIX.1\-2001 仕様では、 \fBstrptime\fP(3)  については \fB%E\fP や \fB%O\fP
141 といった修正子を用いた変換指定を規定しているが、 \fBgetdate\fP()  についてはこのような修飾子の規定はない。 glibc では、
142 \fBgetdate\fP()  は \fBstrptime\fP(3)  を用いて実装されており、 両者では全く同じ変換が両者でサポートされている。
143 .SH 例
144 以下のプログラムは、コマンドライン引き数のそれぞれについて \fBgetdate\fP()  を呼び出し、それぞれについて返された \fItm\fP
145 構造体のフィールド値を表示する。 次のシェル・セッションは、プログラムの動作例である。
146
147 .in +4n
148 .nf
149 $\fB TFILE=$PWD/tfile\fP
150 $\fB echo \(aq%A\(aq > $TFILE \fP      # Full weekday name
151 $\fB echo \(aq%T\(aq >> $TFILE\fP      # ISO date (YYYY\-MM\-DD)
152 $\fB echo \(aq%F\(aq >> $TFILE\fP      # Time (HH:MM:SS)
153 $\fB date\fP
154 $\fB export DATEMSK=$TFILE\fP
155 $\fB ./a.out Tuesday \(aq2009\-12\-28\(aq \(aq12:22:33\(aq\fP
156 Sun Sep  7 06:03:36 CEST 2008
157 Call 1 ("Tuesday") succeeded:
158     tm_sec   = 36
159     tm_min   = 3
160     tm_hour  = 6
161     tm_mday  = 9
162     tm_mon   = 8
163     tm_year  = 108
164     tm_wday  = 2
165     tm_yday  = 252
166     tm_isdst = 1
167 Call 2 ("2009\-12\-28") succeeded:
168     tm_sec   = 36
169     tm_min   = 3
170     tm_hour  = 6
171     tm_mday  = 28
172     tm_mon   = 11
173     tm_year  = 109
174     tm_wday  = 1
175     tm_yday  = 361
176     tm_isdst = 0
177 Call 3 ("12:22:33") succeeded:
178     tm_sec   = 33
179     tm_min   = 22
180     tm_hour  = 12
181     tm_mday  = 7
182     tm_mon   = 8
183     tm_year  = 108
184     tm_wday  = 0
185     tm_yday  = 250
186     tm_isdst = 1
187 .fi
188 .in
189 .SS プログラムのソース
190 \&
191 .nf
192 #define _GNU_SOURCE 500
193 #include <time.h>
194 #include <stdio.h>
195 #include <stdlib.h>
196
197 int
198 main(int argc, char *argv[])
199 {
200     struct tm *tmp;
201     int j;
202
203     for (j = 1; j < argc; j++) {
204         tmp = getdate(argv[j]);
205
206         if (tmp == NULL) {
207             printf("Call %d failed; getdate_err = %d\en",
208                    j, getdate_err);
209             continue;
210         }
211
212         printf("Call %d (\e"%s\e") succeeded:\en", j, argv[j]);
213         printf("    tm_sec   = %d\en", tmp\->tm_sec);
214         printf("    tm_min   = %d\en", tmp\->tm_min);
215         printf("    tm_hour  = %d\en", tmp\->tm_hour);
216         printf("    tm_mday  = %d\en", tmp\->tm_mday);
217         printf("    tm_mon   = %d\en", tmp\->tm_mon);
218         printf("    tm_year  = %d\en", tmp\->tm_year);
219         printf("    tm_wday  = %d\en", tmp\->tm_wday);
220         printf("    tm_yday  = %d\en", tmp\->tm_yday);
221         printf("    tm_isdst = %d\en", tmp\->tm_isdst);
222     }
223
224     exit(EXIT_SUCCESS);
225 }
226 .fi
227 .SH 関連項目
228 \fBtime\fP(2), \fBlocaltime\fP(3), \fBsetlocale\fP(3), \fBstrftime\fP(3), \fBstrptime\fP(3)
229 .SH この文書について
230 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.50 の一部
231 である。プロジェクトの説明とバグ報告に関する情報は
232 http://www.kernel.org/doc/man\-pages/ に書かれている。