setbuf.3s

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 3S 代码 · 共 172 行

3S
172
字号
.\" SCCSID: @(#)setbuf.3s	8.2	1/29/91.TH setbuf 3s .SH Namesetbuf, setbuffer, setlinebuf, setvbuf \- assign buffering to a stream.SH Syntax.B #include <stdio.h>.PP.B void setbuf(\fIstream, buf\fP).br.SM.B FILE.B *\fIstream\fP;.br.B char *\fIbuf\fP;.PP.B void setbuffer(\fIstream, buf, size\fP).br.SM.B FILE.B *\fIstream\fP;.br.B char *\fIbuf\fP;.br.B int \fIsize\fP;.PP.B void setlinebuf(\fIstream\fP).br.SM.B FILE.B *\fIstream\fP;.PP.B int setvbuf(\fIstream, buf, type, size\fP).br.B FILE *\fIstream\fP;.br.B char *\fIbuf\fP;.br .B int \fItype\fP;.B size_t \fIsize\fP; .SH Description.NXR "setbuf subroutine".NXR "setbuffer subroutine".NXR "setlinebuf subroutine".NXR "setvbuf subroutine".NXR "stream" "assigning buffering to".NXR "buffering" "types of"The three types of buffering available are unbuffered, block buffered,and line buffered.When an output stream is unbuffered, information appears on thedestination file or terminal as soon as written;when it is block buffered manycharacters are saved up and written as a block;when it is line buffered characters are saved up until a new line isencountered or input is read from stdin.The routine.PN fflush ,may be used to force the block out early.Normally all files are block buffered.For further information, see .MS fclose 3s .A buffer is obtained from .MS malloc 3upon the first.PN getcor.PN putcon the file.If the standard stream.B stdoutrefers to a terminal it is line buffered.The standard stream.B stderris always unbuffered..PPThe.PN setbufroutine is used after a stream has been opened but before it is read or written.The character array.I bufis used instead of an automatically allocated buffer.  If.I bufis the constant pointer NULL,input/output will be completely unbuffered.A manifest constant BUFSIZtells how big an array is needed:.EXchar buf[BUFSIZ];.EE.PPThe.PN setbufferroutine, an alternate form of .PN setbuf ,is used after a stream has been opened but before it is read or written.The character array.I bufwhose size is determined by the .I sizeargument is used instead of an automatically allocated buffer.  If.I bufis the constant pointer NULL,input/output will be completely unbuffered..PPThe.PN setlinebufroutine is used to change.B stdoutor.B stderrfrom block buffered or unbuffered to line buffered.Unlike.PN setbufand.PN setbufferit can be used at any time that the file descriptor is active..PPThe.PN setvbufroutine may be used after a stream has been opened butbefore it is read or written..I Typedetermines how \fIstream\fP will be buffered.Legal values for \fItype\fP, defined in stdio.h are:.TP 15 _IOFBFcauses input/output to be fully buffered..TP 15 _IOLBFcauses output to be line buffered; the buffer will beflushed when a new line is written, the buffer is full, or input is requested..TP 15 _IONBFcauses input/output to be completely unbuffered..PPIf \fIbuf\fP is not the NULL pointer, the array it points to will be used for buffering,instead of an automatically allocated buffer.The.I sizespecifies the size of the buffer to be used.  The constantBUFSIZ in <stdio.h> is suggested as a good buffer size.If input/output is unbuffered, \fIbuf\fP and \fIsize\fPare ignored..PPBy default, output to a terminal is line bufferedand all other input/output is fully buffered..PPA file can be changed from unbuffered or line buffered to block bufferedby using.PN freopen .For further information, see .MS fopen 3s .A file can be changed from block buffered or line buffered to unbufferedby using.PN freopenfollowed by.PN setbufwith a buffer argument of NULL..SH RestrictionsThe standard error stream should be line buffered by default..PPThe.PN setbufferand.PN setlinebuffunctions are not portable to non 4.2 BSD versions of UNIX..SH See Alsomalloc(3), fclose(3s), fopen(3s), fread(3s), getc(3s), printf(3s), putc(3s), puts(3s).

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?