xref: /csrg-svn/lib/libc/stdio/stdio.3 (revision 64897)
161180Sbostic.\" Copyright (c) 1990, 1991, 1993
261180Sbostic.\"	The Regents of the University of California.  All rights reserved.
320455Smckusick.\"
449264Scael.\" %sccs.include.redist.man%
520455Smckusick.\"
6*64897Sbostic.\"     @(#)stdio.3	8.2 (Berkeley) 11/16/93
749264Scael.\"
849264Scael.Dd
949264Scael.Dt STDIO 3
1049264Scael.Os BSD 4
1149264Scael.Sh NAME
1249264Scael.Nm stdio
1349264Scael.Nd standard input/output library functions
1449264Scael.Sh SYNOPSIS
1549264Scael.Fd #include <stdio.h>
1649264Scael.Fd FILE *stdin;
1749264Scael.Fd FILE *stdout;
1849264Scael.Fd FILE *stderr;
1949264Scael.Sh DESCRIPTION
2049264ScaelThe standard
2149264Scael.Tn I/O
2249264Scaellibrary provides a simple and efficient buffered stream
2349264Scael.Tn I/O
2449264Scaelinterface.
2549264ScaelInput and ouput is mapped into logical data streams
2649264Scaeland the physical
2749264Scael.Tn I/O
2849264Scaelcharacteristics are concealed. The functions and macros are listed
2949264Scaelbelow; more information is available from the individual man pages.
3049264Scael.Pp
3149264ScaelA stream is associated with an external file (which may be a physical
3249264Scaeldevice) by
3349264Scael.Em opening
3449264Scaela file, which may involve creating a new file. Creating an
3549264Scaelexisting file causes its former contents to be discarded.
3649264ScaelIf a file can support positioning requests (such as a disk file, as opposed
3749264Scaelto a terminal) then a
3849264Scael.Em file position indicator
3949264Scaelassociated with the stream is positioned at the start of the file (byte
4049264Scaelzero), unless the file is opened with appened mode. If append mode
4149264Scaelis used, the position indicator will be placed the end-of-file.
4249264ScaelThe position indicator is maintained by subsequent reads, writes
4349264Scaeland positioning requests. All input occurs as if the characters
4449264Scaelwere read by successive calls to the
4549264Scael.Xr fgetc 3
4649264Scaelfunction; all ouput takes place as if all characters were
4749264Scaelread by successive calls to the
4849264Scael.Xr fputc 3
4949264Scaelfunction.
5049264Scael.Pp
5149264ScaelA file is disassociated from a stream by
5249264Scael.Em closing
5349264Scaelthe file.
5449264ScaelOuput streams are flushed (any unwritten buffer contents are transfered
5549264Scaelto the host environment) before the stream is disassociated from the file.
5649264ScaelThe value of a pointer to a
5749264Scael.Dv FILE
5849264Scaelobject is indeterminate after a file is closed (garbage).
5949264Scael.Pp
6049264ScaelA file may be subsequently reopened, by the same or another program
6149264Scaelexecution, and its contents reclaimed or modified (if it can be repositioned
6249264Scaelat the start).  If the main function returns to its original caller, or
6349264Scaelthe
6449264Scael.Xr exit 3
6549264Scaelfunction is called, all open files are closed (hence all output
6649264Scaelstreams are flushed) before program termination.  Other methods
6749264Scaelof program termination, such as
6849264Scael.Xr abort 3
6949264Scaeldo not bother about closing files properly.
7049264Scael.Pp
7149264ScaelAt program startup, three text streams are predefined and need not be
7249264Scaelopened explicitly
7349264Scael\(em
7449264Scael.Em standard input
7549264Scael(for reading converntional input),
7649264Scael\(em
7749264Scael.Em standard output
7849264Scael(for writing converntional input),
7920455Smckusickand
8049264Scael.Em standard error
8149264Scael(for writing diagnostic output).
8249264ScaelThese streams are abbreviated
8349264Scael.Em stdin , stdout
8420455Smckusickand
8549264Scael.Em stderr .
8649264ScaelWhen opened, the standard error stream
8749264Scaelis not fully buffered; the standard input and output streams are
8849264Scaelfully buffered if and only if the streams do not to refer to
8949264Scaelan interactive device.
9049264Scael.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
9749264Scael.Xr fflush 3
9846106Sbosticthe standard output before going off and computing so that the output
9946106Sbosticwill appear.
10049264Scael.Pp
10149264ScaelThe
10249264Scael.Nm stdio
10349264Scaellibrary is a part of the library
10449264Scael.Xr libc
10549264Scaeland routines are automatically loaded as needed by the compilers
10649264Scael.Xr cc 1
10749264Scaeland
10849264Scael.Xr pc 1 .
10949264ScaelThe
11049264Scael.Tn SYNOPSIS
11149264Scaelsections of the following manual pages indicate which include files
11249264Scaelare to be used, what the compiler declaration for the function
11349264Scaellooks like and which external variables are of interest.
11449264Scael.Pp
11549264ScaelThe following are defined as macros;
11649264Scaelthese names may not be re-used
11749264Scaelwithout first removing their current definitions with
11849264Scael.Dv #undef :
11949264Scael.Dv BUFSIZ ,
12049264Scael.Dv EOF ,
12149264Scael.Dv FILENAME_MAX ,
12249264Scael.DV FOPEN_MAX ,
12349264Scael.Dv L_cuserid ,
12449264Scael.Dv L_ctermid ,
12549264Scael.Dv L_tmpnam,
12649264Scael.Dv NULL ,
12749264Scael.Dv SEEK_END ,
12849264Scael.Dv SEEK_SET ,
12949264Scael.Dv SEE_CUR ,
13049264Scael.Dv TMP_MAX ,
13149264Scael.Dv clearerr ,
13249264Scael.Dv feof ,
13349264Scael.Dv ferror ,
13449264Scael.Dv fileno ,
13549264Scael.Dv fropen ,
13649264Scael.Dv fwopen ,
13749264Scael.Dv getc ,
13849264Scael.Dv getchar ,
13949264Scael.Dv putc ,
14049264Scael.Dv putchar ,
14149264Scael.Dv stderr ,
14249264Scael.Dv stdin ,
14349264Scael.Dv stdout .
14449264ScaelFunction versions of the macro functions
14549264Scael.Xr feof ,
14649264Scael.Xr ferror ,
14749264Scael.Xr clearerr ,
14849264Scael.Xr fileno ,
14949264Scael.Xr getc ,
15049264Scael.Xr getchar ,
15149264Scael.Xr putc ,
15249264Scaeland
15349264Scael.Xr putchar
15449264Scaelexist and will be used if the macros
15549264Scaeldefinitions are explicitly removed.
15649264Scael.Sh SEE ALSO
15749264Scael.Xr open 2 ,
15849264Scael.Xr close 2 ,
15949264Scael.Xr read 2 ,
16049264Scael.Xr write 2
16149264Scael.Sh BUGS
16220456SmckusickThe standard buffered functions do not interact well with certain other
16349264Scaellibrary and system functions, especially
16449264Scael.Xr vfork
16549264Scaeland
16649264Scael.Xr abort .
16749264Scael.Sh STANDARDS
16849264ScaelThe
16949264Scael.Nm stdio
17049264Scaellibrary conforms to
17149264Scael.St -ansiC .
17249264Scael.Sh LIST OF FUNCTIONS
17349264Scael.Bl -column "Description"
17449264Scael.Sy Function	Description
17549264Scaelclearerr	check and reset stream status
17649264Scaelfclose	close a stream
17749264Scaelfdopen	stream open functions
17849264Scaelfeof	check and reset stream status
17949264Scaelferror	check and reset stream status
18049264Scaelfflush	flush a stream
18149264Scaelfgetc	get next character or word from input stream
18249264Scaelfgetline	get a line from a stream
18349264Scaelfgetpos	reposition a stream
18449264Scaelfgets	get a line from a stream
18549264Scaelfileno	check and reset stream status
18649264Scaelfopen	stream open functions
18749264Scaelfprintf	formatted output conversion
18849264Scaelfpurge	flush a stream
18949264Scaelfputc	output a character or word to a stream
19049264Scaelfputs	output a line to a stream
19149264Scaelfread	binary stream input/output
19249264Scaelfreopen	stream open functions
19349264Scaelfropen	open a stream
19449264Scaelfscanf	input format conversion
19549264Scaelfseek	reposition a stream
19649264Scaelfsetpos	reposition a stream
19749264Scaelftell	reposition a stream
19849264Scaelfunopen	open a stream
19949264Scaelfwopen	open a stream
20049264Scaelfwrite	binary stream input/output
20149264Scaelgetc	get next character or word from input stream
20249264Scaelgetchar	get next character or word from input stream
20349264Scaelgets	get a line from a stream
20449264Scaelgetw	get next character or word from input stream
205*64897Sbosticmkstemp	create unique temporary file
206*64897Sbosticmktemp	create unique temporary file
20749264Scaelperror	system error messages
20849264Scaelprintf	formatted output conversion
20949264Scaelputc	output a character or word to a stream
21049264Scaelputchar	output a character or word to a stream
21149264Scaelputs	output a line to a stream
21249264Scaelputw	output a character or word to a stream
21349264Scaelremove	remove directory entry
21449264Scaelrewind	reposition a stream
21549264Scaelscanf	input format conversion
21649264Scaelsetbuf	stream buffering operations
21749264Scaelsetbuffer	stream buffering operations
21849264Scaelsetlinebuf	stream buffering operations
21949264Scaelsetvbuf	stream buffering operations
22049264Scaelsnprintf	formatted output conversion
22149264Scaelsprintf	formatted output conversion
22249264Scaelsscanf	input format conversion
22349264Scaelstrerror	system error messages
22449264Scaelsys_errlist	system error messages
22549264Scaelsys_nerr	system error messages
22649264Scaeltempnam	temporary file routines
22749264Scaeltmpfile	temporary file routines
22849264Scaeltmpnam	temporary file routines
22949264Scaelungetc	un-get character from input stream
23049264Scaelvfprintf	formatted output conversion
23149264Scaelvfscanf	input format conversion
23249264Scaelvprintf	formatted output conversion
23349264Scaelvscanf	input format conversion
23449264Scaelvsnprintf	formatted output conversion
23549264Scaelvsprintf	formatted output conversion
23649264Scaelvsscanf	input format conversion
23749264Scael.El
238