1 .\" Copyright (c) 1990, 1991, 1993
2 .\" The Regents of the University of California. 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 8.1 (Berkeley) 6/4/93
37 .\" $FreeBSD: src/lib/libc/stdio/fopen.3,v 1.18 2003/01/26 10:01:59 tjr Exp $
46 .Nd stream open functions
52 .Fn fopen "const char * restrict path" "const char * restrict mode"
54 .Fn fdopen "int fildes" "const char *mode"
56 .Fn freopen "const char *path" "const char *mode" "FILE *stream"
61 opens the file whose name is the string pointed to by
63 and associates a stream with it.
67 points to a string beginning with one of the following
68 sequences (Additional characters may follow these sequences.):
69 .Bl -tag -width indent
71 Open text file for reading.
72 The stream is positioned at the beginning of the file.
74 Open for reading and writing.
75 The stream is positioned at the beginning of the file.
77 Truncate file to zero length or create text file for writing.
78 The stream is positioned at the beginning of the file.
80 Open for reading and writing.
81 The file is created if it does not exist, otherwise it is truncated.
82 The stream is positioned at the beginning of the file.
85 The file is created if it does not exist.
86 The stream is positioned at the end of the file.
87 Subsequent writes to the file will always end up at the then current
88 end of file, irrespective of any intervening
92 Open for reading and writing.
93 The file is created if it does not exist.
94 The stream is positioned at the end of the file.
95 Subsequent writes to the file will always end up at the then current
96 end of file, irrespective of any intervening
103 string can also include the letter ``b'' either as a third character or
104 as a character between the characters in any of the two-character strings
106 This is strictly for compatibility with
108 and has no effect; the ``b'' is ignored.
110 Any created files will have mode
123 as modified by the process'
127 Reads and writes may be intermixed on read/write streams in any order,
128 and do not require an intermediate seek as in previous versions of
130 This is not portable to other systems, however;
133 a file positioning function intervene between output and input, unless
134 an input operation encounters end-of-file.
138 function associates a stream with the existing file descriptor,
141 of the stream must be compatible with the mode of the file descriptor.
142 When the stream is closed via
150 opens the file whose name is the string pointed to by
152 and associates the stream pointed to by
155 The original stream (if it exists) is closed.
158 argument is used just as in the
167 attempts to re-open the file associated with
170 The new mode must be compatible with the mode that the stream was originally
172 .Bl -bullet -offset indent
174 Streams originally opened with mode
176 can only be reopened with that same mode.
178 Streams originally opened with mode
180 can be reopened with the same mode, or mode
183 Streams originally opened with mode
185 can be reopened with the same mode, or mode
188 Streams originally opened with mode
193 can be reopened with any mode.
196 The primary use of the
199 is to change the file associated with a
201 .Dv ( stderr , stdin ,
205 Upon successful completion
215 is returned and the global variable
217 is set to indicate the error.
238 may also fail and set
240 for any of the errors specified for the routine
246 may also fail and set
248 for any of the errors specified for the routine
254 may also fail and set
256 for any of the errors specified for the routine
262 may also fail and set
264 for any of the errors specified for the routines