1 .\" From dholland@burgundy.eecs.harvard.edu Tue Mar 24 18:08:15 1998
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()
7 .\" 2007-12-08, mtk, Converted from mdoc to man macros
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>
13 .TH STDIN 3 2008-07-14 "Linux" "Linux Programmer's Manual"
15 .\"O stdin, stdout, stderr \- standard I/O streams
17 stdin, stdout, stderr \- 標準入出力ストリーム
23 .BI "extern FILE *" stdin ;
24 .BI "extern FILE *" stdout ;
25 .BI "extern FILE *" stderr ;
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
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
39 標準の環境では、 UNIX プログラムは起動時に、オープンされているストリー
40 ムを 3 つ与えられる。それぞれ入力用、出力用、診断メッセージやエラーメッ
41 セージの表示用のものである。これらは通常ユーザの端末
43 を見よ) に接続されているが、親プロセスでの選択・設定によってファイル
44 や他のデバイスに関連づけられていることもある
46 の「リダイレクション」セクションも参照のこと)。
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
57 入力ストリームは "standard input" と呼ばれる。出力ストリームは
58 "standard output"、エラーストリームは "standard error" と呼ばれる。
59 これらの用語を短縮したものがそれぞれのファイルを示すシンボルとなる。つ
66 .\"O Each of these symbols is a
68 .\"O macro of type pointer to FILE, and can be used with functions like
74 のマクロで、 FILE へのポインタ型である。したがって
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
89 は UNIX のファイルディスクリプタにバッファ機能を追加したラッパー
90 であるから、これらのマクロにも対応するファイルがあり、 UNIX の raw ファ
97 .\"O On program startup, the integer file descriptors
98 .\"O associated with the streams
103 .\"O are 0, 1, and 2, respectively.
104 .\"O The preprocessor symbols
105 .\"O .BR STDIN_FILENO ,
106 .\"O .BR STDOUT_FILENO ,
108 .\"O .B STDERR_FILENO
109 .\"O are defined with these values in
110 .\"O \fI<unistd.h>\fP.
113 .\"O to one of these streams can change the file descriptor number
114 .\"O associated with the stream.)
120 に結びつけられているファイルディスクリプタの番号は、
131 を適用することで、そのストリームに関連付けられたファイルディスクリプタ
134 .\"O Note that mixing use of
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
144 .\"O the child inherits all open file descriptors, but all old streams
145 .\"O have become inaccessible.
147 と raw なファイルディスクリプタの併用は、予期できない結果を生じ
148 ることがあるので、通常は避けるべきである。 (マゾヒスティックな人に:
149 POSIX.1 のセクション 8.2.3 には、この混用で動作がどのようになりそう
151 一般的なルールは以下の通り: ファイルディスクリプタはカーネルによって
152 扱われ、 stdio は単にライブラリによって扱われるのである。すなわち例えば
154 の後には、子プロセスはオープンされているファイルディスクリプタ
155 をすべて継承するが、親からのストリームはすべてアクセス不可となる。
157 .\"O Since the symbols
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
171 .\"O The standard streams are closed by a call to
173 .\"O and by normal program termination.
178 はすべてマクロとして定義されているので、これらへの代入
179 は移植性を保証されない。標準ストリームはライブラリ関数
181 を用いれば、別のファイルを示すように変更することもできる。
186 の再割り当てが可能なように特別に導入されたものである。
189 の呼び出しと、プログラムの正常終了によってクローズされる。
190 .\"O .SH "CONFORMING TO"
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.
204 また C89 では、これら 3 つのストリームがプログラム
205 の起動時にオープンされているべきであることが規定されている。
213 .\"O is line-buffered when it points to a terminal.
214 .\"O Partial lines will not
219 .\"O is called, or a newline is printed.
220 .\"O This can produce unexpected
221 .\"O results, especially with debugging output.
225 ストリームは、端末に接続されているときには行単位でバッファリング
230 が呼び出されるか、改行文字が印字されるまで表示されない。これは、
231 特にデバッグ時において、予期しない結果を生じる原因となるかもしれない。
232 .\"O The buffering mode of the standard streams (or any other stream)
233 .\"O can be changed using the
238 標準ストリームの (あるいは他のすべてのストリームの)
244 .\"O Note that in case
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);
254 .\"O .BR termios (3).
257 が端末に接続されているときは、端末のドライバでバッファリングされている
258 可能性がある点にも注意すること。これは stdio のバッファリングとは全く
259 関係なく存在しうる。 (実際、通常だと端末入力はカーネルによって行単位
260 でバッファリングされている。) このカーネルによる入力の扱いは
262 などの呼び出しによって変更することができる。