1 .\" Copyright (c) 1990, 1991 The Regents of the University of California.
2 .\" All rights reserved.
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.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
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.
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
36 .\" @(#)fopen.3 6.8 (Berkeley) 6/29/91
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
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>
54 .\"WORD: file descriptor ファイル記述子
55 .\"WORD: file position indicator ファイル位置指示子
56 .\"WORD: indicator 指示子
57 .\"WORD: global variable 大域変数
58 .\"WORD: cancellation points 取り消しポイント
60 .TH FOPEN 3 2009-02-23 "GNU" "Linux Programmer's Manual"
62 .\"O fopen, fdopen, freopen \- stream open functions
63 fopen, fdopen, freopen \- ストリームを開く関数
68 .BI "FILE *fopen(const char *" path ", const char *" mode );
70 .BI "FILE *fdopen(int " fd ", const char *" mode );
72 .BI "FILE *freopen(const char *" path ", const char *" mode ", FILE *" stream );
76 .\"O Feature Test Macro Requirements for glibc (see
77 .\"O .BR feature_test_macros (7)):
79 .RB ( feature_test_macros (7)
84 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _POSIX_SOURCE
88 .\"O function opens the file whose name is the string pointed to by
90 .\"O and associates a stream with it.
94 で指定された名前のファイルを開き、ストリームと結びつける。
98 .\"O points to a string beginning with one of the following sequences
99 .\"O (Additional characters may follow these sequences.):
102 は、以下に続く文字のひとつから始まる文字列へのポインタである
103 (追加の文字がこの文字の後に続くこともある):
106 .\"O Open text file for reading.
107 .\"O The stream is positioned at the beginning of the file.
112 .\"O Open for reading and writing.
113 .\"O The stream is positioned at the beginning of the file.
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.
121 ファイルが既に存在する場合には長さゼロに切り詰める。
122 ファイルがなかった場合には新たに作成する。
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.
130 ファイルが存在していない場合には新たに作成する。
131 存在している場合には長さゼロに切り詰められる。
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 ファイルが存在していない場合には新たに作成する。
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 書き込みは常にファイルの最後に追加される。
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.
161 文字列には文字 \(aqb\(aq を追加指定することができ、
164 上記のうち 2 文字のモードの場合には 2 つの文字の間に指定することもできる。
165 これは C89 との互換性のためだけに用意された
166 ものであり、関数の実行に対してはいかなる影響も持たない。
167 すなわち、Linux を含む全ての POSIX 準拠システムでは、
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
173 (その他のシステムではテキストファイルとバイナリファイルを別々に扱うものもあるので、
175 そのプログラムが非 UNIX 環境へ移植されると予測するなら、
176 \(aqb\(aqを付けておくのは良い考えである)
178 .\"O See NOTES below for details of glibc extensions for
181 の glibc による拡張の詳細については下記の「注意」を参照。
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
188 .BR S_IRUSR " | " S_IWUSR " | " S_IRGRP " | " S_IWGRP " | " S_IROTH " | " S_IWOTH
190 そのプロセスの umask 値によって修正したモードを持つ
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
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 読み出し/書き込みストリームに対しては任意の順序で読み書きを行うことができる。
210 (入力操作がファイルの末尾に到達した場合を除いて)
211 出力と入力の間にはファイルの位置決め関数を
212 挟まなければならないことになっていることに注意されたい
213 (この条件を満足しない場合には、読み込み操作は、
214 最後に書き込まれたものでなく、以前に書き込まれた
216 したがって、このようなストリームでの読み書き操作の間には
221 (Linux では本当に必要となることもときどきある)。
222 この操作は見かけ上何もしない操作 (no-op) でも良い
223 (例えば \fIfseek(..., 0L, SEEK_CUR)\fP を
224 その副次的効果である同期のためだけに呼べば良い)。
226 .\"O Opening a file in append mode (\fBa\fP as the first character of
228 .\"O causes all subsequent write operations to this stream to occur
229 .\"O at end-of-file, as if preceded by an
232 .\"O fseek(stream,0,SEEK_END);
238 の最初の文字を \fBa\fP にする) で開くと、
239 このストリームに対する書き込み操作は (先に
242 fseek(stream,0,SEEK_END);
245 の呼び出しを実行したかのように) ファイル末尾に対して行われる。
249 .\"O function associates a stream with the existing file descriptor,
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.
261 ("r", "r+", "w", "w+", "a", "a+" のいずれか) は
262 ファイル記述子のモードと互換のものでなければならない。
263 .\"O The file position indicator of the new stream is set to that
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.
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
277 .\"O The result of applying
279 .\"O to a shared memory object is undefined.
282 で作成されたストリームが閉じられたときにファイル記述子も
290 .\"O function opens the file whose name is the string pointed to by
292 .\"O and associates the stream pointed to by
295 .\"O The original stream (if it exists) is closed.
298 .\"O argument is used just as in the
301 .\"O The primary use of the
303 .\"O function is to change the file associated with a standard text stream
304 .\"O .RI ( stderr ", " stdin ", or " stdout ).
310 で指定されたストリームに、そのファイルを結びつける。
311 もとのストリームは (もし存在する場合には) 閉じられる。
318 .RI ( stderr ", " stdin ", " stdout )
319 と対応付けられているファイルを変更することである。
321 .\"O Upon successful completion
329 .\"O Otherwise, NULL is returned and
331 .\"O is set to indicate the error.
364 .\"O functions may also fail and set
366 .\"O for any of the errors specified for the routine
373 ルーチンで規定されているエラーでも失敗することがあり、
380 .\"O function may also fail and set
382 .\"O for any of the errors specified for the routine
387 ルーチンで規定されているエラーでも失敗することがあり、
394 .\"O function may also fail and set
396 .\"O for any of the errors specified for the routine
401 ルーチンで規定されているエラーでも失敗することがあり、
408 .\"O function may also fail and set
410 .\"O for any of the errors specified for the routines
420 各ルーチンで規定されているエラーでも失敗することがあり、
429 .\"O functions conform to C89.
432 .\"O function conforms to POSIX.1-1990.
438 関数は POSIX.1-1990 に準拠している。
443 .\"O The GNU C library allows the following extensions for the string specified in
447 に指定できる文字列として、以下の拡張が行われている:
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)
458 .\"O .BR e " (since glibc 2.7)"
459 .BR e " (glibc 2.7 以降)"
460 .\"O Open the file with the
465 .\"O for more information.
467 フラグを有効にしてファイルをオープンする。
472 .\"O .BR m " (since glibc 2.3)"
473 .BR m " (glibc 2.3 以降)"
474 .\"O Attempt to access the file using
476 .\"O rather than I/O system calls
480 .\"O .\" As at glibc 2.4:
483 .\"O is only attempted for a file opened for reading.
492 を使おうとするのは、読み出し用にオープンするファイルについてだけである。
495 .\"O Open the file exclusively
500 .\"O If the file already exists,
518 .\"O This flag is ignored for
523 .\" FIXME document /,ccs= charset/