1.\" $NetBSD: getc.3,v 1.12 2003/08/07 16:43:26 agc Exp $ 2.\" 3.\" Copyright (c) 1990, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" This code is derived from software contributed to Berkeley by 7.\" Chris Torek and the American National Standards Committee X3, 8.\" on Information Processing Systems. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 13.\" 1. Redistributions of source code must retain the above copyright 14.\" notice, this list of conditions and the following disclaimer. 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in the 17.\" documentation and/or other materials provided with the distribution. 18.\" 3. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.\" @(#)getc.3 8.1 (Berkeley) 6/4/93 35.\" 36.Dd April 25, 2001 37.Dt GETC 3 38.Os 39.Sh NAME 40.Nm fgetc , 41.Nm getc , 42.Nm getchar , 43.Nm getc_unlocked , 44.Nm getchar_unlocked , 45.Nm getw 46.Nd get next character or word from input stream 47.Sh LIBRARY 48.Lb libc 49.Sh SYNOPSIS 50.In stdio.h 51.Ft int 52.Fn fgetc "FILE *stream" 53.Ft int 54.Fn getc "FILE *stream" 55.Ft int 56.Fn getchar 57.Ft int 58.Fn getc_unlocked "FILE *stream" 59.Ft int 60.Fn getchar_unlocked 61.Ft int 62.Fn getw "FILE *stream" 63.Sh DESCRIPTION 64The 65.Fn fgetc 66function 67obtains the next input character (if present) from the stream pointed at by 68.Fa stream , 69or the next character pushed back on the stream via 70.Xr ungetc 3 . 71.Pp 72The 73.Fn getc 74function 75acts essentially identically to 76.Fn fgetc , 77but is a macro that expands in-line. 78.Pp 79The 80.Fn getchar 81function 82is equivalent to: 83getc with the argument stdin. 84.Pp 85The 86.Fn getc_unlocked 87and 88.Fn getchar_unlocked 89functions provide functionality identical to that of 90.Fn getc 91and 92.Fn getchar , 93respectively, but do not perform implicit locking of the streams they 94operate on. 95In multi-threaded programs they may be used 96.Em only 97within a scope in which the stream 98has been successfully locked by the calling thread using either 99.Xr flockfile 3 100or 101.Xr ftrylockfile 3 , 102and may later be released using 103.Xr funlockfile 3 . 104.Pp 105The 106.Fn getw 107function 108obtains the next 109.Em int 110(if present) 111from the stream pointed at by 112.Fa stream . 113.Sh RETURN VALUES 114If successful, these routines return the next requested object 115from the 116.Fa stream . 117If the stream is at end-of-file or a read error occurs, 118the routines return 119.Dv EOF . 120The routines 121.Xr feof 3 122and 123.Xr ferror 3 124must be used to distinguish between end-of-file and error. 125If an error occurs, the global variable 126.Va errno 127is set to indicate the error. 128The end-of-file condition is remembered, even on a terminal, and all 129subsequent attempts to read will return 130.Dv EOF 131until the condition is cleared with 132.Xr clearerr 3 . 133.Sh SEE ALSO 134.Xr ferror 3 , 135.Xr flockfile 3 , 136.Xr fopen 3 , 137.Xr fread 3 , 138.Xr ftrylockfile 3 , 139.Xr funlockfile 3 , 140.Xr putc 3 , 141.Xr ungetc 3 142.Sh STANDARDS 143The 144.Fn fgetc , 145.Fn getc 146and 147.Fn getchar 148functions 149conform to 150.St -ansiC . 151The 152.Fn getc_unlocked 153and 154.Fn getchar_unlocked 155functions conform to 156.St -p1003.1-96 . 157.Sh BUGS 158Since 159.Dv EOF 160is a valid integer value, 161.Xr feof 3 162and 163.Xr ferror 3 164must be used to check for failure after calling 165.Fn getw . 166The size and byte order of an 167.Em int 168varies from one machine to another, and 169.Fn getw 170is not recommended for portable applications. 171