1*49264Scael.\" Copyright (c) 1990, 1991 Regents of the University of California. 2*49264Scael.\" All rights reserved. 320455Smckusick.\" 4*49264Scael.\" %sccs.include.redist.man% 520455Smckusick.\" 6*49264Scael.\" @(#)stdio.3 6.5 (Berkeley) 05/06/91 7*49264Scael.\" 8*49264Scael.Dd 9*49264Scael.Dt STDIO 3 10*49264Scael.Os BSD 4 11*49264Scael.Sh NAME 12*49264Scael.Nm stdio 13*49264Scael.Nd standard input/output library functions 14*49264Scael.Sh SYNOPSIS 15*49264Scael.Fd #include <stdio.h> 16*49264Scael.Fd FILE *stdin; 17*49264Scael.Fd FILE *stdout; 18*49264Scael.Fd FILE *stderr; 19*49264Scael.Sh DESCRIPTION 20*49264ScaelThe standard 21*49264Scael.Tn I/O 22*49264Scaellibrary provides a simple and efficient buffered stream 23*49264Scael.Tn I/O 24*49264Scaelinterface. 25*49264ScaelInput and ouput is mapped into logical data streams 26*49264Scaeland the physical 27*49264Scael.Tn I/O 28*49264Scaelcharacteristics are concealed. The functions and macros are listed 29*49264Scaelbelow; more information is available from the individual man pages. 30*49264Scael.Pp 31*49264ScaelA stream is associated with an external file (which may be a physical 32*49264Scaeldevice) by 33*49264Scael.Em opening 34*49264Scaela file, which may involve creating a new file. Creating an 35*49264Scaelexisting file causes its former contents to be discarded. 36*49264ScaelIf a file can support positioning requests (such as a disk file, as opposed 37*49264Scaelto a terminal) then a 38*49264Scael.Em file position indicator 39*49264Scaelassociated with the stream is positioned at the start of the file (byte 40*49264Scaelzero), unless the file is opened with appened mode. If append mode 41*49264Scaelis used, the position indicator will be placed the end-of-file. 42*49264ScaelThe position indicator is maintained by subsequent reads, writes 43*49264Scaeland positioning requests. All input occurs as if the characters 44*49264Scaelwere read by successive calls to the 45*49264Scael.Xr fgetc 3 46*49264Scaelfunction; all ouput takes place as if all characters were 47*49264Scaelread by successive calls to the 48*49264Scael.Xr fputc 3 49*49264Scaelfunction. 50*49264Scael.Pp 51*49264ScaelA file is disassociated from a stream by 52*49264Scael.Em closing 53*49264Scaelthe file. 54*49264ScaelOuput streams are flushed (any unwritten buffer contents are transfered 55*49264Scaelto the host environment) before the stream is disassociated from the file. 56*49264ScaelThe value of a pointer to a 57*49264Scael.Dv FILE 58*49264Scaelobject is indeterminate after a file is closed (garbage). 59*49264Scael.Pp 60*49264ScaelA file may be subsequently reopened, by the same or another program 61*49264Scaelexecution, and its contents reclaimed or modified (if it can be repositioned 62*49264Scaelat the start). If the main function returns to its original caller, or 63*49264Scaelthe 64*49264Scael.Xr exit 3 65*49264Scaelfunction is called, all open files are closed (hence all output 66*49264Scaelstreams are flushed) before program termination. Other methods 67*49264Scaelof program termination, such as 68*49264Scael.Xr abort 3 69*49264Scaeldo not bother about closing files properly. 70*49264Scael.Pp 71*49264ScaelAt program startup, three text streams are predefined and need not be 72*49264Scaelopened explicitly 73*49264Scael\(em 74*49264Scael.Em standard input 75*49264Scael(for reading converntional input), 76*49264Scael\(em 77*49264Scael.Em standard output 78*49264Scael(for writing converntional input), 7920455Smckusickand 80*49264Scael.Em standard error 81*49264Scael(for writing diagnostic output). 82*49264ScaelThese streams are abbreviated 83*49264Scael.Em stdin , stdout 8420455Smckusickand 85*49264Scael.Em stderr . 86*49264ScaelWhen opened, the standard error stream 87*49264Scaelis not fully buffered; the standard input and output streams are 88*49264Scaelfully buffered if and only if the streams do not to refer to 89*49264Scaelan interactive device. 90*49264Scael.Pp 9146106SbosticOutput streams that refer to terminal devices 9246106Sbosticare always line buffered by default; 9346106Sbosticpending output to such streams is written automatically 9446106Sbosticwhenever an input stream that refers to a terminal device is read. 9546106SbosticIn cases where a large amount of computation is done after printing 9646106Sbosticpart of a line on an output terminal, it is necessary to 97*49264Scael.Xr fflush 3 9846106Sbosticthe standard output before going off and computing so that the output 9946106Sbosticwill appear. 100*49264Scael.Pp 101*49264ScaelThe 102*49264Scael.Nm stdio 103*49264Scaellibrary is a part of the library 104*49264Scael.Xr libc 105*49264Scaeland routines are automatically loaded as needed by the compilers 106*49264Scael.Xr cc 1 107*49264Scaeland 108*49264Scael.Xr pc 1 . 109*49264ScaelThe 110*49264Scael.Tn SYNOPSIS 111*49264Scaelsections of the following manual pages indicate which include files 112*49264Scaelare to be used, what the compiler declaration for the function 113*49264Scaellooks like and which external variables are of interest. 114*49264Scael.Pp 115*49264ScaelThe following are defined as macros; 116*49264Scaelthese names may not be re-used 117*49264Scaelwithout first removing their current definitions with 118*49264Scael.Dv #undef : 119*49264Scael.Dv BUFSIZ , 120*49264Scael.Dv EOF , 121*49264Scael.Dv FILENAME_MAX , 122*49264Scael.DV FOPEN_MAX , 123*49264Scael.Dv L_cuserid , 124*49264Scael.Dv L_ctermid , 125*49264Scael.Dv L_tmpnam, 126*49264Scael.Dv NULL , 127*49264Scael.Dv SEEK_END , 128*49264Scael.Dv SEEK_SET , 129*49264Scael.Dv SEE_CUR , 130*49264Scael.Dv TMP_MAX , 131*49264Scael.Dv clearerr , 132*49264Scael.Dv feof , 133*49264Scael.Dv ferror , 134*49264Scael.Dv fileno , 135*49264Scael.Dv fropen , 136*49264Scael.Dv fwopen , 137*49264Scael.Dv getc , 138*49264Scael.Dv getchar , 139*49264Scael.Dv putc , 140*49264Scael.Dv putchar , 141*49264Scael.Dv stderr , 142*49264Scael.Dv stdin , 143*49264Scael.Dv stdout . 144*49264ScaelFunction versions of the macro functions 145*49264Scael.Xr feof , 146*49264Scael.Xr ferror , 147*49264Scael.Xr clearerr , 148*49264Scael.Xr fileno , 149*49264Scael.Xr getc , 150*49264Scael.Xr getchar , 151*49264Scael.Xr putc , 152*49264Scaeland 153*49264Scael.Xr putchar 154*49264Scaelexist and will be used if the macros 155*49264Scaeldefinitions are explicitly removed. 156*49264Scael.Sh SEE ALSO 157*49264Scael.Xr open 2 , 158*49264Scael.Xr close 2 , 159*49264Scael.Xr read 2 , 160*49264Scael.Xr write 2 161*49264Scael.Sh BUGS 16220456SmckusickThe standard buffered functions do not interact well with certain other 163*49264Scaellibrary and system functions, especially 164*49264Scael.Xr vfork 165*49264Scaeland 166*49264Scael.Xr abort . 167*49264Scael.Sh STANDARDS 168*49264ScaelThe 169*49264Scael.Nm stdio 170*49264Scaellibrary conforms to 171*49264Scael.St -ansiC . 172*49264Scael.Sh LIST OF FUNCTIONS 173*49264Scael.Bl -column "Description" 174*49264Scael.Sy Function Description 175*49264Scaelclearerr check and reset stream status 176*49264Scaelfclose close a stream 177*49264Scaelfdopen stream open functions 178*49264Scaelfeof check and reset stream status 179*49264Scaelferror check and reset stream status 180*49264Scaelfflush flush a stream 181*49264Scaelfgetc get next character or word from input stream 182*49264Scaelfgetline get a line from a stream 183*49264Scaelfgetpos reposition a stream 184*49264Scaelfgets get a line from a stream 185*49264Scaelfileno check and reset stream status 186*49264Scaelfopen stream open functions 187*49264Scaelfprintf formatted output conversion 188*49264Scaelfpurge flush a stream 189*49264Scaelfputc output a character or word to a stream 190*49264Scaelfputs output a line to a stream 191*49264Scaelfread binary stream input/output 192*49264Scaelfreopen stream open functions 193*49264Scaelfropen open a stream 194*49264Scaelfscanf input format conversion 195*49264Scaelfseek reposition a stream 196*49264Scaelfsetpos reposition a stream 197*49264Scaelftell reposition a stream 198*49264Scaelfunopen open a stream 199*49264Scaelfwopen open a stream 200*49264Scaelfwrite binary stream input/output 201*49264Scaelgetc get next character or word from input stream 202*49264Scaelgetchar get next character or word from input stream 203*49264Scaelgets get a line from a stream 204*49264Scaelgetw get next character or word from input stream 205*49264Scaelmktemp make temporary file name (unique) 206*49264Scaelperror system error messages 207*49264Scaelprintf formatted output conversion 208*49264Scaelputc output a character or word to a stream 209*49264Scaelputchar output a character or word to a stream 210*49264Scaelputs output a line to a stream 211*49264Scaelputw output a character or word to a stream 212*49264Scaelremove remove directory entry 213*49264Scaelrewind reposition a stream 214*49264Scaelscanf input format conversion 215*49264Scaelsetbuf stream buffering operations 216*49264Scaelsetbuffer stream buffering operations 217*49264Scaelsetlinebuf stream buffering operations 218*49264Scaelsetvbuf stream buffering operations 219*49264Scaelsnprintf formatted output conversion 220*49264Scaelsprintf formatted output conversion 221*49264Scaelsscanf input format conversion 222*49264Scaelstrerror system error messages 223*49264Scaelsys_errlist system error messages 224*49264Scaelsys_nerr system error messages 225*49264Scaeltempnam temporary file routines 226*49264Scaeltmpfile temporary file routines 227*49264Scaeltmpnam temporary file routines 228*49264Scaelungetc un-get character from input stream 229*49264Scaelvfprintf formatted output conversion 230*49264Scaelvfscanf input format conversion 231*49264Scaelvprintf formatted output conversion 232*49264Scaelvscanf input format conversion 233*49264Scaelvsnprintf formatted output conversion 234*49264Scaelvsprintf formatted output conversion 235*49264Scaelvsscanf input format conversion 236*49264Scael.El 237