1*045ae074Ssevan.\" $NetBSD: getc.3,v 1.13 2019/09/02 00:30:58 sevan Exp $ 2389c46c5Sjtc.\" 3389c46c5Sjtc.\" Copyright (c) 1990, 1991, 1993 4389c46c5Sjtc.\" The Regents of the University of California. All rights reserved. 561f28255Scgd.\" 661f28255Scgd.\" This code is derived from software contributed to Berkeley by 761f28255Scgd.\" Chris Torek and the American National Standards Committee X3, 861f28255Scgd.\" on Information Processing Systems. 961f28255Scgd.\" 1061f28255Scgd.\" Redistribution and use in source and binary forms, with or without 1161f28255Scgd.\" modification, are permitted provided that the following conditions 1261f28255Scgd.\" are met: 1361f28255Scgd.\" 1. Redistributions of source code must retain the above copyright 1461f28255Scgd.\" notice, this list of conditions and the following disclaimer. 1561f28255Scgd.\" 2. Redistributions in binary form must reproduce the above copyright 1661f28255Scgd.\" notice, this list of conditions and the following disclaimer in the 1761f28255Scgd.\" documentation and/or other materials provided with the distribution. 18eb7c1594Sagc.\" 3. Neither the name of the University nor the names of its contributors 1961f28255Scgd.\" may be used to endorse or promote products derived from this software 2061f28255Scgd.\" without specific prior written permission. 2161f28255Scgd.\" 2261f28255Scgd.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2361f28255Scgd.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2461f28255Scgd.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2561f28255Scgd.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2661f28255Scgd.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2761f28255Scgd.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2861f28255Scgd.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2961f28255Scgd.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3061f28255Scgd.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3161f28255Scgd.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3261f28255Scgd.\" SUCH DAMAGE. 3361f28255Scgd.\" 34389c46c5Sjtc.\" @(#)getc.3 8.1 (Berkeley) 6/4/93 3561f28255Scgd.\" 36*045ae074Ssevan.Dd September 2, 2019 3761f28255Scgd.Dt GETC 3 3861f28255Scgd.Os 3961f28255Scgd.Sh NAME 4061f28255Scgd.Nm fgetc , 4161f28255Scgd.Nm getc , 4261f28255Scgd.Nm getchar , 436213f737Skleink.Nm getc_unlocked , 446213f737Skleink.Nm getchar_unlocked , 4561f28255Scgd.Nm getw 4661f28255Scgd.Nd get next character or word from input stream 47312aca53Sperry.Sh LIBRARY 48312aca53Sperry.Lb libc 4961f28255Scgd.Sh SYNOPSIS 50472351e1Swiz.In stdio.h 5161f28255Scgd.Ft int 5261f28255Scgd.Fn fgetc "FILE *stream" 5361f28255Scgd.Ft int 5461f28255Scgd.Fn getc "FILE *stream" 5561f28255Scgd.Ft int 5661f28255Scgd.Fn getchar 5761f28255Scgd.Ft int 586213f737Skleink.Fn getc_unlocked "FILE *stream" 596213f737Skleink.Ft int 606213f737Skleink.Fn getchar_unlocked 616213f737Skleink.Ft int 6261f28255Scgd.Fn getw "FILE *stream" 6361f28255Scgd.Sh DESCRIPTION 6461f28255ScgdThe 6561f28255Scgd.Fn fgetc 6661f28255Scgdfunction 6761f28255Scgdobtains the next input character (if present) from the stream pointed at by 6861f28255Scgd.Fa stream , 6961f28255Scgdor the next character pushed back on the stream via 708e1d7f3dSfair.Xr ungetc 3 . 7161f28255Scgd.Pp 7261f28255ScgdThe 7361f28255Scgd.Fn getc 7461f28255Scgdfunction 7561f28255Scgdacts essentially identically to 7661f28255Scgd.Fn fgetc , 7761f28255Scgdbut is a macro that expands in-line. 7861f28255Scgd.Pp 7961f28255ScgdThe 8061f28255Scgd.Fn getchar 8161f28255Scgdfunction 8261f28255Scgdis equivalent to: 8361f28255Scgdgetc with the argument stdin. 8461f28255Scgd.Pp 8561f28255ScgdThe 866213f737Skleink.Fn getc_unlocked 876213f737Skleinkand 886213f737Skleink.Fn getchar_unlocked 896213f737Skleinkfunctions provide functionality identical to that of 906213f737Skleink.Fn getc 916213f737Skleinkand 926213f737Skleink.Fn getchar , 936213f737Skleinkrespectively, but do not perform implicit locking of the streams they 946213f737Skleinkoperate on. 956213f737SkleinkIn multi-threaded programs they may be used 966213f737Skleink.Em only 976213f737Skleinkwithin a scope in which the stream 986213f737Skleinkhas been successfully locked by the calling thread using either 996213f737Skleink.Xr flockfile 3 1006213f737Skleinkor 1016213f737Skleink.Xr ftrylockfile 3 , 1026213f737Skleinkand may later be released using 1036213f737Skleink.Xr funlockfile 3 . 1046213f737Skleink.Pp 1056213f737SkleinkThe 10661f28255Scgd.Fn getw 10761f28255Scgdfunction 10861f28255Scgdobtains the next 10961f28255Scgd.Em int 11061f28255Scgd(if present) 11161f28255Scgdfrom the stream pointed at by 11261f28255Scgd.Fa stream . 11361f28255Scgd.Sh RETURN VALUES 11461f28255ScgdIf successful, these routines return the next requested object 11561f28255Scgdfrom the 11661f28255Scgd.Fa stream . 11761f28255ScgdIf the stream is at end-of-file or a read error occurs, 11861f28255Scgdthe routines return 11961f28255Scgd.Dv EOF . 12061f28255ScgdThe routines 12161f28255Scgd.Xr feof 3 12261f28255Scgdand 12361f28255Scgd.Xr ferror 3 12461f28255Scgdmust be used to distinguish between end-of-file and error. 12561f28255ScgdIf an error occurs, the global variable 12661f28255Scgd.Va errno 12761f28255Scgdis set to indicate the error. 12861f28255ScgdThe end-of-file condition is remembered, even on a terminal, and all 12961f28255Scgdsubsequent attempts to read will return 13061f28255Scgd.Dv EOF 13161f28255Scgduntil the condition is cleared with 1328e1d7f3dSfair.Xr clearerr 3 . 13361f28255Scgd.Sh SEE ALSO 13461f28255Scgd.Xr ferror 3 , 1355b62d84eSkleink.Xr flockfile 3 , 13661f28255Scgd.Xr fopen 3 , 13771bd158bSwiz.Xr fread 3 , 1385b62d84eSkleink.Xr ftrylockfile 3 , 1395b62d84eSkleink.Xr funlockfile 3 , 14061f28255Scgd.Xr putc 3 , 14161f28255Scgd.Xr ungetc 3 14261f28255Scgd.Sh STANDARDS 14361f28255ScgdThe 14461f28255Scgd.Fn fgetc , 14561f28255Scgd.Fn getc 14661f28255Scgdand 14761f28255Scgd.Fn getchar 14861f28255Scgdfunctions 14961f28255Scgdconform to 15061f28255Scgd.St -ansiC . 1516213f737SkleinkThe 1526213f737Skleink.Fn getc_unlocked 1536213f737Skleinkand 1546213f737Skleink.Fn getchar_unlocked 1556213f737Skleinkfunctions conform to 1566213f737Skleink.St -p1003.1-96 . 157*045ae074Ssevan.Sh HISTORY 158*045ae074SsevanThe 159*045ae074Ssevan.Fn getc 160*045ae074Ssevanand 161*045ae074Ssevan.Fn getw 162*045ae074Ssevanfunctions appeared in 163*045ae074Ssevan.At v1 . 16461f28255Scgd.Sh BUGS 16561f28255ScgdSince 16661f28255Scgd.Dv EOF 16761f28255Scgdis a valid integer value, 1688e1d7f3dSfair.Xr feof 3 16961f28255Scgdand 1708e1d7f3dSfair.Xr ferror 3 17161f28255Scgdmust be used to check for failure after calling 17261f28255Scgd.Fn getw . 17361f28255ScgdThe size and byte order of an 17461f28255Scgd.Em int 17561f28255Scgdvaries from one machine to another, and 17661f28255Scgd.Fn getw 17761f28255Scgdis not recommended for portable applications. 178