.\" Copyright (c) 1990 Regents of the University of California. .\" All rights reserved. The Berkeley software License Agreement .\" specifies the terms and conditions for redistribution. .\" .\" @(#)stdio.3 6.3 (Berkeley) 01/20/91 .\" .TH STDIO 3 "" .UC 4 .SH NAME stdio \- standard buffered input/output package .SH SYNOPSIS .B #include .PP .SM .B FILE .B *stdin; .br .SM .B FILE .B *stdout; .br .SM .B FILE .B *stderr; .SH DESCRIPTION The functions described here constitute a user-level buffering scheme. The in-line macros .IR getc (3) and .IR putc (3) handle characters quickly. The higher level routines in .I stdio all use .I getc and .IR putc ; they can be freely intermixed. .PP A file with associated buffering is called a .IR stream , and is declared to be a pointer to a defined type .SM .BR FILE . .IR Fopen (3) and .IR funopen (3) create certain descriptive data for a stream and return a pointer to designate the stream in all further transactions. There are three normally open streams with constant pointers declared in the include file and associated with the standard open files: .TP 10n .B stdin standard input file .br .ns .TP .B stdout standard output file .br .ns .TP .B stderr standard error file .PP A constant `pointer' .SM .B NULL (0) designates no stream at all. .PP An integer constant .SM .B EOF (\-1) is returned upon end of file or error by integer functions that deal with streams. .PP Any routine that uses the standard input/output package must include the header file .RI < stdio.h > . The constants and functions listed here are declared in the include file and need no further declaration. The following are implemented as macros; these names may not be reused without first removing their current definitions with .BR #undef : .IR NULL , .IR BUFSIZ , .IR EOF , .IR FOPEN_MAX , .IR FILENAME_MAX , .IR L_tmpnam , .IR SEEK_SET , .IR SEE_CUR , .IR SEEK_END , .IR TMP_MAX , .IR stdin , .IR stdout , .IR stderr , .IR fropen , .IR fwopen , .IR feof , .IR ferror , .IR clearerr , .IR fileno , .IR getc , .IR getchar , .IR putc , .IR putchar , .IR L_cuserid . Function versions of the macro functions .IR feof , .IR ferror , .IR clearerr , .IR fileno , .IR getc , .IR getchar , .IR putc , and .I putchar exist and will be used if the macros definitions are explicitly removed. .PP Output streams that refer to terminal devices are always line buffered by default; pending output to such streams is written automatically whenever an input stream that refers to a terminal device is read. In cases where a large amount of computation is done after printing part of a line on an output terminal, it is necessary to .IR fflush (3) the standard output before going off and computing so that the output will appear. .SH "SEE ALSO" open(2), close(2), read(2), write(2) .br all of the manuals listed below .SH "RETURN VALUE" The value .SM .B EOF is returned uniformly to indicate that a .SM .B FILE pointer has not been initialized with .IR fopen , input (output) has been attempted on an output (input) stream, or a .SM .B FILE pointer designates corrupt or otherwise unintelligible .SM .B FILE data. .SH BUGS The standard buffered functions do not interact well with certain other library and system functions, especially \fIvfork\fP and \fIabort\fP. .SH "LIST OF FUNCTIONS" .sp 2 .nf .ta \w'setlinebuf'u+2n +\w'setvbuf.3'u+10n \fIName\fP \fIAppears on Page\fP \fIDescription\fP .ta \w'setlinebuf'u+4n +\w'setvbuf.3'u+4n .sp 5p clearerr ferror.3 stream status inquiries fclose fclose.3 close a stream fdopen fopen.3 open a stream feof ferror.3 stream status inquiries ferror ferror.3 stream status inquiries fflush fflush.3 flush a stream fgetc getc.3 get a character or word from a stream fgetline fgetline.3 get a line from a stream fgetpos fseek.3 reposition a stream fgets fgets.3 get a line from a stream fileno ferror.3 stream status inquiries fmemopen fmemopen.3 open a block of memory as a stream fopen fopen.3 open a stream fprintf printf.3 formatted output conversion fpurge fpurge.3 discard buffered stream data fputc putc.3 put a character or word to a stream fputs fputs.3 put a line to a stream fread fread.3 stream binary input/output freopen fopen.3 open a stream fscanf scanf.3 formatted input conversion fseek fseek.3 reposition a stream fsetpos fseek.3 reposition a stream ftell fseek.3 reposition a stream funopen fopen.3 open a stream fwrite fread.3 stream binary input/output getc getc.3 get a character or word from a stream getchar getc.3 get a character or word from a stream gets fgets.3 get a line from a stream getw getc.3 get a character or word from a stream printf printf.3 formatted output conversion putc putc.3 put a character or word to a stream putchar putc.3 put a character or word to a stream puts fputs.3 put a line to a stream putw putc.3 put a character or word to a stream remove remove.3 remove a file xxx rewind fseek.3 reposition a stream scanf scanf.3 formatted input conversion setbuf setvbuf.3 assign buffering to a stream setbuffer setvbuf.3 assign buffering to a stream setlinebuf setvbuf.3 assign buffering to a stream setvbuf setvbuf.3 assign buffering to a stream .\" smprintf printf.3 formatted output conversion snprintf printf.3 formatted output conversion sprintf printf.3 formatted output conversion tmpfile xxx.3 xxx tmpnam xxx.3 xxx ungetc ungetc.3 push character back into input stream vfprintf printf.3 formatted output conversion vprintf printf.3 formatted output conversion .\" vsmprintf printf.3 formatted output conversion vsnprintf printf.3 formatted output conversion vsprintf printf.3 formatted output conversion .fi .sp 2 Although these have nothing to do with `standard I/O', the following declarations also appear in .RI < stdio.h > as required by ANSI X3.159-1989 and IEEE 1003.2 standards: .sp .nf .ta \w'setlinebuf'u+2n +\w'setvbuf.3'u+10n \fIName\fP \fIAppears on Page\fP \fIDescription\fP .ta \w'setlinebuf'u+4n +\w'setvbuf.3'u+4n .sp 5p cuserid cuserid.3 xxx getlogin getlogin.3 get login name pclose popen.3 initiate I/O to/from a process perror strerror.3 xxx popen popen.3 initiate I/O to/from a process remove remove.3 xxx rename rename.2 xxx .fi