Change error return to -1 to match manual page. Shouldn't affect anything --
[unix-history] / usr / src / lib / libc / stdio / fopen.3
CommitLineData
251f9c2d
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
cf0272dc 5.\" @(#)fopen.3 6.1 (Berkeley) %G%
251f9c2d 6.\"
cf0272dc 7.TH FOPEN 3S ""
251f9c2d
KM
8.UC 4
9.SH NAME
10fopen, freopen, fdopen \- open a stream
11.SH SYNOPSIS
12.B #include <stdio.h>
13.PP
14.SM
15.B FILE
16.B *fopen(filename, type)
17.br
18.B char *filename, *type;
19.PP
20.SM
21.B FILE
22.B *freopen(filename, type, stream)
23.br
24.B char *filename, *type;
25.br
26.SM
27.B FILE
28.B *stream;
29.PP
30.SM
31.B FILE
32.B *fdopen(fildes, type)
33.br
34.B char *type;
35.SH DESCRIPTION
36.I Fopen
37opens the file named by
38.I filename
39and associates a stream with it.
40.I Fopen
e2703397 41returns a pointer to be used to identify the stream in subsequent operations.
251f9c2d
KM
42.PP
43.I Type
44is a character string having one of the following values:
45.TP 5
46"r"
47open for reading
48.ns
49.TP 5
50"w"
51create for writing
52.ns
53.TP 5
54"a"
e2703397 55append: open for writing at end of file, or create for writing
251f9c2d
KM
56.PP
57In addition, each
58.I type
e2703397
KM
59may be followed by a '+' to have the file opened for reading and writing.
60"r+" positions the stream at the beginning of the file, "w+" creates
251f9c2d
KM
61or truncates it, and "a+" positions it at the end. Both reads and writes
62may be used on read/write streams, with the limitation that an
63.I fseek, rewind,
e2703397 64or reading an end-of-file must be used between a read and a write or vice-versa.
251f9c2d
KM
65.PP
66.I Freopen
e2703397 67substitutes the named file in place of the open
251f9c2d
KM
68.IR stream .
69It returns the original value of
70.IR stream .
71The original stream is closed.
72.PP
73.I Freopen
e2703397 74is typically used to attach the preopened constant names,
251f9c2d
KM
75.B stdin, stdout, stderr,
76to specified files.
77.PP
78.I Fdopen
79associates a stream with a file descriptor obtained from
80.I open, dup, creat,
81or
82.IR pipe (2).
83The
84.I type
85of the stream must agree with the mode of the open file.
86.SH "SEE ALSO"
87open(2),
88fclose(3)
89.SH DIAGNOSTICS
90.I Fopen
91and
92.I freopen
93return the pointer
94.SM
95.B NULL
96if
97.I filename
98cannot be accessed.
99.SH BUGS
100.I Fdopen
101is not portable to systems other than UNIX.
102.PP
103The read/write
104.I types
105do not exist on all systems. Those systems without
106read/write modes will probably treat the
107.I type
e2703397 108as if the '+' was not present. These are unreliable in any event.