OSDN Git Service

(split) LDP v3.24 -> v3.29 の定型的な変更内容を反映。
[linuxjm/LDP_man-pages.git] / draft / man3 / fopen.3
1 .\" Copyright (c) 1990, 1991 The Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" Chris Torek and the American National Standards Committee X3,
6 .\" on Information Processing Systems.
7 .\"
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
10 .\" are met:
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\"    notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\"    notice, this list of conditions and the following disclaimer in the
15 .\"    documentation and/or other materials provided with the distribution.
16 .\" 3. All advertising materials mentioning features or use of this software
17 .\"    must display the following acknowledgement:
18 .\"     This product includes software developed by the University of
19 .\"     California, Berkeley and its contributors.
20 .\" 4. Neither the name of the University nor the names of its contributors
21 .\"    may be used to endorse or promote products derived from this software
22 .\"    without specific prior written permission.
23 .\"
24 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" SUCH DAMAGE.
35 .\"
36 .\"     @(#)fopen.3     6.8 (Berkeley) 6/29/91
37 .\"
38 .\" Converted for Linux, Mon Nov 29 15:22:01 1993, faith@cs.unc.edu
39 .\" Modified, aeb, 960421, 970806
40 .\" Modified, joey, aeb, 2002-01-03
41 .\"
42 .\" Japanese Version Copyright (c) 1997 YOSHINO Takashi
43 .\"       all rights reserved.
44 .\" Translated Thu Feb 13 12:10:38 JST 1997
45 .\"       by YOSHINO Takashi <yoshino@civil.jcn.nihon-u.ac.jp>
46 .\" Updated & Modified Mon Mar 1 1999
47 .\"       by NAKANO Takeo <nakano@apm.seikei.ac.jp>
48 .\" Updated 1999-12-08, Kentaro Shirakata <argrath@ub32.org>
49 .\" Updated 2001-12-13, Kentaro Shirakata <argrath@ub32.org>
50 .\" Updated 2002-03-23, Kentaro Shirakata <argrath@ub32.org>
51 .\" Updated 2005-10-15, Kentaro Shirakata <argrath@ub32.org>
52 .\" Updated 2006-07-20, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
53 .\"
54 .\"WORD:        file descriptor         ¥Õ¥¡¥¤¥ëµ­½Ò»Ò
55 .\"WORD:        file position indicator ¥Õ¥¡¥¤¥ë°ÌÃֻؼ¨»Ò
56 .\"WORD:        indicator               »Ø¼¨»Ò
57 .\"WORD:        global variable         Âç°èÊÑ¿ô
58 .\"WORD:        cancellation points     ¼è¤ê¾Ã¤·¥Ý¥¤¥ó¥È
59 .\"
60 .TH FOPEN 3  2009-02-23 "GNU" "Linux Programmer's Manual"
61 .SH Ì¾Á°
62 .\"O fopen, fdopen, freopen \- stream open functions
63 fopen, fdopen, freopen \- ¥¹¥È¥ê¡¼¥à¤ò³«¤¯´Ø¿ô
64 .SH ½ñ¼°
65 .nf
66 .B #include <stdio.h>
67 .sp
68 .BI "FILE *fopen(const char *" path ", const char *" mode );
69
70 .BI "FILE *fdopen(int " fd ", const char *" mode );
71
72 .BI "FILE *freopen(const char *" path ", const char *" mode ", FILE *" stream );
73 .fi
74 .sp
75 .in -4n
76 .\"O Feature Test Macro Requirements for glibc (see
77 .\"O .BR feature_test_macros (7)):
78 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
79 .RB ( feature_test_macros (7)
80 »²¾È):
81 .in
82 .sp
83 .BR fdopen ():
84 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _POSIX_SOURCE
85 .SH ÀâÌÀ
86 .\"O The
87 .\"O .BR fopen ()
88 .\"O function opens the file whose name is the string pointed to by
89 .\"O .I path
90 .\"O and associates a stream with it.
91 .BR fopen ()
92 ´Ø¿ô¤Ï¡¢
93 .I path
94 ¤Ç»ØÄꤵ¤ì¤¿Ì¾Á°¤Î¥Õ¥¡¥¤¥ë¤ò³«¤­¡¢¥¹¥È¥ê¡¼¥à¤È·ë¤Ó¤Ä¤±¤ë¡£
95 .PP
96 .\"O The argument
97 .\"O .I mode
98 .\"O points to a string beginning with one of the following sequences
99 .\"O (Additional characters may follow these sequences.):
100 °ú¿ô
101 .I mode
102 ¤Ï¡¢°Ê²¼¤Ë³¤¯Ê¸»ú¤Î¤Ò¤È¤Ä¤«¤é»Ï¤Þ¤ëʸ»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë
103 (ÄɲäÎʸ»ú¤¬¤³¤Îʸ»ú¤Î¸å¤Ë³¤¯¤³¤È¤â¤¢¤ë):
104 .TP
105 .B r
106 .\"O Open text file for reading.
107 .\"O The stream is positioned at the beginning of the file.
108 ¥Æ¥­¥¹¥È¥Õ¥¡¥¤¥ë¤òÆɤ߽Ф¹¤¿¤á¤Ë³«¤¯¡£
109 ¥¹¥È¥ê¡¼¥à¤Ï¥Õ¥¡¥¤¥ë¤ÎÀèƬ¤Ë°ÌÃÖ¤µ¤ì¤ë¡£
110 .TP
111 .B r+
112 .\"O Open for reading and writing.
113 .\"O The stream is positioned at the beginning of the file.
114 Æɤ߽Ф·¤ª¤è¤Ó½ñ¤­¹þ¤ß¤¹¤ë¤¿¤á¤Ë³«¤¯¡£
115 ¥¹¥È¥ê¡¼¥à¤Ï¥Õ¥¡¥¤¥ë¤ÎÀèƬ¤Ë°ÌÃÖ¤µ¤ì¤ë¡£
116 .TP
117 .B w
118 .\"O Truncate file to zero length or create text file for writing.
119 .\"O The stream is positioned at the beginning of the file.
120 ¥Õ¥¡¥¤¥ë¤ò½ñ¤­¹þ¤ß¤Î¤¿¤á¤Ë³«¤¯¡£
121 ¥Õ¥¡¥¤¥ë¤¬´û¤Ë¸ºß¤¹¤ë¾ì¹ç¤Ë¤ÏŤµ¥¼¥í¤ËÀÚ¤êµÍ¤á¤ë¡£
122 ¥Õ¥¡¥¤¥ë¤¬¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¤Ï¿·¤¿¤ËºîÀ®¤¹¤ë¡£
123 ¥¹¥È¥ê¡¼¥à¤Ï¥Õ¥¡¥¤¥ë¤ÎÀèƬ¤Ë°ÌÃÖ¤µ¤ì¤ë¡£
124 .TP
125 .B w+
126 .\"O Open for reading and writing.
127 .\"O The file is created if it does not exist, otherwise it is truncated.
128 .\"O The stream is positioned at the beginning of the file.
129 Æɤ߽Ф·¤ª¤è¤Ó½ñ¤­¹þ¤ß¤Î¤¿¤á¤Ë³«¤¯¡£
130 ¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Ï¿·¤¿¤ËºîÀ®¤¹¤ë¡£
131 ¸ºß¤·¤Æ¤¤¤ë¾ì¹ç¤Ë¤ÏŤµ¥¼¥í¤ËÀÚ¤êµÍ¤á¤é¤ì¤ë¡£
132 ¥¹¥È¥ê¡¼¥à¤Ï¥Õ¥¡¥¤¥ë¤ÎÀèƬ¤Ë°ÌÃÖ¤µ¤ì¤ë¡£
133 .TP
134 .B a
135 .\"O Open for appending (writing at end of file).
136 .\"O The file is created if it does not exist.
137 .\"O The stream is positioned at the end of the file.
138 Äɲà(¥Õ¥¡¥¤¥ë¤ÎºÇ¸å¤Ë½ñ¤­¹þ¤à) ¤Î¤¿¤á¤Ë³«¤¯¡£
139 ¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Ï¿·¤¿¤ËºîÀ®¤¹¤ë¡£
140 ¥¹¥È¥ê¡¼¥à¤Ï¥Õ¥¡¥¤¥ë¤ÎºÇ¸å¤Ë°ÌÃÖ¤µ¤ì¤ë¡£
141 .TP
142 .B a+
143 .\"O Open for reading and appending (writing at end of file).
144 .\"O The file is created if it does not exist.
145 .\"O The initial file position for reading is at the beginning of the file,
146 .\"O but output is always appended to the end of the file.
147 Æɤ߽Ф·¤ª¤è¤ÓÄɲà(¥Õ¥¡¥¤¥ë¤ÎºÇ¸å¤Ë½ñ¤­¹þ¤à) ¤Î¤¿¤á¤Ë³«¤¯¡£
148 ¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Ï¿·¤¿¤ËºîÀ®¤¹¤ë¡£
149 Æɤ߽Ф·¤Î½é´ü¥Õ¥¡¥¤¥ë°ÌÃ֤ϥե¡¥¤¥ë¤ÎÀèƬ¤Ç¤¢¤ë¤¬¡¢
150 ½ñ¤­¹þ¤ß¤Ï¾ï¤Ë¥Õ¥¡¥¤¥ë¤ÎºÇ¸å¤ËÄɲ䵤ì¤ë¡£
151 .PP
152 .\"O The
153 .\"O .I mode
154 .\"O string can also include the letter \(aqb\(aq either as a last character or as
155 .\"O a character between the characters in any of the two-character strings
156 .\"O described above.
157 .\"O This is strictly for compatibility with C89
158 .\"O and has no effect; the \(aqb\(aq is ignored on all POSIX
159 .\"O conforming systems, including Linux.
160 .I mode
161 ʸ»úÎó¤Ë¤Ïʸ»ú \(aqb\(aq ¤òÄɲûØÄꤹ¤ë¤³¤È¤¬¤Ç¤­¡¢
162 .I mode
163 ʸ»úÎó¤ÎºÇ¸å¤Îʸ»ú¤È¤·¤Æ»ØÄꤹ¤ë¡£
164 ¾åµ­¤Î¤¦¤Á 2 Ê¸»ú¤Î¥â¡¼¥É¤Î¾ì¹ç¤Ë¤Ï 2 ¤Ä¤Îʸ»ú¤Î´Ö¤Ë»ØÄꤹ¤ë¤³¤È¤â¤Ç¤­¤ë¡£
165 ¤³¤ì¤Ï C89 ¤È¤Î¸ß´¹À­¤Î¤¿¤á¤À¤±¤ËÍÑ°Õ¤µ¤ì¤¿
166 ¤â¤Î¤Ç¤¢¤ê¡¢´Ø¿ô¤Î¼Â¹Ô¤ËÂФ·¤Æ¤Ï¤¤¤«¤Ê¤ë±Æ¶Á¤â»ý¤¿¤Ê¤¤¡£
167 ¤¹¤Ê¤ï¤Á¡¢Linux ¤ò´Þ¤àÁ´¤Æ¤Î POSIX ½àµò¥·¥¹¥Æ¥à¤Ç¤Ï¡¢
168 ¤³¤Î \(aqb\(aq ¤Ï̵»ë¤µ¤ì¤ë¡£
169 .\"O (Other systems may treat text files and binary files differently,
170 .\"O and adding the \(aqb\(aq may be a good idea if you do I/O to a binary
171 .\"O file and expect that your program may be ported to non-UNIX
172 .\"O environments.)
173 (¤½¤Î¾¤Î¥·¥¹¥Æ¥à¤Ç¤Ï¥Æ¥­¥¹¥È¥Õ¥¡¥¤¥ë¤È¥Ð¥¤¥Ê¥ê¥Õ¥¡¥¤¥ë¤òÊÌ¡¹¤Ë°·¤¦¤â¤Î¤â¤¢¤ë¤Î¤Ç¡¢
174 ¤â¤·¥Ð¥¤¥Ê¥ê¥Õ¥¡¥¤¥ë¤ÎÆþ½ÐÎϤò¹Ô¤¤¡¢
175 ¤½¤Î¥×¥í¥°¥é¥à¤¬Èó UNIX ´Ä¶­¤Ø°Ü¿¢¤µ¤ì¤ë¤Èͽ¬¤¹¤ë¤Ê¤é¡¢
176 \(aqb\(aq¤òÉÕ¤±¤Æ¤ª¤¯¤Î¤ÏÎɤ¤¹Í¤¨¤Ç¤¢¤ë)
177 .PP
178 .\"O See NOTES below for details of glibc extensions for
179 .\"O .IR mode .
180 .I mode
181 ¤Î glibc ¤Ë¤è¤ë³ÈÄ¥¤Î¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï²¼µ­¤Î¡ÖÃí°Õ¡×¤ò»²¾È¡£
182 .PP
183 .\"O Any created files will have mode
184 .\"O .BR S_IRUSR " | " S_IWUSR " | "  S_IRGRP " | "  S_IWGRP " | " S_IROTH " | " S_IWOTH
185 .\"O (0666), as modified by the process's umask value (see
186 .\"O .BR umask (2)).
187 ¤¹¤Ù¤Æ¤ÎÀ¸À®¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ï¡¢
188 .BR S_IRUSR " | " S_IWUSR " | "  S_IRGRP " | "  S_IWGRP " | " S_IROTH " | " S_IWOTH
189 (0666) ¤Î¥â¡¼¥É¤ò
190 ¤½¤Î¥×¥í¥»¥¹¤Î umask Ãͤˤè¤Ã¤Æ½¤Àµ¤·¤¿¥â¡¼¥É¤ò»ý¤Ä
191 .RB ( umask (2)
192 ¤ò¸«¤è)¡£
193 .PP
194 .\"O Reads and writes may be intermixed on read/write streams in any order.
195 .\"O Note that ANSI C requires that a file positioning function intervene
196 .\"O between output and input, unless an input operation encounters end-of-file.
197 .\"O (If this condition is not met, then a read is allowed to return the
198 .\"O result of writes other than the most recent.)
199 .\"O Therefore it is good practice (and indeed sometimes necessary
200 .\"O under Linux) to put an
201 .\"O .BR fseek (3)
202 .\"O or
203 .\"O .BR fgetpos (3)
204 .\"O operation between write and read operations on such a stream.
205 .\"O This operation may be an apparent no-op
206 .\"O (as in \fIfseek(..., 0L, SEEK_CUR)\fP
207 .\"O called for its synchronizing side effect.
208 Æɤ߽Ф·/½ñ¤­¹þ¤ß¥¹¥È¥ê¡¼¥à¤ËÂФ·¤Æ¤ÏǤ°Õ¤Î½ç½ø¤ÇÆɤ߽ñ¤­¤ò¹Ô¤¦¤³¤È¤¬¤Ç¤­¤ë¡£
209 ¤¿¤À¤· ANSI C ¤Ç¤Ï¡¢
210 (ÆþÎÏÁàºî¤¬¥Õ¥¡¥¤¥ë¤ÎËöÈø¤ËÅþ㤷¤¿¾ì¹ç¤ò½ü¤¤¤Æ)
211 ½ÐÎϤÈÆþÎϤδ֤ˤϥե¡¥¤¥ë¤Î°ÌÃÖ·è¤á´Ø¿ô¤ò
212 ¶´¤Þ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤³¤È¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤³¤È¤ËÃí°Õ¤µ¤ì¤¿¤¤
213 (¤³¤Î¾ò·ï¤òËþ­¤·¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢Æɤ߹þ¤ßÁàºî¤Ï¡¢
214 ºÇ¸å¤Ë½ñ¤­¹þ¤Þ¤ì¤¿¤â¤Î¤Ç¤Ê¤¯¡¢°ÊÁ°¤Ë½ñ¤­¹þ¤Þ¤ì¤¿
215 ÃͤòÊÖ¤¹¤³¤È¤òµö¤µ¤ì¤Æ¤¤¤ë)¡£
216 ¤·¤¿¤¬¤Ã¤Æ¡¢¤³¤Î¤è¤¦¤Ê¥¹¥È¥ê¡¼¥à¤Ç¤ÎÆɤ߽ñ¤­Áàºî¤Î´Ö¤Ë¤Ï
217 .BR fseek (3)
218 ¤Þ¤¿¤Ï
219 .BR fgetpos (3)
220 Áàºî¤ò¶´¤ó¤Ç¤ª¤¯¤ÈÎɤ¤¤À¤í¤¦
221 (Linux ¤Ç¤ÏËÜÅö¤ËɬÍפȤʤ뤳¤È¤â¤È¤­¤É¤­¤¢¤ë)¡£
222 ¤³¤ÎÁàºî¤Ï¸«¤«¤±¾å²¿¤â¤·¤Ê¤¤Áàºî (no-op) ¤Ç¤âÎɤ¤
223 (Î㤨¤Ð \fIfseek(..., 0L, SEEK_CUR)\fP ¤ò
224 ¤½¤ÎÉû¼¡Åª¸ú²Ì¤Ç¤¢¤ëƱ´ü¤Î¤¿¤á¤À¤±¤Ë¸Æ¤Ù¤ÐÎɤ¤)¡£
225 .PP
226 .\"O Opening a file in append mode (\fBa\fP as the first character of
227 .\"O .IR mode )
228 .\"O causes all subsequent write operations to this stream to occur
229 .\"O at end-of-file, as if preceded by an
230 .\"O .nf
231 .\"O 
232 .\"O     fseek(stream,0,SEEK_END);
233 .\"O .fi
234 .\"O .PP
235 .\"O call.
236 ¥Õ¥¡¥¤¥ë¤òÄɲå⡼¥É
237 .RI ( mode
238 ¤ÎºÇ½é¤Îʸ»ú¤ò \fBa\fP ¤Ë¤¹¤ë) ¤Ç³«¤¯¤È¡¢
239 ¤³¤Î¥¹¥È¥ê¡¼¥à¤ËÂФ¹¤ë½ñ¤­¹þ¤ßÁàºî¤Ï (Àè¤Ë
240 .nf
241
242     fseek(stream,0,SEEK_END);
243
244 .fi
245 ¤Î¸Æ¤Ó½Ð¤·¤ò¼Â¹Ô¤·¤¿¤«¤Î¤è¤¦¤Ë) ¥Õ¥¡¥¤¥ëËöÈø¤ËÂФ·¤Æ¹Ô¤ï¤ì¤ë¡£
246 .PP
247 .\"O The
248 .\"O .BR fdopen ()
249 .\"O function associates a stream with the existing file descriptor,
250 .\"O .IR fd .
251 .BR fdopen ()
252 ´Ø¿ô¤Ï¡¢´û¸¤Î¥Õ¥¡¥¤¥ëµ­½Ò»Ò
253 .I fd
254 ¤Ë¥¹¥È¥ê¡¼¥à¤ò·ë¤Ó¤Ä¤±¤ë¡£
255 .\"O The
256 .\"O .I mode
257 .\"O of the stream (one of the values "r", "r+", "w", "w+", "a", "a+")
258 .\"O must be compatible with the mode of the file descriptor.
259 ¥¹¥È¥ê¡¼¥à¤Î
260 .I mode
261 ("r", "r+", "w", "w+", "a", "a+" ¤Î¤¤¤º¤ì¤«) ¤Ï
262 ¥Õ¥¡¥¤¥ëµ­½Ò»Ò¤Î¥â¡¼¥É¤È¸ß´¹¤Î¤â¤Î¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
263 .\"O The file position indicator of the new stream is set to that
264 .\"O belonging to
265 .\"O .IR fd ,
266 .\"O and the error and end-of-file indicators are cleared.
267 .\"O Modes "w" or "w+" do not cause truncation of the file.
268 ¿·¤·¤¤¥¹¥È¥ê¡¼¥à¤Î¥Õ¥¡¥¤¥ë°ÌÃֻؼ¨»Ò¤Ï
269 .I fd
270 ¤Ë°¤·¤Æ¤¤¤ëÃͤËÀßÄꤵ¤ì¤ë¡£
271 error ¤È end-of-file ¤Î³Æ»Ø¼¨»Ò¤Ï¥¯¥ê¥¢¤µ¤ì¤ë¡£
272 "w" ¤ª¤è¤Ó "w+" ¥â¡¼¥É¤Ç¤Î¥Õ¥¡¥¤¥ë¤ÎÀÚ¤êµÍ¤á¤Ï¹Ô¤ï¤ì¤Ê¤¤¡£
273 .\"O The file descriptor is not dup'ed, and will be closed when
274 .\"O the stream created by
275 .\"O .BR fdopen ()
276 .\"O is closed.
277 .\"O The result of applying
278 .\"O .BR fdopen ()
279 .\"O to a shared memory object is undefined.
280 ¥Õ¥¡¥¤¥ëµ­½Ò»Ò¤ÎÊ£À½¤Ï¹Ô¤Ê¤ï¤ì¤Ê¤¤¡£
281 .BR fdopen ()
282 ¤ÇºîÀ®¤µ¤ì¤¿¥¹¥È¥ê¡¼¥à¤¬ÊĤ¸¤é¤ì¤¿¤È¤­¤Ë¥Õ¥¡¥¤¥ëµ­½Ò»Ò¤â
283 ÊĤ¸¤é¤ì¤ë¡£
284 ¶¦Í­¥á¥â¥ê¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ø
285 .BR fdopen ()
286 ¤ò¹Ô¤Ã¤¿¤È¤­¤Î·ë²Ì¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
287 .PP
288 .\"O The
289 .\"O .BR freopen ()
290 .\"O function opens the file whose name is the string pointed to by
291 .\"O .I path
292 .\"O and associates the stream pointed to by
293 .\"O .I stream
294 .\"O with it.
295 .\"O The original stream (if it exists) is closed.
296 .\"O The
297 .\"O .I mode
298 .\"O argument is used just as in the
299 .\"O .BR fopen ()
300 .\"O function.
301 .\"O The primary use of the
302 .\"O .BR freopen ()
303 .\"O function is to change the file associated with a standard text stream
304 .\"O .RI ( stderr ", " stdin ", or " stdout ).
305 .BR freopen ()
306 ´Ø¿ô¤Ï
307 .I path
308 ¤Ç̾Á°¤¬»ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤ò³«¤­¡¢
309 .I stream
310 ¤Ç»ØÄꤵ¤ì¤¿¥¹¥È¥ê¡¼¥à¤Ë¡¢¤½¤Î¥Õ¥¡¥¤¥ë¤ò·ë¤Ó¤Ä¤±¤ë¡£
311 ¤â¤È¤Î¥¹¥È¥ê¡¼¥à¤Ï (¤â¤·Â¸ºß¤¹¤ë¾ì¹ç¤Ë¤Ï) ÊĤ¸¤é¤ì¤ë¡£
312 .I mode
313 °ú¿ô¤Ï
314 .BR fopen ()
315 ´Ø¿ô¤ÈƱ¤¸·Á¤Ç»È¤ï¤ì¤ë¡£
316 .BR freopen ()
317 ´Ø¿ô¤Î¼ç¤ÊÍÑÅӤϡ¢É¸½à¥Æ¥­¥¹¥È¥¹¥È¥ê¡¼¥à
318 .RI ( stderr ", " stdin ", " stdout )
319 ¤ÈÂбþÉÕ¤±¤é¤ì¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¤òÊѹ¹¤¹¤ë¤³¤È¤Ç¤¢¤ë¡£
320 .SH ÊÖ¤êÃÍ
321 .\"O Upon successful completion
322 .\"O .BR fopen (),
323 .\"O .BR fdopen ()
324 .\"O and
325 .\"O .BR freopen ()
326 .\"O return a
327 .\"O .I FILE
328 .\"O pointer.
329 .\"O Otherwise, NULL is returned and
330 .\"O .I errno
331 .\"O is set to indicate the error.
332 .BR fopen (),
333 .BR fdopen (),
334 .BR freopen ()
335 ¤ÏÀ®¸ù¤¹¤ë¤È
336 .I FILE
337 ·¿¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
338 ¼ºÇÔ¤¹¤ë¤È NULL ¤¬ÊÖ¤µ¤ì¡¢
339 .I errno
340 ¤¬¥¨¥é¡¼¤ò¼¨¤¹Ãͤ˥»¥Ã¥È¤µ¤ì¤ë¡£
341 .SH ¥¨¥é¡¼
342 .TP
343 .B EINVAL
344 .\"O The
345 .\"O .I mode
346 .\"O provided to
347 .\"O .BR fopen (),
348 .\"O .BR fdopen (),
349 .\"O or
350 .\"O .BR freopen ()
351 .\"O was invalid.
352 .BR fopen (),
353 .BR fdopen (),
354 .BR freopen ()
355 ¤ÇÍ¿¤¨¤é¤ì¤¿
356 .I mode
357 ¤¬ÉÔŬÀڤǤ¢¤ë¡£
358 .PP
359 .\"O The
360 .\"O .BR fopen (),
361 .\"O .BR fdopen ()
362 .\"O and
363 .\"O .BR freopen ()
364 .\"O functions may also fail and set
365 .\"O .I errno
366 .\"O for any of the errors specified for the routine
367 .\"O .BR malloc (3).
368 .BR fopen (),
369 .BR fdopen (),
370 .BR freopen ()
371 ´Ø¿ô¤Ï
372 .BR malloc (3)
373 ¥ë¡¼¥Á¥ó¤Çµ¬Äꤵ¤ì¤Æ¤¤¤ë¥¨¥é¡¼¤Ç¤â¼ºÇÔ¤¹¤ë¤³¤È¤¬¤¢¤ê¡¢
374 ¤½¤Î»þ¤ÏÂбþ¤¹¤ëÃͤË
375 .I errno
376 ¤ò¥»¥Ã¥È¤¹¤ë¡£
377 .PP
378 .\"O The
379 .\"O .BR fopen ()
380 .\"O function may also fail and set
381 .\"O .I errno
382 .\"O for any of the errors specified for the routine
383 .\"O .BR open (2).
384 .BR fopen ()
385 ´Ø¿ô¤Ï
386 .BR open (2)
387 ¥ë¡¼¥Á¥ó¤Çµ¬Äꤵ¤ì¤Æ¤¤¤ë¥¨¥é¡¼¤Ç¤â¼ºÇÔ¤¹¤ë¤³¤È¤¬¤¢¤ê¡¢
388 ¤½¤Î»þ¤ÏÂбþ¤¹¤ëÃͤË
389 .I errno
390 ¤ò¥»¥Ã¥È¤¹¤ë¡£
391 .PP
392 .\"O The
393 .\"O .BR fdopen ()
394 .\"O function may also fail and set
395 .\"O .I errno
396 .\"O for any of the errors specified for the routine
397 .\"O .BR fcntl (2).
398 .BR fdopen ()
399 ´Ø¿ô¤Ï
400 .BR fcntl (2)
401 ¥ë¡¼¥Á¥ó¤Çµ¬Äꤵ¤ì¤Æ¤¤¤ë¥¨¥é¡¼¤Ç¤â¼ºÇÔ¤¹¤ë¤³¤È¤¬¤¢¤ê¡¢
402 ¤½¤Î»þ¤ÏÂбþ¤¹¤ëÃͤË
403 .I errno
404 ¤ò¥»¥Ã¥È¤¹¤ë¡£
405 .PP
406 .\"O The
407 .\"O .BR freopen ()
408 .\"O function may also fail and set
409 .\"O .I errno
410 .\"O for any of the errors specified for the routines
411 .\"O .BR open (2),
412 .\"O .BR fclose (3)
413 .\"O and
414 .\"O .BR fflush (3).
415 .BR freopen ()
416 ´Ø¿ô¤Ï
417 .BR open (2),
418 .BR fclose (3),
419 .BR fflush (3)
420 ³Æ¥ë¡¼¥Á¥ó¤Çµ¬Äꤵ¤ì¤Æ¤¤¤ë¥¨¥é¡¼¤Ç¤â¼ºÇÔ¤¹¤ë¤³¤È¤¬¤¢¤ê¡¢
421 ¤½¤Î»þ¤ÏÂбþ¤¹¤ëÃͤË
422 .I errno
423 ¤ò¥»¥Ã¥È¤¹¤ë¡£
424 .SH ½àµò
425 .\"O The
426 .\"O .BR fopen ()
427 .\"O and
428 .\"O .BR freopen ()
429 .\"O functions conform to C89.
430 .\"O The
431 .\"O .BR fdopen ()
432 .\"O function conforms to POSIX.1-1990.
433 .BR fopen ()
434 ´Ø¿ô¤È
435 .BR freopen ()
436 ´Ø¿ô¤Ï C89¤Ë½àµò¤·¤Æ¤¤¤ë¡£
437 .BR fdopen ()
438 ´Ø¿ô¤Ï POSIX.1-1990 ¤Ë½àµò¤·¤Æ¤¤¤ë¡£
439 .\"O .SH NOTES
440 .\"O .SS Glibc Notes
441 .SH Ãí°Õ
442 .SS glibc ¤Ç¤ÎÃí°Õ
443 .\"O The GNU C library allows the following extensions for the string specified in
444 .\"O .IR mode :
445 GNU C ¥é¥¤¥Ö¥é¥ê¤Ç¤Ï¡¢
446 .I mode
447 ¤Ë»ØÄê¤Ç¤­¤ëʸ»úÎó¤È¤·¤Æ¡¢°Ê²¼¤Î³ÈÄ¥¤¬¹Ô¤ï¤ì¤Æ¤¤¤ë:
448 .TP
449 .\"O .BR c " (since glibc 2.3.3)"
450 .BR c " (glibc 2.3.3 °Ê¹ß)"
451 .\"O Do not make the open operation,
452 .\"O or subsequent read and write operations,
453 .\"O thread cancellation points.
454 open Áàºî¡¢¤½¤ì¤Ë³¤¯ read/write Áàºî¤Î¡¢
455 ¥¹¥ì¥Ã¥É¤Î¼è¤ê¾Ã¤·¥Ý¥¤¥ó¥È (cancellation points)
456 ¤òºîÀ®¤·¤Ê¤¤¡£
457 .TP
458 .\"O .BR e " (since glibc 2.7)"
459 .BR e " (glibc 2.7 °Ê¹ß)"
460 .\"O Open the file with the
461 .\"O .B O_CLOEXEC
462 .\"O flag.
463 .\"O See
464 .\"O .BR open (2)
465 .\"O for more information.
466 .B O_CLOEXEC
467 ¥Õ¥é¥°¤òÍ­¸ú¤Ë¤·¤Æ¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤¹¤ë¡£
468 ¾ÜºÙ¤Ï
469 .BR open (2)
470 ¤ò»²¾È¡£
471 .TP
472 .\"O .BR m " (since glibc 2.3)"
473 .BR m " (glibc 2.3 °Ê¹ß)"
474 .\"O Attempt to access the file using
475 .\"O .BR mmap (2),
476 .\"O rather than I/O system calls
477 .\"O .RB ( read (2),
478 .\"O .BR write (2)).
479 .\"O Currently,
480 .\"O .\" As at glibc 2.4:
481 .\"O use of
482 .\"O .BR mmap (2)
483 .\"O is only attempted for a file opened for reading.
484 I/O ¥·¥¹¥Æ¥à¥³¡¼¥ë
485 .RB ( read (2),
486 .BR write (2))
487 ¤Ç¤Ï¤Ê¤¯¡¢
488 .BR mmap (2)
489 ¤ò»È¤Ã¤Æ¥Õ¥¡¥¤¥ë¤Ë¥¢¥¯¥»¥¹¤·¤è¤¦¤È¤¹¤ë¡£
490 .\" glibc 2.4 ¤Ç¤Ï
491 .BR mmap (2)
492 ¤ò»È¤ª¤¦¤È¤¹¤ë¤Î¤Ï¡¢Æɤ߽Ф·ÍѤ˥ª¡¼¥×¥ó¤¹¤ë¥Õ¥¡¥¤¥ë¤Ë¤Ä¤¤¤Æ¤À¤±¤Ç¤¢¤ë¡£
493 .TP
494 .B x
495 .\"O Open the file exclusively
496 .\"O (like the
497 .\"O .B O_EXCL
498 .\"O flag of
499 .\"O .BR open (2)).
500 .\"O If the file already exists,
501 .\"O .BR fopen ()
502 .\"O fails, and sets
503 .\"O .I errno
504 .\"O to
505 .\"O .BR EEXIST .
506 ¥Õ¥¡¥¤¥ë¤òÇÓ¾Ū¤Ë¥ª¡¼¥×¥ó¤¹¤ë
507 .RB ( open (2)
508 ¤Î
509 .B O_EXCL
510 ¥Õ¥é¥°¤ÈƱÍÍ)¡£
511 ¥Õ¥¡¥¤¥ë¤¬¤¹¤Ç¤Ë¸ºß¤¹¤ë¾ì¹ç¡¢
512 .BR fopen ()
513 ¤Ï¼ºÇÔ¤·¡¢
514 .I errno
515 ¤Ë
516 .B EEXIST
517 ¤¬¥»¥Ã¥È¤µ¤ì¤ë¡£
518 .\"O This flag is ignored for
519 .\"O .BR fdopen ().
520 ¤³¤Î¥Õ¥é¥°¤Ï
521 .BR fdopen ()
522 ¤Ç¤Ï̵»ë¤µ¤ì¤ë¡£
523 .\" FIXME document /,ccs= charset/
524 .\"O .SH "SEE ALSO"
525 .SH ´ØÏ¢¹àÌÜ
526 .BR open (2),
527 .BR fclose (3),
528 .BR fileno (3),
529 .BR fmemopen (3),
530 .BR fopencookie (3)