📄 stdio.3
字号:
.\" Copyright (c) 1990, 1991, 1993.\" The Regents of the University of California. All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" @(#)stdio.3 8.7 (Berkeley) 4/19/94.\".Dd April 19, 1994.Dt STDIO 3.Os BSD 4.Sh NAME.Nm stdio.Nd standard input/output library functions.Sh SYNOPSIS.Fd #include <stdio.h>.Fd FILE *stdin;.Fd FILE *stdout;.Fd FILE *stderr;.Sh DESCRIPTIONThe standard.Tn I/Olibrary provides a simple and efficient buffered stream.Tn I/Ointerface.Input and ouput is mapped into logical data streamsand the physical.Tn I/Ocharacteristics are concealed. The functions and macros are listedbelow; more information is available from the individual man pages..PpA stream is associated with an external file (which may be a physicaldevice) by.Em openinga file, which may involve creating a new file. Creating anexisting file causes its former contents to be discarded.If a file can support positioning requests (such as a disk file, as opposedto a terminal) then a.Em file position indicatorassociated with the stream is positioned at the start of the file (bytezero), unless the file is opened with appended mode. If append modeis used, the position indicator will be placed the end-of-file.The position indicator is maintained by subsequent reads, writesand positioning requests. All input occurs as if the characterswere read by successive calls to the.Xr fgetc 3function; all ouput takes place as if all characters wereread by successive calls to the.Xr fputc 3function..PpA file is disassociated from a stream by.Em closingthe file.Ouput streams are flushed (any unwritten buffer contents are transferredto the host environment) before the stream is disassociated from the file.The value of a pointer to a.Dv FILEobject is indeterminate after a file is closed (garbage)..PpA file may be subsequently reopened, by the same or another programexecution, and its contents reclaimed or modified (if it can be repositionedat the start). If the main function returns to its original caller, orthe.Xr exit 3function is called, all open files are closed (hence all outputstreams are flushed) before program termination. Other methodsof program termination, such as.Xr abort 3do not bother about closing files properly..PpThis implementation needs and makesno distinction between.Dq textand.Dq binarystreams.In effect, all streams are binary.No translation is performed and no extra padding appears on any stream..PpAt program startup, three streams are predefined and need not beopened explicitly:.Bl -bullet -compact -offset indent.It.Em standard input (for reading conventional input),.It.Em standard output (for writing conventional input), and.It.Em standard error(for writing diagnostic output)..ElThese streams are abbreviated.Em stdin , stdoutand.Em stderr .Initially, the standard error streamis unbuffered; the standard input and output streams arefully buffered if and only if the streams do not refer toan interactive or.Dq terminaldevice, as determined by the.Xr isatty 3function.In fact,.Em allfreshly-opened streams that refer to terminal devicesdefault to line buffering, andpending output to such streams is written automaticallywhenever an such an input stream is read.Note that this applies only to.Dq "true reads" ;if the read request can be satisfied by existing buffered data,no automatic flush will occur.In these cases,or when a large amount of computation is done after printingpart of a line on an output terminal, it is necessary to.Xr fflush 3the standard output before going off and computing so that the outputwill appear.Alternatively, these defaults may be modified via the.Xr setvbuf 3function..PpThe.Nm stdiolibrary is a part of the library.Xr libcand routines are automatically loaded as needed by the compilers.Xr cc 1and.Xr pc 1 .The.Tn SYNOPSISsections of the following manual pages indicate which include filesare to be used, what the compiler declaration for the functionlooks like and which external variables are of interest..PpThe following are defined as macros;these names may not be re-usedwithout first removing their current definitions with.Dv #undef :.Dv BUFSIZ ,.Dv EOF ,.Dv FILENAME_MAX ,.DV FOPEN_MAX ,.Dv L_cuserid ,.Dv L_ctermid ,.Dv L_tmpnam,.Dv NULL ,.Dv SEEK_END ,.Dv SEEK_SET ,.Dv SEE_CUR ,.Dv TMP_MAX ,.Dv clearerr ,.Dv feof ,.Dv ferror ,.Dv fileno ,.Dv freopen ,.Dv fwopen ,.Dv getc ,.Dv getchar ,.Dv putc ,.Dv putchar ,.Dv stderr ,.Dv stdin ,.Dv stdout .Function versions of the macro functions.Xr feof ,.Xr ferror ,.Xr clearerr ,.Xr fileno ,.Xr getc ,.Xr getchar ,.Xr putc ,and.Xr putcharexist and will be used if the macrosdefinitions are explicitly removed..Sh SEE ALSO.Xr open 2 ,.Xr close 2 ,.Xr read 2 ,.Xr write 2.Sh BUGSThe standard buffered functions do not interact well with certain otherlibrary and system functions, especially.Xr vforkand.Xr abort ..Sh STANDARDSThe.Nm stdiolibrary conforms to.St -ansiC ..Sh LIST OF FUNCTIONS.Bl -column "Description".Sy Function Descriptionclearerr check and reset stream statusfclose close a streamfdopen stream open functionsfeof check and reset stream statusferror check and reset stream statusfflush flush a streamfgetc get next character or word from input streamfgetline get a line from a streamfgetpos reposition a streamfgets get a line from a streamfileno check and reset stream statusfopen stream open functionsfprintf formatted output conversionfpurge flush a streamfputc output a character or word to a streamfputs output a line to a streamfread binary stream input/outputfreopen stream open functionsfropen open a streamfscanf input format conversionfseek reposition a streamfsetpos reposition a streamftell reposition a streamfunopen open a streamfwopen open a streamfwrite binary stream input/outputgetc get next character or word from input streamgetchar get next character or word from input streamgets get a line from a streamgetw get next character or word from input streammkstemp create unique temporary filemktemp create unique temporary fileperror system error messagesprintf formatted output conversionputc output a character or word to a streamputchar output a character or word to a streamputs output a line to a streamputw output a character or word to a streamremove remove directory entryrewind reposition a streamscanf input format conversionsetbuf stream buffering operationssetbuffer stream buffering operationssetlinebuf stream buffering operationssetvbuf stream buffering operationssnprintf formatted output conversionsprintf formatted output conversionsscanf input format conversionstrerror system error messagessys_errlist system error messagessys_nerr system error messagestempnam temporary file routinestmpfile temporary file routinestmpnam temporary file routinesungetc un-get character from input streamvfprintf formatted output conversionvfscanf input format conversionvprintf formatted output conversionvscanf input format conversionvsnprintf formatted output conversionvsprintf formatted output conversionvsscanf input format conversion.El
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -