OSDN Git Service

(split) LDP v3.24 -> v3.29 の定型的な変更内容を反映。
[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)