-
Notifications
You must be signed in to change notification settings - Fork 2
/
fopen.3
99 lines (98 loc) · 2.29 KB
/
fopen.3
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
.\" Copyright (c) 1980 Regents of the University of California.
.\" All rights reserved. The Berkeley software License Agreement
.\" specifies the terms and conditions for redistribution.
.\"
.\" @(#)fopen.3s 6.3 (Berkeley) 5/27/86
.\"
.TH FOPEN 3 "May 27, 1986"
.UC 4
.SH NAME
fopen, freopen, fdopen \- open a stream
.SH SYNOPSIS
.nf
.ft B
#include <stdio.h>
FILE *fopen(const char *\fIfilename\fP, const char *\fItype\fP)
FILE *freopen(const char *\fIfilename\fP, const char *\fItype\fP, FILE *\fIstream\fP)
FILE *fdopen(int \fIfildes\fP, const char *\fItype\fP)
.ft R
.fi
.SH DESCRIPTION
.B Fopen
opens the file named by
.I filename
and associates a stream with it.
.B Fopen
returns a pointer to be used to identify the stream in subsequent operations.
.PP
.I Type
is a character string having one of the following values:
.TP 5
"r"
open for reading
.ns
.TP 5
"w"
create for writing
.ns
.TP 5
"a"
append: open for writing at end of file, or create for writing
.PP
In addition, each
.I type
may be followed by a "+" to have the file opened for reading and writing.
"r+" positions the stream at the beginning of the file, "w+" creates
or truncates it, and "a+" positions it at the end. Both reads and writes
may be used on read/write streams, with the limitation that an
.BR fseek ,
.BR rewind ,
or reading an end-of-file must be used between a read and a write or vice-versa.
.PP
.B Freopen
substitutes the named file in place of the open
.IR stream .
It returns the original value of
.IR stream .
The original stream is closed.
.PP
.B Freopen
is typically used to attach the preopened constant names,
.B stdin, stdout, stderr,
to specified files.
.PP
.B Fdopen
associates a stream with a file descriptor obtained from
.BR open ,
.BR dup ,
.BR creat ,
or
.BR pipe (2).
The
.I type
of the stream must agree with the mode of the open file.
.SH "SEE ALSO"
.BR open (2),
.BR fclose (3).
.SH DIAGNOSTICS
.B Fopen
and
.B freopen
return the pointer
.SM
.B NULL
if
.I filename
cannot be accessed,
if too many files are already open,
or if other resources needed cannot be allocated.
.SH BUGS
.B Fdopen
is not portable to systems other than UNIX.
.PP
The read/write
.I types
do not exist on all systems. Those systems without
read/write modes will probably treat the
.I type
as if the "+" was not present. These are unreliable in any event.