Files
oldlinux-files/Minix/2.0.0/wwwman/man3/fopen.3.html
2024-02-19 00:21:39 -05:00

124 lines
3.4 KiB
HTML

<HTML>
<HEAD>
<TITLE>fopen(3)</TITLE>
</HEAD>
<BODY>
<H1>fopen(3)</H1>
<HR>
<PRE>
</PRE>
<H2>NAME</H2><PRE>
fopen, freopen, fdopen - open a stream
</PRE>
<H2>SYNOPSIS</H2><PRE>
<STRONG>#include</STRONG> <STRONG>&lt;stdio.h&gt;</STRONG>
<STRONG>FILE</STRONG> <STRONG>*fopen(const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>filename</EM><STRONG>,</STRONG> <STRONG>const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>type</EM><STRONG>)</STRONG>
<STRONG>FILE</STRONG> <STRONG>*freopen(const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>filename</EM><STRONG>,</STRONG> <STRONG>const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>type</EM><STRONG>,</STRONG> <STRONG>FILE</STRONG> <STRONG>*</STRONG><EM>stream</EM><STRONG>)</STRONG>
<STRONG>FILE</STRONG> <STRONG>*fdopen(int</STRONG> <EM>fildes</EM><STRONG>,</STRONG> <STRONG>const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>type</EM><STRONG>)</STRONG>
</PRE>
<H2>DESCRIPTION</H2><PRE>
<STRONG>Fopen</STRONG> opens the file named by <EM>filename</EM> and associates a stream with it.
<STRONG>Fopen</STRONG> returns a pointer to be used to identify the stream in subsequent
operations.
<EM>Type</EM> is a character string having one of the following values:
"r" open for reading
"w" create for writing
"a" append: open for writing at end of file, or create for writing
In addition, each <EM>type</EM> 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 <STRONG>fseek</STRONG>, <STRONG>rewind</STRONG>, or reading an end-of-file must be used
between a read and a write or vice-versa.
<STRONG>Freopen</STRONG> substitutes the named file in place of the open <EM>stream</EM>. It
returns the original value of <EM>stream</EM>. The original stream is closed.
<STRONG>Freopen</STRONG> is typically used to attach the preopened constant names, <STRONG>stdin,</STRONG>
<STRONG>stdout,</STRONG> <STRONG>stderr,</STRONG> to specified files.
<STRONG>Fdopen</STRONG> associates a stream with a file descriptor obtained from <STRONG>open</STRONG>,
<STRONG>dup</STRONG>, <STRONG>creat</STRONG>, or <STRONG><A HREF="../man2/pipe.2.html">pipe(2)</A></STRONG>. The <EM>type</EM> of the stream must agree with the mode
of the open file.
</PRE>
<H2>SEE ALSO</H2><PRE>
<STRONG><A HREF="../man2/open.2.html">open(2)</A></STRONG>, <STRONG><A HREF="../man3/fclose.3.html">fclose(3)</A></STRONG>.
</PRE>
<H2>DIAGNOSTICS</H2><PRE>
<STRONG>Fopen</STRONG> and <STRONG>freopen</STRONG> return the pointer <STRONG>NULL</STRONG> if <EM>filename</EM> cannot be accessed,
if too many files are already open, or if other resources needed cannot
be allocated.
</PRE>
<H2>BUGS</H2><PRE>
<STRONG>Fdopen</STRONG> is not portable to systems other than UNIX.
The read/write <EM>types</EM> do not exist on all systems. Those systems without
read/write modes will probably treat the <EM>type</EM> as if the "+" was not
present. These are unreliable in any event.
</PRE>
</BODY>
</HTML>