340 lines
14 KiB
HTML
340 lines
14 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of STDIO</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>STDIO</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-11-26<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
stdio - standard input/output library functions
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>></B>
|
|
|
|
<P>
|
|
|
|
<B>FILE *</B><I>stdin</I><B>;</B>
|
|
|
|
<BR>
|
|
|
|
<B>FILE *</B><I>stdout</I><B>;</B>
|
|
|
|
<BR>
|
|
|
|
<B>FILE *</B><I>stderr</I><B>;</B>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The standard I/O library provides a simple and efficient buffered stream
|
|
I/O interface.
|
|
Input and output is mapped into logical data streams and the
|
|
physical I/O characteristics are concealed.
|
|
The functions and macros are
|
|
listed below; more information is available from the individual man pages.
|
|
<P>
|
|
|
|
A stream is associated with an external file (which may be a physical
|
|
device) by
|
|
<I>opening</I>
|
|
|
|
a file, which may involve creating a new file.
|
|
Creating an existing file
|
|
causes its former contents to be discarded.
|
|
If a file can support positioning requests (such as a disk file,
|
|
as opposed to a terminal), then a
|
|
<I>file position indicator</I>
|
|
|
|
associated with the stream is positioned at the start of the file (byte
|
|
zero), unless the file is opened with append mode.
|
|
If append mode is used,
|
|
it is unspecified whether the position indicator will be placed at the
|
|
start or the end of the file.
|
|
The position indicator is maintained by
|
|
subsequent reads, writes and positioning requests.
|
|
All input occurs as if the characters were read by successive calls to the
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fgetc">fgetc</A></B>(3)
|
|
|
|
function; all output takes place as if all characters were written by
|
|
successive calls to the
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fputc">fputc</A></B>(3)
|
|
|
|
function.
|
|
<P>
|
|
|
|
A file is disassociated from a stream by
|
|
<I>closing</I>
|
|
|
|
the file.
|
|
Output streams are flushed (any unwritten buffer contents are
|
|
transferred to the host environment) before the stream is disassociated from
|
|
the file.
|
|
The value of a pointer to a
|
|
<I>FILE</I>
|
|
|
|
object is indeterminate after a file is closed (garbage).
|
|
<P>
|
|
|
|
A file may be subsequently reopened, by the same or another program
|
|
execution, and its contents reclaimed or modified (if it can be
|
|
repositioned at the start).
|
|
If the main function returns to its original
|
|
caller, or the
|
|
<B><A HREF="/cgi-bin/man/man2html?3+exit">exit</A></B>(3)
|
|
|
|
function is called, all open files are closed (hence all output streams are
|
|
flushed) before program termination.
|
|
Other methods of program termination,
|
|
such as
|
|
<B><A HREF="/cgi-bin/man/man2html?3+abort">abort</A></B>(3)
|
|
|
|
do not bother about closing files properly.
|
|
<P>
|
|
|
|
At program startup, three text streams are predefined and need not be
|
|
opened explicitly:
|
|
<I>standard input</I>
|
|
|
|
(for reading conventional input),
|
|
<I>standard output</I>
|
|
|
|
(for writing conventional output), and
|
|
<I>standard error</I>
|
|
|
|
(for writing diagnostic output).
|
|
These streams are abbreviated
|
|
<I>stdin</I>,
|
|
|
|
<I>stdout</I>,
|
|
|
|
and
|
|
<I>stderr</I>.
|
|
|
|
When opened, the standard error stream is not fully buffered; the standard
|
|
input and output streams are fully buffered if and only if the streams do
|
|
not refer to an interactive device.
|
|
<P>
|
|
|
|
Output streams that refer to terminal devices are always line buffered by
|
|
default; pending output to such streams is written automatically whenever
|
|
an input stream that refers to a terminal device is read.
|
|
In cases where a
|
|
large amount of computation is done after printing part of a line on an
|
|
output terminal, it is necessary to
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fflush">fflush</A></B>(3)
|
|
|
|
the standard output before going off and computing so that the output will
|
|
appear.
|
|
<P>
|
|
|
|
The
|
|
<I>stdio</I>
|
|
|
|
library is a part of the library
|
|
<B>libc</B>
|
|
|
|
and routines are automatically loaded as needed by
|
|
<B><A HREF="/cgi-bin/man/man2html?1+cc">cc</A></B>(1).
|
|
|
|
The
|
|
SYNOPSIS
|
|
sections of the following manual pages indicate which include files are to
|
|
be used, what the compiler declaration for the function looks like and
|
|
which external variables are of interest.
|
|
<P>
|
|
|
|
The following are defined as macros; these names may not be reused without
|
|
first removing their current definitions with
|
|
<B>#undef</B>:
|
|
|
|
<B>BUFSIZ</B>,
|
|
|
|
<B>EOF</B>,
|
|
|
|
<B>FILENAME_MAX</B>,
|
|
|
|
<B>FOPEN_MAX</B>,
|
|
|
|
<B>L_cuserid</B>,
|
|
|
|
<B>L_ctermid</B>,
|
|
|
|
<B>L_tmpnam</B>,
|
|
|
|
<B>NULL</B>,
|
|
|
|
<B>SEEK_END</B>,
|
|
|
|
<B>SEEK_SET</B>,
|
|
|
|
<B>SEEK_CUR</B>,
|
|
|
|
<B>TMP_MAX</B>,
|
|
|
|
<B>clearerr</B>,
|
|
|
|
<B>feof</B>,
|
|
|
|
<B>ferror</B>,
|
|
|
|
<B>fileno</B>,
|
|
|
|
|
|
|
|
<B>getc</B>,
|
|
|
|
<B>getchar</B>,
|
|
|
|
<B>putc</B>,
|
|
|
|
<B>putchar</B>,
|
|
|
|
<B>stderr</B>,
|
|
|
|
<B>stdin</B>,
|
|
|
|
<B>stdout</B>.
|
|
|
|
Function versions of the macro functions
|
|
<B>feof</B>,
|
|
|
|
<B>ferror</B>,
|
|
|
|
<B>clearerr</B>,
|
|
|
|
<B>fileno</B>,
|
|
|
|
<B>getc</B>,
|
|
|
|
<B>getchar</B>,
|
|
|
|
<B>putc</B>,
|
|
|
|
and
|
|
<B>putchar</B>
|
|
|
|
exist and will be used if the macros definitions are explicitly removed.
|
|
<A NAME="lbAE"> </A>
|
|
<H3>List of functions</H3>
|
|
|
|
<TABLE>
|
|
<TR VALIGN=top><TD><B>Function</B></TD><TD><B>Description</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD COLSPAN=2><HR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+clearerr">clearerr</A></B>(3)</TD><TD>check and reset stream status<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+fclose">fclose</A></B>(3)</TD><TD>close a stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+fdopen">fdopen</A></B>(3)</TD><TD>stream open functions<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+feof">feof</A></B>(3)</TD><TD>check and reset stream status<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+ferror">ferror</A></B>(3)</TD><TD>check and reset stream status<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+fflush">fflush</A></B>(3)</TD><TD>flush a stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+fgetc">fgetc</A></B>(3)</TD><TD>get next character or word from input stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+fgetpos">fgetpos</A></B>(3)</TD><TD>reposition a stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+fgets">fgets</A></B>(3)</TD><TD>get a line from a stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+fileno">fileno</A></B>(3)</TD><TD>return the integer descriptor of the argument stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+fopen">fopen</A></B>(3)</TD><TD>stream open functions<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+fprintf">fprintf</A></B>(3)</TD><TD>formatted output conversion<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+fpurge">fpurge</A></B>(3)</TD><TD>flush a stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+fputc">fputc</A></B>(3)</TD><TD>output a character or word to a stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+fputs">fputs</A></B>(3)</TD><TD>output a line to a stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+fread">fread</A></B>(3)</TD><TD>binary stream input/output<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+freopen">freopen</A></B>(3)</TD><TD>stream open functions<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+fscanf">fscanf</A></B>(3)</TD><TD>input format conversion<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+fseek">fseek</A></B>(3)</TD><TD>reposition a stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+fsetpos">fsetpos</A></B>(3)</TD><TD>reposition a stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+ftell">ftell</A></B>(3)</TD><TD>reposition a stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+fwrite">fwrite</A></B>(3)</TD><TD>binary stream input/output<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+getc">getc</A></B>(3)</TD><TD>get next character or word from input stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+getchar">getchar</A></B>(3)</TD><TD>get next character or word from input stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+gets">gets</A></B>(3)</TD><TD>get a line from a stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+getw">getw</A></B>(3)</TD><TD>get next character or word from input stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+mktemp">mktemp</A></B>(3)</TD><TD>make temporary filename (unique)<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+perror">perror</A></B>(3)</TD><TD>system error messages<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+printf">printf</A></B>(3)</TD><TD>formatted output conversion<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+putc">putc</A></B>(3)</TD><TD>output a character or word to a stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+putchar">putchar</A></B>(3)</TD><TD>output a character or word to a stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+puts">puts</A></B>(3)</TD><TD>output a line to a stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+putw">putw</A></B>(3)</TD><TD>output a character or word to a stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+remove">remove</A></B>(3)</TD><TD>remove directory entry<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+rewind">rewind</A></B>(3)</TD><TD>reposition a stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+scanf">scanf</A></B>(3)</TD><TD>input format conversion<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+setbuf">setbuf</A></B>(3)</TD><TD>stream buffering operations<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+setbuffer">setbuffer</A></B>(3)</TD><TD>stream buffering operations<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+setlinebuf">setlinebuf</A></B>(3)</TD><TD>stream buffering operations<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+setvbuf">setvbuf</A></B>(3)</TD><TD>stream buffering operations<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+sprintf">sprintf</A></B>(3)</TD><TD>formatted output conversion<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+sscanf">sscanf</A></B>(3)</TD><TD>input format conversion<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+strerror">strerror</A></B>(3)</TD><TD>system error messages<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+sys_errlist">sys_errlist</A></B>(3)</TD><TD>system error messages<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+sys_nerr">sys_nerr</A></B>(3)</TD><TD>system error messages<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+tempnam">tempnam</A></B>(3)</TD><TD>temporary file routines<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+tmpfile">tmpfile</A></B>(3)</TD><TD>temporary file routines<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+tmpnam">tmpnam</A></B>(3)</TD><TD>temporary file routines<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+ungetc">ungetc</A></B>(3)</TD><TD>un-get character from input stream<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+vfprintf">vfprintf</A></B>(3)</TD><TD>formatted output conversion<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+vfscanf">vfscanf</A></B>(3)</TD><TD>input format conversion<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+vprintf">vprintf</A></B>(3)</TD><TD>formatted output conversion<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+vscanf">vscanf</A></B>(3)</TD><TD>input format conversion<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+vsprintf">vsprintf</A></B>(3)</TD><TD>formatted output conversion<BR></TD></TR>
|
|
<TR VALIGN=top><TD><B><A HREF="/cgi-bin/man/man2html?3+vsscanf">vsscanf</A></B>(3)</TD><TD>input format conversion<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
The
|
|
<I>stdio</I>
|
|
|
|
library conforms to C89.
|
|
<A NAME="lbAG"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+close">close</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+open">open</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+write">write</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+stdout">stdout</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+unlocked_stdio">unlocked_stdio</A></B>(3)
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DL>
|
|
<DT id="4"><A HREF="#lbAE">List of functions</A><DD>
|
|
</DL>
|
|
<DT id="5"><A HREF="#lbAF">CONFORMING TO</A><DD>
|
|
<DT id="6"><A HREF="#lbAG">SEE ALSO</A><DD>
|
|
<DT id="7"><A HREF="#lbAH">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:57 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|