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 3358f0484fSRodney W. Grimes.\" 3458f0484fSRodney W. Grimes.Dd April 19, 1994 3558f0484fSRodney W. Grimes.Dt STDIO 3 3658f0484fSRodney W. Grimes.Os BSD 4 3758f0484fSRodney W. Grimes.Sh NAME 3858f0484fSRodney W. Grimes.Nm stdio 3958f0484fSRodney W. Grimes.Nd standard input/output library functions 4058f0484fSRodney W. Grimes.Sh SYNOPSIS 4158f0484fSRodney W. Grimes.Fd #include <stdio.h> 4258f0484fSRodney W. Grimes.Fd FILE *stdin; 4358f0484fSRodney W. Grimes.Fd FILE *stdout; 4458f0484fSRodney W. Grimes.Fd FILE *stderr; 4558f0484fSRodney W. Grimes.Sh DESCRIPTION 4658f0484fSRodney W. GrimesThe standard 4758f0484fSRodney W. Grimes.Tn I/O 4858f0484fSRodney W. Grimeslibrary provides a simple and efficient buffered stream 4958f0484fSRodney W. Grimes.Tn I/O 5058f0484fSRodney W. Grimesinterface. 51a5ed710cSMike PritchardInput and output is mapped into logical data streams 5258f0484fSRodney W. Grimesand the physical 5358f0484fSRodney W. Grimes.Tn I/O 5458f0484fSRodney W. Grimescharacteristics are concealed. The functions and macros are listed 5558f0484fSRodney W. Grimesbelow; more information is available from the individual man pages. 5658f0484fSRodney W. Grimes.Pp 5758f0484fSRodney W. GrimesA stream is associated with an external file (which may be a physical 5858f0484fSRodney W. Grimesdevice) by 5958f0484fSRodney W. Grimes.Em opening 6058f0484fSRodney W. Grimesa file, which may involve creating a new file. Creating an 6158f0484fSRodney W. Grimesexisting file causes its former contents to be discarded. 6258f0484fSRodney W. GrimesIf a file can support positioning requests (such as a disk file, as opposed 6358f0484fSRodney W. Grimesto a terminal) then a 6458f0484fSRodney W. Grimes.Em file position indicator 6558f0484fSRodney W. Grimesassociated with the stream is positioned at the start of the file (byte 66712dc76eSMike Pritchardzero), unless the file is opened with append mode. If append mode 67b8e5e42dSStephen McKayis used, the position indicator will be placed at the end-of-file. 6858f0484fSRodney W. GrimesThe position indicator is maintained by subsequent reads, writes 6958f0484fSRodney W. Grimesand positioning requests. All input occurs as if the characters 7058f0484fSRodney W. Grimeswere read by successive calls to the 7158f0484fSRodney W. Grimes.Xr fgetc 3 72a5ed710cSMike Pritchardfunction; all output takes place as if all characters were 73b8e5e42dSStephen McKaywritten by successive calls to the 7458f0484fSRodney W. Grimes.Xr fputc 3 7558f0484fSRodney W. Grimesfunction. 7658f0484fSRodney W. Grimes.Pp 7758f0484fSRodney W. GrimesA file is disassociated from a stream by 7858f0484fSRodney W. Grimes.Em closing 7958f0484fSRodney W. Grimesthe file. 80a5ed710cSMike PritchardOutput streams are flushed (any unwritten buffer contents are transferred 8158f0484fSRodney W. Grimesto the host environment) before the stream is disassociated from the file. 8258f0484fSRodney W. GrimesThe value of a pointer to a 8358f0484fSRodney W. Grimes.Dv FILE 84b8e5e42dSStephen McKayobject is indeterminate (garbage) after a file is closed. 8558f0484fSRodney W. Grimes.Pp 8658f0484fSRodney W. GrimesA file may be subsequently reopened, by the same or another program 8758f0484fSRodney W. Grimesexecution, and its contents reclaimed or modified (if it can be repositioned 8858f0484fSRodney W. Grimesat the start). If the main function returns to its original caller, or 8958f0484fSRodney W. Grimesthe 9058f0484fSRodney W. Grimes.Xr exit 3 9158f0484fSRodney W. Grimesfunction is called, all open files are closed (hence all output 9258f0484fSRodney W. Grimesstreams are flushed) before program termination. Other methods 93b8e5e42dSStephen McKayof program termination may not close files properly and hence 94b8e5e42dSStephen McKaybuffered output may be lost. In particular, 95b8e5e42dSStephen McKay.Xr _exit 2 96b8e5e42dSStephen McKaydoes not flush stdio files. Neither does an exit due to a signal. 97b8e5e42dSStephen McKayBuffers are flushed by 9858f0484fSRodney W. Grimes.Xr abort 3 99b8e5e42dSStephen McKayas required by POSIX, although previous implementations did not. 10058f0484fSRodney W. Grimes.Pp 101b8e5e42dSStephen McKayThis implementation makes no distinction between 10258f0484fSRodney W. Grimes.Dq text 10358f0484fSRodney W. Grimesand 10458f0484fSRodney W. Grimes.Dq binary 10558f0484fSRodney W. Grimesstreams. 10658f0484fSRodney W. GrimesIn effect, all streams are binary. 10758f0484fSRodney W. GrimesNo translation is performed and no extra padding appears on any stream. 10858f0484fSRodney W. Grimes.Pp 10958f0484fSRodney W. GrimesAt program startup, three streams are predefined and need not be 11058f0484fSRodney W. Grimesopened explicitly: 11158f0484fSRodney W. Grimes.Bl -bullet -compact -offset indent 11258f0484fSRodney W. Grimes.It 11358f0484fSRodney W. Grimes.Em standard input 11458f0484fSRodney W. Grimes(for reading conventional input), 11558f0484fSRodney W. Grimes.It 11658f0484fSRodney W. Grimes.Em standard output 117712dc76eSMike Pritchard(for writing conventional output), and 11858f0484fSRodney W. Grimes.It 11958f0484fSRodney W. Grimes.Em standard error 12058f0484fSRodney W. Grimes(for writing diagnostic output). 12158f0484fSRodney W. Grimes.El 12258f0484fSRodney W. GrimesThese streams are abbreviated 12358f0484fSRodney W. Grimes.Em stdin , stdout 12458f0484fSRodney W. Grimesand 12558f0484fSRodney W. Grimes.Em stderr . 12658f0484fSRodney W. GrimesInitially, the standard error stream 12758f0484fSRodney W. Grimesis unbuffered; the standard input and output streams are 12858f0484fSRodney W. Grimesfully buffered if and only if the streams do not refer to 12958f0484fSRodney W. Grimesan interactive or 13058f0484fSRodney W. Grimes.Dq terminal 13158f0484fSRodney W. Grimesdevice, as determined by the 13258f0484fSRodney W. Grimes.Xr isatty 3 13358f0484fSRodney W. Grimesfunction. 13458f0484fSRodney W. GrimesIn fact, 13558f0484fSRodney W. Grimes.Em all 13658f0484fSRodney W. Grimesfreshly-opened streams that refer to terminal devices 13758f0484fSRodney W. Grimesdefault to line buffering, and 13858f0484fSRodney W. Grimespending output to such streams is written automatically 139b8e5e42dSStephen McKaywhenever such an input stream is read. 14058f0484fSRodney W. GrimesNote that this applies only to 14158f0484fSRodney W. Grimes.Dq "true reads" ; 14258f0484fSRodney W. Grimesif the read request can be satisfied by existing buffered data, 14358f0484fSRodney W. Grimesno automatic flush will occur. 14458f0484fSRodney W. GrimesIn these cases, 14558f0484fSRodney W. Grimesor when a large amount of computation is done after printing 14658f0484fSRodney W. Grimespart of a line on an output terminal, it is necessary to 14758f0484fSRodney W. Grimes.Xr fflush 3 14858f0484fSRodney W. Grimesthe standard output before going off and computing so that the output 14958f0484fSRodney W. Grimeswill appear. 15058f0484fSRodney W. GrimesAlternatively, these defaults may be modified via the 15158f0484fSRodney W. Grimes.Xr setvbuf 3 15258f0484fSRodney W. Grimesfunction. 15358f0484fSRodney W. Grimes.Pp 15458f0484fSRodney W. GrimesThe 15558f0484fSRodney W. Grimes.Nm stdio 15658f0484fSRodney W. Grimeslibrary is a part of the library 157064f0074SMike Pritchard.Nm libc 158b8e5e42dSStephen McKayand routines are automatically loaded as needed by the C compiler. 15958f0484fSRodney W. GrimesThe 16058f0484fSRodney W. Grimes.Tn SYNOPSIS 16158f0484fSRodney W. Grimessections of the following manual pages indicate which include files 16258f0484fSRodney W. Grimesare to be used, what the compiler declaration for the function 16358f0484fSRodney W. Grimeslooks like and which external variables are of interest. 16458f0484fSRodney W. Grimes.Pp 16558f0484fSRodney W. GrimesThe following are defined as macros; 16658f0484fSRodney W. Grimesthese names may not be re-used 16758f0484fSRodney W. Grimeswithout first removing their current definitions with 16858f0484fSRodney W. Grimes.Dv #undef : 16958f0484fSRodney W. Grimes.Dv BUFSIZ , 17058f0484fSRodney W. Grimes.Dv EOF , 17158f0484fSRodney W. Grimes.Dv FILENAME_MAX , 17224653713SBruce Evans.Dv FOPEN_MAX , 17358f0484fSRodney W. Grimes.Dv L_cuserid , 17458f0484fSRodney W. Grimes.Dv L_ctermid , 17558f0484fSRodney W. Grimes.Dv L_tmpnam, 17658f0484fSRodney W. Grimes.Dv NULL , 177b8e5e42dSStephen McKay.Dv P_tmpdir, 178b8e5e42dSStephen McKay.Dv SEEK_CUR , 17958f0484fSRodney W. Grimes.Dv SEEK_END , 18058f0484fSRodney W. Grimes.Dv SEEK_SET , 18158f0484fSRodney W. Grimes.Dv TMP_MAX , 18258f0484fSRodney W. Grimes.Dv clearerr , 18358f0484fSRodney W. Grimes.Dv feof , 18458f0484fSRodney W. Grimes.Dv ferror , 18558f0484fSRodney W. Grimes.Dv fileno , 186b8e5e42dSStephen McKay.Dv fropen , 18758f0484fSRodney W. Grimes.Dv fwopen , 18858f0484fSRodney W. Grimes.Dv getc , 18958f0484fSRodney W. Grimes.Dv getchar , 19058f0484fSRodney W. Grimes.Dv putc , 19158f0484fSRodney W. Grimes.Dv putchar , 19258f0484fSRodney W. Grimes.Dv stderr , 19358f0484fSRodney W. Grimes.Dv stdin , 194b8e5e42dSStephen McKay.Dv stdout , 195b8e5e42dSStephen McKay.Dv vfscanf . 19658f0484fSRodney W. GrimesFunction versions of the macro functions 197b8e5e42dSStephen McKay.Fn clearerr , 198064f0074SMike Pritchard.Fn feof , 199064f0074SMike Pritchard.Fn ferror , 200064f0074SMike Pritchard.Fn fileno , 201064f0074SMike Pritchard.Fn getc , 202064f0074SMike Pritchard.Fn getchar , 203064f0074SMike Pritchard.Fn putc , 20458f0484fSRodney W. Grimesand 205064f0074SMike Pritchard.Fn putchar 206b8e5e42dSStephen McKayexist and will be used if the macro 20758f0484fSRodney W. Grimesdefinitions are explicitly removed. 20858f0484fSRodney W. Grimes.Sh SEE ALSO 20958f0484fSRodney W. Grimes.Xr close 2 , 21075141cc9SWolfram Schneider.Xr open 2 , 21158f0484fSRodney W. Grimes.Xr read 2 , 21258f0484fSRodney W. Grimes.Xr write 2 21358f0484fSRodney W. Grimes.Sh BUGS 21458f0484fSRodney W. GrimesThe standard buffered functions do not interact well with certain other 21558f0484fSRodney W. Grimeslibrary and system functions, especially 216b8e5e42dSStephen McKay.Xr vfork 2 . 21758f0484fSRodney W. Grimes.Sh STANDARDS 21858f0484fSRodney W. GrimesThe 21958f0484fSRodney W. Grimes.Nm stdio 22058f0484fSRodney W. Grimeslibrary conforms to 22158f0484fSRodney W. Grimes.St -ansiC . 22258f0484fSRodney W. Grimes.Sh LIST OF FUNCTIONS 22358f0484fSRodney W. Grimes.Bl -column "Description" 22458f0484fSRodney W. Grimes.Sy Function Description 225b8e5e42dSStephen McKayasprintf formatted output conversion 22658f0484fSRodney W. Grimesclearerr check and reset stream status 22758f0484fSRodney W. Grimesfclose close a stream 22858f0484fSRodney W. Grimesfdopen stream open functions 22958f0484fSRodney W. Grimesfeof check and reset stream status 23058f0484fSRodney W. Grimesferror check and reset stream status 23158f0484fSRodney W. Grimesfflush flush a stream 23258f0484fSRodney W. Grimesfgetc get next character or word from input stream 233712dc76eSMike Pritchardfgetln get a line from a stream 23458f0484fSRodney W. Grimesfgetpos reposition a stream 23558f0484fSRodney W. Grimesfgets get a line from a stream 23658f0484fSRodney W. Grimesfileno check and reset stream status 23758f0484fSRodney W. Grimesfopen stream open functions 23858f0484fSRodney W. Grimesfprintf formatted output conversion 23958f0484fSRodney W. Grimesfpurge flush a stream 24058f0484fSRodney W. Grimesfputc output a character or word to a stream 24158f0484fSRodney W. Grimesfputs output a line to a stream 24258f0484fSRodney W. Grimesfread binary stream input/output 24358f0484fSRodney W. Grimesfreopen stream open functions 24458f0484fSRodney W. Grimesfropen open a stream 24558f0484fSRodney W. Grimesfscanf input format conversion 24658f0484fSRodney W. Grimesfseek reposition a stream 24758f0484fSRodney W. Grimesfsetpos reposition a stream 24858f0484fSRodney W. Grimesftell reposition a stream 24958f0484fSRodney W. Grimesfunopen open a stream 25058f0484fSRodney W. Grimesfwopen open a stream 25158f0484fSRodney W. Grimesfwrite binary stream input/output 25258f0484fSRodney W. Grimesgetc get next character or word from input stream 25358f0484fSRodney W. Grimesgetchar get next character or word from input stream 25458f0484fSRodney W. Grimesgets get a line from a stream 25558f0484fSRodney W. Grimesgetw get next character or word from input stream 256b8e5e42dSStephen McKaymkdtemp create unique temporary file 25758f0484fSRodney W. Grimesmkstemp create unique temporary file 25858f0484fSRodney W. Grimesmktemp create unique temporary file 25958f0484fSRodney W. Grimesperror system error messages 26058f0484fSRodney W. Grimesprintf formatted output conversion 26158f0484fSRodney W. Grimesputc output a character or word to a stream 26258f0484fSRodney W. Grimesputchar output a character or word to a stream 26358f0484fSRodney W. Grimesputs output a line to a stream 26458f0484fSRodney W. Grimesputw output a character or word to a stream 26558f0484fSRodney W. Grimesremove remove directory entry 26658f0484fSRodney W. Grimesrewind reposition a stream 26758f0484fSRodney W. Grimesscanf input format conversion 26858f0484fSRodney W. Grimessetbuf stream buffering operations 26958f0484fSRodney W. Grimessetbuffer stream buffering operations 27058f0484fSRodney W. Grimessetlinebuf stream buffering operations 27158f0484fSRodney W. Grimessetvbuf stream buffering operations 27258f0484fSRodney W. Grimessnprintf formatted output conversion 27358f0484fSRodney W. Grimessprintf formatted output conversion 27458f0484fSRodney W. Grimessscanf input format conversion 27558f0484fSRodney W. Grimesstrerror system error messages 27658f0484fSRodney W. Grimessys_errlist system error messages 27758f0484fSRodney W. Grimessys_nerr system error messages 27858f0484fSRodney W. Grimestempnam temporary file routines 27958f0484fSRodney W. Grimestmpfile temporary file routines 28058f0484fSRodney W. Grimestmpnam temporary file routines 28158f0484fSRodney W. Grimesungetc un-get character from input stream 282b8e5e42dSStephen McKayvasprintf formatted output conversion 28358f0484fSRodney W. Grimesvfprintf formatted output conversion 28458f0484fSRodney W. Grimesvfscanf input format conversion 28558f0484fSRodney W. Grimesvprintf formatted output conversion 28658f0484fSRodney W. Grimesvscanf input format conversion 28758f0484fSRodney W. Grimesvsnprintf formatted output conversion 28858f0484fSRodney W. Grimesvsprintf formatted output conversion 28958f0484fSRodney W. Grimesvsscanf input format conversion 29058f0484fSRodney W. Grimes.El 291