version 1, including all changes.
.
| Rev |
Author |
# |
Line |
| 1 |
perry |
1 |
FOPEN |
| |
|
2 |
!!!FOPEN |
| |
|
3 |
NAME |
| |
|
4 |
SYNOPSIS |
| |
|
5 |
DESCRIPTION |
| |
|
6 |
RETURN VALUE |
| |
|
7 |
ERRORS |
| |
|
8 |
CONFORMING TO |
| |
|
9 |
SEE ALSO |
| |
|
10 |
---- |
| |
|
11 |
!!NAME |
| |
|
12 |
|
| |
|
13 |
|
| |
|
14 |
fopen, fdopen, freopen - stream open functions |
| |
|
15 |
!!SYNOPSIS |
| |
|
16 |
|
| |
|
17 |
|
| |
|
18 |
__#include __ |
| |
|
19 |
|
| |
|
20 |
|
| |
|
21 |
__FILE *fopen (const char *__''path''__, const char |
| |
|
22 |
*__''mode''__); |
| |
|
23 |
FILE *fdopen (int__ ''fildes''__, const char |
| |
|
24 |
*__''mode''__); |
| |
|
25 |
FILE *freopen (const char *__''path''__, const char |
| |
|
26 |
*__''mode''__, FILE |
| |
|
27 |
*__''stream''__);__ |
| |
|
28 |
!!DESCRIPTION |
| |
|
29 |
|
| |
|
30 |
|
| |
|
31 |
The __fopen__ function opens the file whose name is the |
| |
|
32 |
string pointed to by ''path'' and associates a stream |
| |
|
33 |
with it. |
| |
|
34 |
|
| |
|
35 |
|
| |
|
36 |
The argument ''mode'' points to a string beginning with |
| |
|
37 |
one of the following sequences (Additional characters may |
| |
|
38 |
follow these sequences.): |
| |
|
39 |
|
| |
|
40 |
|
| |
|
41 |
__r__ |
| |
|
42 |
|
| |
|
43 |
|
| |
|
44 |
Open text file for reading. The stream is positioned at the |
| |
|
45 |
beginning of the file. |
| |
|
46 |
|
| |
|
47 |
|
| |
|
48 |
__r+__ |
| |
|
49 |
|
| |
|
50 |
|
| |
|
51 |
Open for reading and writing. The stream is positioned at |
| |
|
52 |
the beginning of the file. |
| |
|
53 |
|
| |
|
54 |
|
| |
|
55 |
__w__ |
| |
|
56 |
|
| |
|
57 |
|
| |
|
58 |
Truncate file to zero length or create text file for |
| |
|
59 |
writing. The stream is positioned at the beginning of the |
| |
|
60 |
file. |
| |
|
61 |
|
| |
|
62 |
|
| |
|
63 |
__w+__ |
| |
|
64 |
|
| |
|
65 |
|
| |
|
66 |
Open for reading and writing. The file is created if it does |
| |
|
67 |
not exist, otherwise it is truncated. The stream is |
| |
|
68 |
positioned at the beginning of the file. |
| |
|
69 |
|
| |
|
70 |
|
| |
|
71 |
__a__ |
| |
|
72 |
|
| |
|
73 |
|
| |
|
74 |
Open for writing. The file is created if it does not exist. |
| |
|
75 |
The stream is positioned at the end of the |
| |
|
76 |
file. |
| |
|
77 |
|
| |
|
78 |
|
| |
|
79 |
__a+__ |
| |
|
80 |
|
| |
|
81 |
|
| |
|
82 |
Open for reading and writing. The file is created if it does |
| |
|
83 |
not exist. The stream is positioned at the end of the |
| |
|
84 |
file. |
| |
|
85 |
|
| |
|
86 |
|
| |
|
87 |
The ''mode'' string can also include the letter ``b'' |
| |
|
88 |
either as a last character or as a character between the |
| |
|
89 |
characters in any of the two-character strings described |
| |
|
90 |
above. This is strictly for compatibility with ANSI |
| |
|
91 |
X3.159-1989 (``ANSI C'') and has no effect; the ``b'' is |
| |
|
92 |
ignored on all POSIX conforming systems, including Linux. |
| |
|
93 |
(Other systems may treat text files and binary files |
| |
|
94 |
differently, and adding the ``b'' may be a good idea if you |
| |
|
95 |
do I/O to a binary file and expect that your program may be |
| |
|
96 |
ported to non-Unix environments.) |
| |
|
97 |
|
| |
|
98 |
|
| |
|
99 |
Any created files will have mode |
| |
|
100 |
__S_IRUSR__|__S_IWUSR__|__S_IRGRP__|__S_IWGRP__|__S_IROTH__|__S_IWOTH__ |
| |
|
101 |
(0666), as modified by the process' umask value (see |
| |
|
102 |
umask(2). |
| |
|
103 |
|
| |
|
104 |
|
| |
|
105 |
Reads and writes may be intermixed on read/write streams in |
| |
|
106 |
any order. Note that ANSI C requires that a file positioning |
| |
|
107 |
function intervene between output and input, unless an input |
| |
|
108 |
operation encounters end-of-file. (If this condition is not |
| |
|
109 |
met, then a read is allowed to return the result of writes |
| |
|
110 |
other than the most recent.) Therefore it is good practice |
| |
|
111 |
(and indeed sometimes necessary under Linux) to put an |
| |
|
112 |
__fseek__ or __fgetpos__ operation between write and |
| |
|
113 |
read operations on such a stream. This operation may be an |
| |
|
114 |
apparent no-op (as in ''fseek(..., 0L, SEEK_CUR)'' called |
| |
|
115 |
for its synchronizing side effect. |
| |
|
116 |
|
| |
|
117 |
|
| |
|
118 |
The __fdopen__ function associates a stream with the |
| |
|
119 |
existing file descriptor, ''fildes''. The ''mode'' of |
| |
|
120 |
the stream (one of the values |
| |
|
121 |
''fildes'', and the error and |
| |
|
122 |
end-of-file indicators are cleared. Modes |
| |
|
123 |
''fdopen__ is closed. The result of applying |
| |
|
124 |
__fdopen__ to a shared memory object is |
| |
|
125 |
undefined. |
| |
|
126 |
|
| |
|
127 |
|
| |
|
128 |
The __freopen__ function opens the file whose name is the |
| |
|
129 |
string pointed to by ''path'' and associates the stream |
| |
|
130 |
pointed to by ''stream'' with it. The original stream (if |
| |
|
131 |
it exists) is closed. The ''mode'' argument is used just |
| |
|
132 |
as in the __fopen__ function. The primary use of the |
| |
|
133 |
__freopen__ function is to change the file associated |
| |
|
134 |
with a standard text stream (''stderr'', ''stdin'', or |
| |
|
135 |
''stdout''). |
| |
|
136 |
!!RETURN VALUE |
| |
|
137 |
|
| |
|
138 |
|
| |
|
139 |
Upon successful completion __fopen__, __fdopen__ and |
| |
|
140 |
__freopen__ return a __FILE__ pointer. Otherwise, |
| |
|
141 |
__NULL__ is returned and the global variable ''errno'' |
| |
|
142 |
is set to indicate the error. |
| |
|
143 |
!!ERRORS |
| |
|
144 |
|
| |
|
145 |
|
| |
|
146 |
__EINVAL__ |
| |
|
147 |
|
| |
|
148 |
|
| |
|
149 |
The ''mode'' provided to __fopen__, __fdopen__, or |
| |
|
150 |
__freopen__ was invalid. |
| |
|
151 |
|
| |
|
152 |
|
| |
|
153 |
The __fopen__, __fdopen__ and __freopen__ functions |
| |
|
154 |
may also fail and set ''errno'' for any of the errors |
| |
|
155 |
specified for the routine malloc(3). |
| |
|
156 |
|
| |
|
157 |
|
| |
|
158 |
The __fopen__ function may also fail and set ''errno'' |
| |
|
159 |
for any of the errors specified for the routine |
| |
|
160 |
open(2). |
| |
|
161 |
|
| |
|
162 |
|
| |
|
163 |
The __fdopen__ function may also fail and set |
| |
|
164 |
''errno'' for any of the errors specified for the routine |
| |
|
165 |
fcntl(2). |
| |
|
166 |
|
| |
|
167 |
|
| |
|
168 |
The __freopen__ function may also fail and set |
| |
|
169 |
''errno'' for any of the errors specified for the |
| |
|
170 |
routines open(2), fclose(3) and |
| |
|
171 |
fflush(3). |
| |
|
172 |
!!CONFORMING TO |
| |
|
173 |
|
| |
|
174 |
|
| |
|
175 |
The __fopen__ and __freopen__ functions conform to |
| |
|
176 |
ANSI X3.159-1989 (``ANSI C''). The __fdopen__ function |
| |
|
177 |
conforms to IEEE Std1003.1-1988 (``POSIX.1''). |
| |
|
178 |
!!SEE ALSO |
| |
|
179 |
|
| |
|
180 |
|
| |
|
181 |
open(2), fclose(3), |
| |
|
182 |
fileno(3) |
| |
|
183 |
---- |