OSDN Git Service

ac0911be18b3d961d83d98ef0348e817d9baf40d
[linuxjm/LDP_man-pages.git] / draft / man3 / stdin.3
1 .\" From dholland@burgundy.eecs.harvard.edu Tue Mar 24 18:08:15 1998
2 .\"
3 .\" This man page was written in 1998 by David A. Holland
4 .\" and placed in the Public Domain. Polished a bit by aeb.
5 .\" 2005-06-16 mtk, mentioned freopen()
6 .\"
7 .\" 2007-12-08, mtk, Converted from mdoc to man macros
8 .\"
9 .\" Japanese Version Copyright (c) 1998 NAKANO Takeo all rights reserved.
10 .\" Translated 1998-03-22, NAKANO Takeo <nakano@apm.seikei.ac.jp>
11 .\" Updated 2005-09-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
12 .\"
13 .TH STDIN 3 2008-07-14 "Linux" "Linux Programmer's Manual"
14 .\"O .SH NAME
15 .\"O stdin, stdout, stderr \- standard I/O streams
16 .SH 名前
17 stdin, stdout, stderr \- 標準入出力ストリーム
18 .\"O .SH SYNOPSIS
19 .SH 書式
20 .nf
21 .B #include <stdio.h>
22
23 .BI "extern FILE *" stdin ;
24 .BI "extern FILE *" stdout ;
25 .BI "extern FILE *" stderr ;
26 .fi
27 .\"O .SH DESCRIPTION
28 .SH 説明
29 .\"O Under normal circumstances every UNIX program has three streams opened
30 .\"O for it when it starts up, one for input, one for output, and one for
31 .\"O printing diagnostic or error messages.
32 .\"O These are typically attached to
33 .\"O the user's terminal (see
34 .\"O .BR tty (4))
35 .\"O but might instead refer to files or other devices, depending on what
36 .\"O the parent process chose to set up.
37 .\"O (See also the "Redirection" section of
38 .\"O .BR sh (1).)
39 標準の環境では、 UNIX プログラムは起動時に、オープンされているストリー
40 ムを 3 つ与えられる。それぞれ入力用、出力用、診断メッセージやエラーメッ
41 セージの表示用のものである。これらは通常ユーザの端末
42 .RB ( tty (4)
43 を見よ) に接続されているが、親プロセスでの選択・設定によってファイル
44 や他のデバイスに関連づけられていることもある
45 .RB ( sh (1)
46 の「リダイレクション」セクションも参照のこと)。
47 .PP
48 .\"O The input stream is referred to as "standard input"; the output stream is
49 .\"O referred to as "standard output"; and the error stream is referred to
50 .\"O as "standard error".
51 .\"O These terms are abbreviated to form the symbols
52 .\"O used to refer to these files, namely
53 .\"O .IR stdin ,
54 .\"O .IR stdout ,
55 .\"O and
56 .\"O .IR stderr .
57 入力ストリームは "standard input" と呼ばれる。出力ストリームは
58 "standard output"、エラーストリームは "standard error" と呼ばれる。
59 これらの用語を短縮したものがそれぞれのファイルを示すシンボルとなる。つ
60 まり
61 .IR stdin ,
62 .IR stdout ,
63 .I stderr
64 である。
65 .PP
66 .\"O Each of these symbols is a
67 .\"O .BR stdio (3)
68 .\"O macro of type pointer to FILE, and can be used with functions like
69 .\"O .BR fprintf (3)
70 .\"O or
71 .\"O .BR fread (3).
72 これらのシンボルは
73 .BR stdio (3)
74 のマクロで、 FILE へのポインタ型である。したがって
75 .BR fprintf (3)
76
77 .BR fread (3)
78 などの関数とともに用いることができる。
79 .PP
80 .\"O Since
81 .\"O .IR FILE s
82 .\"O are a buffering wrapper around UNIX file descriptors, the
83 .\"O same underlying files may also be accessed using the raw UNIX file
84 .\"O interface, that is, the functions like
85 .\"O .BR read (2)
86 .\"O and
87 .\"O .BR lseek (2).
88 .I FILE
89 は UNIX のファイルディスクリプタにバッファ機能を追加したラッパー
90 であるから、これらのマクロにも対応するファイルがあり、 UNIX の raw ファ
91 イルインタフェース
92 .RB ( read (2)
93
94 .BR lseek (2)
95 など) によってアクセスすることもできる。
96 .PP
97 .\"O On program startup, the integer file descriptors
98 .\"O associated with the streams
99 .\"O .IR stdin ,
100 .\"O .IR stdout ,
101 .\"O and
102 .\"O .I stderr
103 .\"O are 0, 1, and 2, respectively.
104 .\"O The preprocessor symbols
105 .\"O .BR STDIN_FILENO ,
106 .\"O .BR STDOUT_FILENO ,
107 .\"O and
108 .\"O .B STDERR_FILENO
109 .\"O are defined with these values in
110 .\"O \fI<unistd.h>\fP.
111 .\"O (Applying
112 .\"O .BR freopen (3)
113 .\"O to one of these streams can change the file descriptor number
114 .\"O associated with the stream.)
115 プログラムの起動時には、
116 ストリーム
117 .IR stdin ,
118 .IR stdout ,
119 .I stderr
120 に結びつけられているファイルディスクリプタの番号は、
121 それぞれ 0, 1, 2 である。
122 プリプロセッサシンボル
123 .BR STDIN_FILENO ,
124 .BR STDOUT_FILENO ,
125 .B STDERR_FILENO
126
127 .I <unistd.h>
128 中でそれぞれこれらの値に定義されている。
129 (これらのストリームに対して
130 .BR freopen (3)
131 を適用することで、そのストリームに関連付けられたファイルディスクリプタ
132 の番号を変更することができる。)
133 .PP
134 .\"O Note that mixing use of
135 .\"O .IR FILE s
136 .\"O and raw file descriptors can produce
137 .\"O unexpected results and should generally be avoided.
138 .\"O (For the masochistic among you: POSIX.1, section 8.2.3, describes
139 .\"O in detail how this interaction is supposed to work.)
140 .\"O A general rule is that file descriptors are handled in the kernel,
141 .\"O while stdio is just a library.
142 .\"O This means for example, that after an
143 .\"O .BR exec (3),
144 .\"O the child inherits all open file descriptors, but all old streams
145 .\"O have become inaccessible.
146 .I FILE
147 と raw なファイルディスクリプタの併用は、予期できない結果を生じ
148 ることがあるので、通常は避けるべきである。 (マゾヒスティックな人に:
149 POSIX.1 のセクション 8.2.3 には、この混用で動作がどのようになりそう
150 かが詳しく記述されている。)
151 一般的なルールは以下の通り: ファイルディスクリプタはカーネルによって
152 扱われ、 stdio は単にライブラリによって扱われるのである。すなわち例えば
153 .BR exec (3)
154 の後には、子プロセスはオープンされているファイルディスクリプタ
155 をすべて継承するが、親からのストリームはすべてアクセス不可となる。
156 .PP
157 .\"O Since the symbols
158 .\"O .IR stdin ,
159 .\"O .IR stdout ,
160 .\"O and
161 .\"O .I stderr
162 .\"O are specified to be macros, assigning to them is nonportable.
163 .\"O The standard streams can be made to refer to different files
164 .\"O with help of the library function
165 .\"O .BR freopen (3),
166 .\"O specially introduced to make it possible to reassign
167 .\"O .IR stdin ,
168 .\"O .IR stdout ,
169 .\"O and
170 .\"O .IR stderr .
171 .\"O The standard streams are closed by a call to
172 .\"O .BR exit (3)
173 .\"O and by normal program termination.
174 シンボル
175 .IR stdin ,
176 .IR stdout ,
177 .I stderr
178 はすべてマクロとして定義されているので、これらへの代入
179 は移植性を保証されない。標準ストリームはライブラリ関数
180 .BR freopen (3)
181 を用いれば、別のファイルを示すように変更することもできる。
182 このライブラリ関数は
183 .IR stdin ,
184 .IR stdout ,
185 .I stderr
186 の再割り当てが可能なように特別に導入されたものである。
187 標準ストリームは
188 .BR exit (3)
189 の呼び出しと、プログラムの正常終了によってクローズされる。
190 .\"O .SH "CONFORMING TO"
191 .SH 準拠
192 .\"O The
193 .\"O .IR stdin ,
194 .\"O .IR stdout ,
195 .\"O and
196 .\"O .I stderr
197 .\"O macros conform to C89
198 .\"O and this standard also stipulates that these three
199 .\"O streams shall be open at program startup.
200 .IR stdin ,
201 .IR stdout ,
202 .I stderr
203 マクロは C89 に準拠している。
204 また C89 では、これら 3 つのストリームがプログラム
205 の起動時にオープンされているべきであることが規定されている。
206 .\"O .SH NOTES
207 .SH 注意
208 .\"O The stream
209 .\"O .I stderr
210 .\"O is unbuffered.
211 .\"O The stream
212 .\"O .I stdout
213 .\"O is line-buffered when it points to a terminal.
214 .\"O Partial lines will not
215 .\"O appear until
216 .\"O .BR fflush (3)
217 .\"O or
218 .\"O .BR exit (3)
219 .\"O is called, or a newline is printed.
220 .\"O This can produce unexpected
221 .\"O results, especially with debugging output.
222 .I stderr
223 ストリームはバッファリングされていない。
224 .I stdout
225 ストリームは、端末に接続されているときには行単位でバッファリング
226 されている。一行に満たない内容は、
227 .BR fflush (3)
228
229 .BR exit (3)
230 が呼び出されるか、改行文字が印字されるまで表示されない。これは、
231 特にデバッグ時において、予期しない結果を生じる原因となるかもしれない。
232 .\"O The buffering mode of the standard streams (or any other stream)
233 .\"O can be changed using the
234 .\"O .BR setbuf (3)
235 .\"O or
236 .\"O .BR setvbuf (3)
237 .\"O call.
238 標準ストリームの (あるいは他のすべてのストリームの)
239 バッファリングモードは、
240 .BR setbuf (3)
241 または
242 .BR setvbuf (3)
243 を呼び出すことによって変更できる。
244 .\"O Note that in case
245 .\"O .I stdin
246 .\"O is associated with a terminal, there may also be input buffering
247 .\"O in the terminal driver, entirely unrelated to stdio buffering.
248 .\"O (Indeed, normally terminal input is line buffered in the kernel.)
249 .\"O This kernel input handling can be modified using calls like
250 .\"O .BR tcsetattr (3);
251 .\"O see also
252 .\"O .BR stty (1),
253 .\"O and
254 .\"O .BR termios (3).
255 ただし、
256 .I stdin
257 が端末に接続されているときは、端末のドライバでバッファリングされている
258 可能性がある点にも注意すること。これは stdio のバッファリングとは全く
259 関係なく存在しうる。 (実際、通常だと端末入力はカーネルによって行単位
260 でバッファリングされている。) このカーネルによる入力の扱いは
261 .BR tcsetattr (3)
262 などの呼び出しによって変更することができる。
263 .BR stty (1)
264
265 .BR termios (3)
266 も参照すること。
267 .\"O .SH SEE ALSO
268 .SH 関連項目
269 .BR csh (1),
270 .BR sh (1),
271 .BR open (2),
272 .BR fopen (3),
273 .BR stdio (3)