158f0484fSRodney W. Grimes.\" Copyright (c) 1990, 1991, 1993 258f0484fSRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 358f0484fSRodney W. Grimes.\" 458f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 558f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions 658f0484fSRodney W. Grimes.\" are met: 758f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 858f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 958f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 1058f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 1158f0484fSRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 1258f0484fSRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software 1358f0484fSRodney W. Grimes.\" must display the following acknowledgement: 1458f0484fSRodney W. Grimes.\" This product includes software developed by the University of 1558f0484fSRodney W. Grimes.\" California, Berkeley and its contributors. 1658f0484fSRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors 1758f0484fSRodney W. Grimes.\" may be used to endorse or promote products derived from this software 1858f0484fSRodney W. Grimes.\" without specific prior written permission. 1958f0484fSRodney W. Grimes.\" 2058f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2158f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2258f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2358f0484fSRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2458f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2558f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2658f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2758f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2858f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2958f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3058f0484fSRodney W. Grimes.\" SUCH DAMAGE. 3158f0484fSRodney W. Grimes.\" 3258f0484fSRodney W. Grimes.\" @(#)stdio.3 8.7 (Berkeley) 4/19/94 337f3dea24SPeter Wemm.\" $FreeBSD$ 3458f0484fSRodney W. Grimes.\" 3558f0484fSRodney W. Grimes.Dd April 19, 1994 3658f0484fSRodney W. Grimes.Dt STDIO 3 3758f0484fSRodney W. Grimes.Os BSD 4 3858f0484fSRodney W. Grimes.Sh NAME 3958f0484fSRodney W. Grimes.Nm stdio 4058f0484fSRodney W. Grimes.Nd standard input/output library functions 4158f0484fSRodney W. Grimes.Sh SYNOPSIS 4258f0484fSRodney W. Grimes.Fd #include <stdio.h> 4358f0484fSRodney W. Grimes.Fd FILE *stdin; 4458f0484fSRodney W. Grimes.Fd FILE *stdout; 4558f0484fSRodney W. Grimes.Fd FILE *stderr; 4658f0484fSRodney W. Grimes.Sh DESCRIPTION 4758f0484fSRodney W. GrimesThe standard 4858f0484fSRodney W. Grimes.Tn I/O 4958f0484fSRodney W. Grimeslibrary provides a simple and efficient buffered stream 5058f0484fSRodney W. Grimes.Tn I/O 5158f0484fSRodney W. Grimesinterface. 52a5ed710cSMike PritchardInput and output is mapped into logical data streams 5358f0484fSRodney W. Grimesand the physical 5458f0484fSRodney W. Grimes.Tn I/O 55c6ff3a1bSSheldon Hearncharacteristics are concealed. 56c6ff3a1bSSheldon HearnThe functions and macros are listed 5758f0484fSRodney W. Grimesbelow; more information is available from the individual man pages. 5858f0484fSRodney W. Grimes.Pp 5958f0484fSRodney W. GrimesA stream is associated with an external file (which may be a physical 6058f0484fSRodney W. Grimesdevice) by 6158f0484fSRodney W. Grimes.Em opening 62c6ff3a1bSSheldon Hearna file, which may involve creating a new file. 63c6ff3a1bSSheldon HearnCreating an 6458f0484fSRodney W. Grimesexisting file causes its former contents to be discarded. 6558f0484fSRodney W. GrimesIf a file can support positioning requests (such as a disk file, as opposed 6658f0484fSRodney W. Grimesto a terminal) then a 6758f0484fSRodney W. Grimes.Em file position indicator 6858f0484fSRodney W. Grimesassociated with the stream is positioned at the start of the file (byte 69c6ff3a1bSSheldon Hearnzero), unless the file is opened with append mode. 70c6ff3a1bSSheldon HearnIf append mode 71b8e5e42dSStephen McKayis used, the position indicator will be placed at the end-of-file. 7258f0484fSRodney W. GrimesThe position indicator is maintained by subsequent reads, writes 73c6ff3a1bSSheldon Hearnand positioning requests. 74c6ff3a1bSSheldon HearnAll input occurs as if the characters 7558f0484fSRodney W. Grimeswere read by successive calls to the 7658f0484fSRodney W. Grimes.Xr fgetc 3 77a5ed710cSMike Pritchardfunction; all output takes place as if all characters were 78b8e5e42dSStephen McKaywritten by successive calls to the 7958f0484fSRodney W. Grimes.Xr fputc 3 8058f0484fSRodney W. Grimesfunction. 8158f0484fSRodney W. Grimes.Pp 8258f0484fSRodney W. GrimesA file is disassociated from a stream by 8358f0484fSRodney W. Grimes.Em closing 8458f0484fSRodney W. Grimesthe file. 85a5ed710cSMike PritchardOutput streams are flushed (any unwritten buffer contents are transferred 8658f0484fSRodney W. Grimesto the host environment) before the stream is disassociated from the file. 8758f0484fSRodney W. GrimesThe value of a pointer to a 8858f0484fSRodney W. Grimes.Dv FILE 89b8e5e42dSStephen McKayobject is indeterminate (garbage) after a file is closed. 9058f0484fSRodney W. Grimes.Pp 9158f0484fSRodney W. GrimesA file may be subsequently reopened, by the same or another program 9258f0484fSRodney W. Grimesexecution, and its contents reclaimed or modified (if it can be repositioned 9358f0484fSRodney W. Grimesat the start). If the main function returns to its original caller, or 9458f0484fSRodney W. Grimesthe 9558f0484fSRodney W. Grimes.Xr exit 3 9658f0484fSRodney W. Grimesfunction is called, all open files are closed (hence all output 9758f0484fSRodney W. Grimesstreams are flushed) before program termination. Other methods 98b8e5e42dSStephen McKayof program termination may not close files properly and hence 99b8e5e42dSStephen McKaybuffered output may be lost. In particular, 100b8e5e42dSStephen McKay.Xr _exit 2 101b8e5e42dSStephen McKaydoes not flush stdio files. Neither does an exit due to a signal. 102b8e5e42dSStephen McKayBuffers are flushed by 10358f0484fSRodney W. Grimes.Xr abort 3 104b8e5e42dSStephen McKayas required by POSIX, although previous implementations did not. 10558f0484fSRodney W. Grimes.Pp 106b8e5e42dSStephen McKayThis implementation makes no distinction between 10758f0484fSRodney W. Grimes.Dq text 10858f0484fSRodney W. Grimesand 10958f0484fSRodney W. Grimes.Dq binary 11058f0484fSRodney W. Grimesstreams. 11158f0484fSRodney W. GrimesIn effect, all streams are binary. 11258f0484fSRodney W. GrimesNo translation is performed and no extra padding appears on any stream. 11358f0484fSRodney W. Grimes.Pp 11458f0484fSRodney W. GrimesAt program startup, three streams are predefined and need not be 11558f0484fSRodney W. Grimesopened explicitly: 11658f0484fSRodney W. Grimes.Bl -bullet -compact -offset indent 11758f0484fSRodney W. Grimes.It 11858f0484fSRodney W. Grimes.Em standard input 11958f0484fSRodney W. Grimes(for reading conventional input), 12058f0484fSRodney W. Grimes.It 12158f0484fSRodney W. Grimes.Em standard output 122712dc76eSMike Pritchard(for writing conventional output), and 12358f0484fSRodney W. Grimes.It 12458f0484fSRodney W. Grimes.Em standard error 12558f0484fSRodney W. Grimes(for writing diagnostic output). 12658f0484fSRodney W. Grimes.El 12758f0484fSRodney W. GrimesThese streams are abbreviated 12858f0484fSRodney W. Grimes.Em stdin , stdout 12958f0484fSRodney W. Grimesand 13058f0484fSRodney W. Grimes.Em stderr . 13158f0484fSRodney W. GrimesInitially, the standard error stream 13258f0484fSRodney W. Grimesis unbuffered; the standard input and output streams are 13358f0484fSRodney W. Grimesfully buffered if and only if the streams do not refer to 13458f0484fSRodney W. Grimesan interactive or 13558f0484fSRodney W. Grimes.Dq terminal 13658f0484fSRodney W. Grimesdevice, as determined by the 13758f0484fSRodney W. Grimes.Xr isatty 3 13858f0484fSRodney W. Grimesfunction. 13958f0484fSRodney W. GrimesIn fact, 14058f0484fSRodney W. Grimes.Em all 14158f0484fSRodney W. Grimesfreshly-opened streams that refer to terminal devices 14258f0484fSRodney W. Grimesdefault to line buffering, and 14358f0484fSRodney W. Grimespending output to such streams is written automatically 144b8e5e42dSStephen McKaywhenever such an input stream is read. 14558f0484fSRodney W. GrimesNote that this applies only to 14658f0484fSRodney W. Grimes.Dq "true reads" ; 14758f0484fSRodney W. Grimesif the read request can be satisfied by existing buffered data, 14858f0484fSRodney W. Grimesno automatic flush will occur. 14958f0484fSRodney W. GrimesIn these cases, 15058f0484fSRodney W. Grimesor when a large amount of computation is done after printing 15158f0484fSRodney W. Grimespart of a line on an output terminal, it is necessary to 15258f0484fSRodney W. Grimes.Xr fflush 3 15358f0484fSRodney W. Grimesthe standard output before going off and computing so that the output 15458f0484fSRodney W. Grimeswill appear. 15558f0484fSRodney W. GrimesAlternatively, these defaults may be modified via the 15658f0484fSRodney W. Grimes.Xr setvbuf 3 15758f0484fSRodney W. Grimesfunction. 15858f0484fSRodney W. Grimes.Pp 15958f0484fSRodney W. GrimesThe 16058f0484fSRodney W. Grimes.Nm stdio 16158f0484fSRodney W. Grimeslibrary is a part of the library 162064f0074SMike Pritchard.Nm libc 163b8e5e42dSStephen McKayand routines are automatically loaded as needed by the C compiler. 16458f0484fSRodney W. GrimesThe 16558f0484fSRodney W. Grimes.Tn SYNOPSIS 16658f0484fSRodney W. Grimessections of the following manual pages indicate which include files 16758f0484fSRodney W. Grimesare to be used, what the compiler declaration for the function 16858f0484fSRodney W. Grimeslooks like and which external variables are of interest. 16958f0484fSRodney W. Grimes.Pp 17058f0484fSRodney W. GrimesThe following are defined as macros; 17158f0484fSRodney W. Grimesthese names may not be re-used 17258f0484fSRodney W. Grimeswithout first removing their current definitions with 17358f0484fSRodney W. Grimes.Dv #undef : 17458f0484fSRodney W. Grimes.Dv BUFSIZ , 17558f0484fSRodney W. Grimes.Dv EOF , 17658f0484fSRodney W. Grimes.Dv FILENAME_MAX , 17724653713SBruce Evans.Dv FOPEN_MAX , 17858f0484fSRodney W. Grimes.Dv L_cuserid , 17958f0484fSRodney W. Grimes.Dv L_ctermid , 18058f0484fSRodney W. Grimes.Dv L_tmpnam, 18158f0484fSRodney W. Grimes.Dv NULL , 182b8e5e42dSStephen McKay.Dv P_tmpdir, 183b8e5e42dSStephen McKay.Dv SEEK_CUR , 18458f0484fSRodney W. Grimes.Dv SEEK_END , 18558f0484fSRodney W. Grimes.Dv SEEK_SET , 18658f0484fSRodney W. Grimes.Dv TMP_MAX , 18758f0484fSRodney W. Grimes.Dv clearerr , 18858f0484fSRodney W. Grimes.Dv feof , 18958f0484fSRodney W. Grimes.Dv ferror , 19058f0484fSRodney W. Grimes.Dv fileno , 191b8e5e42dSStephen McKay.Dv fropen , 19258f0484fSRodney W. Grimes.Dv fwopen , 19358f0484fSRodney W. Grimes.Dv getc , 19458f0484fSRodney W. Grimes.Dv getchar , 19558f0484fSRodney W. Grimes.Dv putc , 19658f0484fSRodney W. Grimes.Dv putchar , 19758f0484fSRodney W. Grimes.Dv stderr , 19858f0484fSRodney W. Grimes.Dv stdin , 199b8e5e42dSStephen McKay.Dv stdout , 200b8e5e42dSStephen McKay.Dv vfscanf . 20158f0484fSRodney W. GrimesFunction versions of the macro functions 202b8e5e42dSStephen McKay.Fn clearerr , 203064f0074SMike Pritchard.Fn feof , 204064f0074SMike Pritchard.Fn ferror , 205064f0074SMike Pritchard.Fn fileno , 206064f0074SMike Pritchard.Fn getc , 207064f0074SMike Pritchard.Fn getchar , 208064f0074SMike Pritchard.Fn putc , 20958f0484fSRodney W. Grimesand 210064f0074SMike Pritchard.Fn putchar 211b8e5e42dSStephen McKayexist and will be used if the macro 21258f0484fSRodney W. Grimesdefinitions are explicitly removed. 21358f0484fSRodney W. Grimes.Sh SEE ALSO 21458f0484fSRodney W. Grimes.Xr close 2 , 21575141cc9SWolfram Schneider.Xr open 2 , 21658f0484fSRodney W. Grimes.Xr read 2 , 21758f0484fSRodney W. Grimes.Xr write 2 21858f0484fSRodney W. Grimes.Sh BUGS 21958f0484fSRodney W. GrimesThe standard buffered functions do not interact well with certain other 22058f0484fSRodney W. Grimeslibrary and system functions, especially 221b8e5e42dSStephen McKay.Xr vfork 2 . 22258f0484fSRodney W. Grimes.Sh STANDARDS 22358f0484fSRodney W. GrimesThe 22458f0484fSRodney W. Grimes.Nm stdio 22558f0484fSRodney W. Grimeslibrary conforms to 22658f0484fSRodney W. Grimes.St -ansiC . 22758f0484fSRodney W. Grimes.Sh LIST OF FUNCTIONS 22858f0484fSRodney W. Grimes.Bl -column "Description" 22958f0484fSRodney W. Grimes.Sy Function Description 230b8e5e42dSStephen McKayasprintf formatted output conversion 23158f0484fSRodney W. Grimesclearerr check and reset stream status 23258f0484fSRodney W. Grimesfclose close a stream 23358f0484fSRodney W. Grimesfdopen stream open functions 23458f0484fSRodney W. Grimesfeof check and reset stream status 23558f0484fSRodney W. Grimesferror check and reset stream status 23658f0484fSRodney W. Grimesfflush flush a stream 23758f0484fSRodney W. Grimesfgetc get next character or word from input stream 238712dc76eSMike Pritchardfgetln get a line from a stream 23958f0484fSRodney W. Grimesfgetpos reposition a stream 24058f0484fSRodney W. Grimesfgets get a line from a stream 24158f0484fSRodney W. Grimesfileno check and reset stream status 24258f0484fSRodney W. Grimesfopen stream open functions 24358f0484fSRodney W. Grimesfprintf formatted output conversion 24458f0484fSRodney W. Grimesfpurge flush a stream 24558f0484fSRodney W. Grimesfputc output a character or word to a stream 24658f0484fSRodney W. Grimesfputs output a line to a stream 24758f0484fSRodney W. Grimesfread binary stream input/output 24858f0484fSRodney W. Grimesfreopen stream open functions 24958f0484fSRodney W. Grimesfropen open a stream 25058f0484fSRodney W. Grimesfscanf input format conversion 25158f0484fSRodney W. Grimesfseek reposition a stream 25258f0484fSRodney W. Grimesfsetpos reposition a stream 25358f0484fSRodney W. Grimesftell reposition a stream 25458f0484fSRodney W. Grimesfunopen open a stream 25558f0484fSRodney W. Grimesfwopen open a stream 25658f0484fSRodney W. Grimesfwrite binary stream input/output 25758f0484fSRodney W. Grimesgetc get next character or word from input stream 25858f0484fSRodney W. Grimesgetchar get next character or word from input stream 25958f0484fSRodney W. Grimesgets get a line from a stream 26058f0484fSRodney W. Grimesgetw get next character or word from input stream 261b8e5e42dSStephen McKaymkdtemp create unique temporary file 26258f0484fSRodney W. Grimesmkstemp create unique temporary file 26358f0484fSRodney W. Grimesmktemp create unique temporary file 26458f0484fSRodney W. Grimesperror system error messages 26558f0484fSRodney W. Grimesprintf formatted output conversion 26658f0484fSRodney W. Grimesputc output a character or word to a stream 26758f0484fSRodney W. Grimesputchar output a character or word to a stream 26858f0484fSRodney W. Grimesputs output a line to a stream 26958f0484fSRodney W. Grimesputw output a character or word to a stream 27058f0484fSRodney W. Grimesremove remove directory entry 27158f0484fSRodney W. Grimesrewind reposition a stream 27258f0484fSRodney W. Grimesscanf input format conversion 27358f0484fSRodney W. Grimessetbuf stream buffering operations 27458f0484fSRodney W. Grimessetbuffer stream buffering operations 27558f0484fSRodney W. Grimessetlinebuf stream buffering operations 27658f0484fSRodney W. Grimessetvbuf stream buffering operations 27758f0484fSRodney W. Grimessnprintf formatted output conversion 27858f0484fSRodney W. Grimessprintf formatted output conversion 27958f0484fSRodney W. Grimessscanf input format conversion 28058f0484fSRodney W. Grimesstrerror system error messages 28158f0484fSRodney W. Grimessys_errlist system error messages 28258f0484fSRodney W. Grimessys_nerr system error messages 28358f0484fSRodney W. Grimestempnam temporary file routines 28458f0484fSRodney W. Grimestmpfile temporary file routines 28558f0484fSRodney W. Grimestmpnam temporary file routines 28658f0484fSRodney W. Grimesungetc un-get character from input stream 287b8e5e42dSStephen McKayvasprintf formatted output conversion 28858f0484fSRodney W. Grimesvfprintf formatted output conversion 28958f0484fSRodney W. Grimesvfscanf input format conversion 29058f0484fSRodney W. Grimesvprintf formatted output conversion 29158f0484fSRodney W. Grimesvscanf input format conversion 29258f0484fSRodney W. Grimesvsnprintf formatted output conversion 29358f0484fSRodney W. Grimesvsprintf formatted output conversion 29458f0484fSRodney W. Grimesvsscanf input format conversion 29558f0484fSRodney W. Grimes.El 296