1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
|
.\" Copyright (c) 1990, 1991 The Regents of the University of California.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Chris Torek and the American National Standards Committee X3,
.\" on Information Processing Systems.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)fopen.3 6.8 (Berkeley) 6/29/91
.\"
.\" Converted for Linux, Mon Nov 29 15:22:01 1993, faith@cs.unc.edu
.\" Modified, aeb, 960421, 970806
.\" Modified, joey, aeb, 2002-01-03
.\"
.\" Japanese Version Copyright (c) 1997 YOSHINO Takashi
.\" all rights reserved.
.\" Translated Thu Feb 13 12:10:38 JST 1997
.\" by YOSHINO Takashi <yoshino@civil.jcn.nihon-u.ac.jp>
.\" Updated & Modified Mon Mar 1 1999
.\" by NAKANO Takeo <nakano@apm.seikei.ac.jp>
.\" Updated 1999-12-08, Kentaro Shirakata <argrath@ub32.org>
.\" Updated 2001-12-13, Kentaro Shirakata <argrath@ub32.org>
.\" Updated 2002-03-23, Kentaro Shirakata <argrath@ub32.org>
.\" Updated 2005-10-15, Kentaro Shirakata <argrath@ub32.org>
.\" Updated 2006-07-20, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
.\"
.\"WORD: file descriptor ե뵭һ
.\"WORD: file position indicator եֻؼ
.\"WORD: indicator ؼ
.\"WORD: global variable ѿ
.\"
.TH FOPEN 3 2007-11-26 "GNU" "Linux Programmer's Manual"
.SH ̾
fopen, fdopen, freopen \- ȥؿ
.SH
.nf
.B #include <stdio.h>
.sp
.BI "FILE *fopen(const char *" path ", const char *" mode );
.BI "FILE *fdopen(int " fd ", const char *" mode );
.BI "FILE *freopen(const char *" path ", const char *" mode ", FILE *" stream );
.fi
.sp
.in -4n
glibc εǽޥ
.RB ( feature_test_macros (7)
):
.in
.sp
.BR fdopen ():
_POSIX_C_SOURCE || _XOPEN_SOURCE
.SH
.BR fopen ()
ؿϡ
.I path
ǻꤵ줿̾ΥեȥȷӤĤ롣
.PP
.I mode
ϡʲ³ʸΤҤȤĤϤޤʸؤΥݥǤ
(ɲäʸʸθ³Ȥ⤢):
.TP
.B r
ƥȥեɤ߽Ф˳
ȥϥեƬ˰֤롣
.TP
.B r+
ɤ߽Фӽߤ뤿˳
ȥϥեƬ˰֤롣
.TP
.B w
եߤΤ˳
ե뤬¸ߤˤĹڤͤ롣
ե뤬ʤäˤϿ˺롣
ȥϥեƬ˰֤롣
.TP
.B w+
ɤ߽ФӽߤΤ˳
ե뤬¸ߤƤʤˤϿ˺롣
¸ߤƤˤĹڤͤ롣
ȥϥեƬ˰֤롣
.TP
.B a
ɲ (եκǸ˽) Τ˳
ե뤬¸ߤƤʤˤϿ˺롣
ȥϥեκǸ˰֤롣
.TP
.B a+
ɤ߽Фɲ (եκǸ˽) Τ˳
ե뤬¸ߤƤʤˤϿ˺롣
ɤ߽Фνե֤ϥեƬǤ뤬
ߤϾ˥եκǸɲä롣
.PP
.I mode
ʸˤʸ 'b' ɲûꤹ뤳ȤǤ
.I mode
ʸκǸʸȤƻꤹ롣
嵭Τ 2 ʸΥ⡼ɤξˤ 2 Ĥʸδ֤˻ꤹ뤳ȤǤ롣
C89 ȤθߴΤѰդ줿
ΤǤꡢؿμ¹ԤФƤϤʤƶʤ
ʤLinux ޤƤ POSIX ƥǤϡ
'b' ̵뤵롣
(¾ΥƥǤϥƥȥեȥХʥե̡˰Τ⤢Τǡ
⤷ХʥեϤԤ
Υץब UNIX Ķذܿͽ¬ʤ顢
'b'դƤΤɤͤǤ)
.PP
٤Ƥ줿եϡ
.BR S_IRUSR " | " S_IWUSR " | " S_IRGRP " | " S_IWGRP " | " S_IROTH " | " S_IWOTH
(0666) Υ⡼ɤ
Υץ umask ͤˤäƽ⡼ɤ
.RB ( umask (2)
)
.PP
ɤ߽Ф/ߥȥФƤǤդνɤ߽ԤȤǤ롣
ANSI C Ǥϡ
(եã)
ϤϤδ֤ˤϥեΰַؿ
ޤʤФʤʤȤˤʤäƤ뤳Ȥդ줿
(ξʤˤϡɤ߹ϡ
Ǹ˽ޤ줿ΤǤʤ˽ޤ줿
֤ͤȤƤ)
äơΤ褦ʥȥǤɤ߽δ֤ˤ
.BR fseek (3)
ޤ
.BR fgetpos (3)
Ǥɤ
(Linux ǤɬפȤʤ뤳ȤȤɤ)
ϸ岿⤷ʤ (no-op) Ǥɤ
(㤨 \fIfseek(..., 0L, SEEK_CUR)\fP
Ṳ̄ǤƱΤ˸Ƥ٤ɤ)
.PP
եɲå⡼
.RI ( mode
κǽʸ \fBa\fP ˤ) dzȡ
ΥȥФ (
.nf
fseek(stream,0,SEEK_END);
.fi
θƤӽФ¹ԤΤ褦) եФƹԤ롣
.PP
.BR fdopen ()
ؿϡ¸Υե뵭һ
.I fd
˥ȥӤĤ롣
ȥ
.I mode
("r", "r+", "w", "w+", "a", "a+" Τ줫)
ե뵭һҤΥ⡼ɤȸߴΤΤǤʤФʤʤ
ȥΥեֻؼҤ
.I fd
°Ƥͤꤵ롣
error end-of-file γƻؼҤϥꥢ롣
"w" "w+" ⡼ɤǤΥեڤͤϹԤʤ
ե뵭һҤʣϹԤʤʤ
.BR fdopen ()
Ǻ줿ȥबĤ줿Ȥ˥ե뵭һҤ
Ĥ롣
ͭΥ֥Ȥ
.BR fdopen ()
ԤäȤη̤Ƥʤ
.PP
.BR freopen ()
ؿ
.I path
̾ꤵ줿ե
.I stream
ǻꤵ줿ȥˡΥեӤĤ롣
ȤΥȥ (⤷¸ߤˤ) Ĥ롣
.I mode
.BR fopen ()
ؿƱǻȤ롣
.BR freopen ()
ؿμӤϡɸƥȥȥ
.RI ( stderr ", " stdin ", " stdout )
бդƤեѹ뤳ȤǤ롣
.SH ֤
.BR fopen (),
.BR fdopen (),
.BR freopen ()
.I FILE
Υݥ֤
Ԥ NULL ֤졢ѿ
.I errno
顼ͤ˥åȤ롣
.SH 顼
.TP
.B EINVAL
.BR fopen (),
.BR fdopen (),
.BR freopen ()
Ϳ줿
.I mode
ŬڤǤ롣
.PP
.BR fopen (),
.BR fdopen (),
.BR freopen ()
ؿ
.BR malloc (3)
롼ǵꤵƤ륨顼Ǥ⼺Ԥ뤳Ȥꡢ
λбͤ
.I errno
åȤ롣
.PP
.BR fopen ()
ؿ
.BR open (2)
롼ǵꤵƤ륨顼Ǥ⼺Ԥ뤳Ȥꡢ
λбͤ
.I errno
åȤ롣
.PP
.BR fdopen ()
ؿ
.BR fcntl (2)
롼ǵꤵƤ륨顼Ǥ⼺Ԥ뤳Ȥꡢ
λбͤ
.I errno
åȤ롣
.PP
.BR freopen ()
ؿ
.BR open (2),
.BR fclose (3),
.BR fflush (3)
ƥ롼ǵꤵƤ륨顼Ǥ⼺Ԥ뤳Ȥꡢ
λбͤ
.I errno
åȤ롣
.SH
.BR fopen ()
ؿ
.BR freopen ()
ؿ C89˽Ƥ롣
.BR fdopen ()
ؿ POSIX.1-1990 ˽Ƥ롣
.SH
.SS glibc Ǥ
GNU C 饤֥Ǥϡ
.I mode
˻ǤʸȤơʲγĥԤƤ:
.TP
.BR c " (glibc 2.3.3 ʹ)"
open ³ read/write Ρ
åɤΥ졼ݥ (cancellation points)
ʤ
.TP
.BR e " (glibc 2.7 ʹ)"
.B O_CLOEXEC
ե饰ͭˤƥեץ롣
ܺ٤
.BR open (2)
ȡ
.TP
.BR m " (glibc 2.3 ʹ)"
I/O ƥॳ
.RB ( read (2),
.BR write (2))
ǤϤʤ
.BR mmap (2)
Ȥäƥե˥褦Ȥ롣
.\" glibc 2.4 Ǥ
.BR mmap (2)
ȤȤΤϡɤ߽ФѤ˥ץեˤĤƤǤ롣
.TP
.B x
ե¾Ū˥ץ
.RB ( open (2)
.B O_EXCL
ե饰Ʊ)
ե뤬Ǥ¸ߤ硢
.BR fopen ()
ϼԤ
.I errno
.B EEXIST
åȤ롣
Υե饰
.BR fdopen ()
Ǥ̵뤵롣
.\" FIXME document /,ccs= charset/
.SH Ϣ
.BR open (2),
.BR fclose (3),
.BR fileno (3)
|