120 lines
4.3 KiB
HTML
120 lines
4.3 KiB
HTML
<HTML>
|
|
<HEAD>
|
|
<TITLE>setbuf(3)</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<H1>setbuf(3)</H1>
|
|
<HR>
|
|
<PRE>
|
|
|
|
</PRE>
|
|
<H2>NAME</H2><PRE>
|
|
setbuf, setvbuf - assign buffering to a stream
|
|
|
|
|
|
</PRE>
|
|
<H2>SYNOPSIS</H2><PRE>
|
|
<STRONG>#include</STRONG> <STRONG><stdio.h></STRONG>
|
|
|
|
<STRONG>int</STRONG> <STRONG>setbuf(FILE</STRONG> <STRONG>*</STRONG><EM>stream</EM><STRONG>,</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>buf</EM><STRONG>)</STRONG>
|
|
<STRONG>int</STRONG> <STRONG>setvbuf(FILE</STRONG> <STRONG>*</STRONG><EM>stream</EM><STRONG>,</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>buf</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>type</EM><STRONG>,</STRONG> <STRONG>size_t</STRONG> <EM>size</EM><STRONG>)</STRONG>
|
|
|
|
|
|
</PRE>
|
|
<H2>DESCRIPTION</H2><PRE>
|
|
The three types of buffering available are unbuffered, block buffered,
|
|
and line buffered. When an output stream is unbuffered, information
|
|
appears on the destination file or terminal as soon as written; when it
|
|
is block buffered many characters are saved up and written as a block;
|
|
when it is line buffered characters are saved up until a newline is
|
|
encountered or input is read from stdin. <STRONG>Fflush</STRONG> (see <STRONG><A HREF="../man3/fclose.3.html">fclose(3)</A></STRONG>) may be
|
|
used to force the block out early. Normally all files are block
|
|
buffered. A buffer is obtained from <STRONG><A HREF="../man3/malloc.3.html">malloc(3)</A></STRONG> upon the first <STRONG>getc</STRONG> or
|
|
<STRONG><A HREF="../man3/putc.3.html">putc(3)</A></STRONG> on the file. If the standard stream <STRONG>stdout</STRONG> refers to a terminal
|
|
it is line buffered. The standard stream <STRONG>stderr</STRONG> is always unbuffered.
|
|
|
|
<STRONG>Setbuf</STRONG> is used after a stream has been opened but before it is read or
|
|
written. The character array <EM>buf</EM> is used instead of an automatically
|
|
allocated buffer. If <EM>buf</EM> is the constant pointer <STRONG>NULL</STRONG>, input/output will
|
|
be completely unbuffered. A manifest constant <STRONG>BUFSIZ</STRONG> tells how big an
|
|
array is needed:
|
|
|
|
<STRONG>char</STRONG> buf[BUFSIZ];
|
|
|
|
<STRONG>Setvbuf</STRONG>, an alternate form of <STRONG>setbuf</STRONG>, is used after a stream has been
|
|
opened but before it is read or written. It has three uses, depending on
|
|
the value of the <EM>type</EM> argument:
|
|
|
|
<STRONG>setvbuf(</STRONG><EM>stream</EM><STRONG>,</STRONG> <EM>buf</EM><STRONG>,</STRONG> <STRONG>_IOFBF,</STRONG> <EM>size</EM><STRONG>)</STRONG>
|
|
Causes input/output to be fully buffered using the character array
|
|
<EM>buf</EM> whose size is determined by the <EM>size</EM> argument. If <EM>buf</EM> is the
|
|
constant pointer <STRONG>NULL</STRONG>, then an automatically allocated buffer will
|
|
be used.
|
|
|
|
<STRONG>setvbuf(</STRONG><EM>stream</EM><STRONG>,</STRONG> <EM>buf</EM><STRONG>,</STRONG> <STRONG>_IOLBF,</STRONG> <EM>size</EM><STRONG>)</STRONG>
|
|
Like above, except that output will be line buffered, i.e. the
|
|
buffer will be flushed when a newline is written, the buffer is
|
|
full, or input is requested.
|
|
|
|
<STRONG>setvbuf(</STRONG><EM>stream</EM><STRONG>,</STRONG> <EM>buf</EM><STRONG>,</STRONG> <STRONG>_IONBF,</STRONG> <EM>size</EM><STRONG>)</STRONG>
|
|
Causes input/output to be completely unbuffered. <EM>Buf</EM> and <EM>size</EM> are
|
|
ignored.
|
|
|
|
|
|
|
|
A file can be changed between unbuffered, line buffered, or block
|
|
buffered by using <STRONG>freopen</STRONG> (see <STRONG><A HREF="../man3/fopen.3.html">fopen(3)</A></STRONG>) followed by the appropriate
|
|
<STRONG>setvbuf</STRONG> call.
|
|
|
|
|
|
</PRE>
|
|
<H2>SEE ALSO</H2><PRE>
|
|
<STRONG><A HREF="../man3/fopen.3.html">fopen(3)</A></STRONG>, <STRONG><A HREF="../man3/getc.3.html">getc(3)</A></STRONG>, <STRONG><A HREF="../man3/putc.3.html">putc(3)</A></STRONG>, <STRONG><A HREF="../man3/malloc.3.html">malloc(3)</A></STRONG>, <STRONG><A HREF="../man3/fclose.3.html">fclose(3)</A></STRONG>, <STRONG><A HREF="../man3/puts.3.html">puts(3)</A></STRONG>, <STRONG><A HREF="../man3/printf.3.html">printf(3)</A></STRONG>,
|
|
<STRONG><A HREF="../man3/fread.3.html">fread(3)</A></STRONG>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</PRE>
|
|
</BODY>
|
|
</HTML>
|