HP-UX Reference (11i v2 03/08) - 3 Library Functions A-M (vol 6)

g
getc(3S) getc(3S)
[EAGAIN] The O_NONBLOCK flag is set for the file descriptor underlying stream and the pro-
cess would be delayed in the read operation.
[EBADF] The file descriptor underlying stream is not a valid file descriptor open for reading.
[EINTR] The read operation was terminated due to the receipt of a signal, and either no data
was transferred or the implementation does not report partial transfer for this file.
[EIO] A physical I/O error has occurred, or the process is a member of a background pro-
cess and is attempting to read from its controlling terminal, and either the process
is ignoring or blocking the
SIGTTIN signal or the process group of the process is
orphaned.
Additional
errno values may be set by the underlying
read() function (see read(2)).
WARNINGS
getc() and getchar() are implemented both as library functions and macros. The macro versions,
which are used by default, are defined in
<stdio.h>. To obtain the library function either use a
#undef to remove the macro definition or, if compiling in ANSI-C mode, enclose the function name in
parenthesis or use the function address. The following example illustrates each of these methods :
#include <stdio.h>
#undef getc
...
main()
{
int (*get_char()) ();
...
return_val=getc(c,fd);
...
return_val=(getc)(c,fd1);
...
get_char = getchar;
};
If the integer value returned by getc(), getc_unlocked()
, getchar(), getchar_unlocked(),
or
fgetc() is stored into a character variable then compared against the integer constant EOF, the com-
parison may never succeed because sign-extension of a character on widening to integer is machine-
dependent.
The macro version of
getc() incorrectly treats a stream argument with side effects. In particular,
getc(*f++) does not work sensibly. The function version of getc() or fgetc() should be used
instead.
Because of possible differences in word length and byte ordering, files written using
putw() are
machine-dependent, and may be unreadable by
getw() on a different processor.
Reentrant Interfaces
If
_REENTRANT is defined before including <stdio.h>, the locked versions of the library functions for
getc() and getchar() are used by default.
getw_unlocked() is an obsolescent interface supported only for compatibility with existing DCE
applications. New multithreaded applications should use getw().
SEE ALSO
read(2), fclose(3S), ferror(3S), flockfile(3S), fopen(3S), fread(3S), gets(3S), putc(3S), scanf(3S), orienta-
tion(5), thread_safety(5).
STANDARDS CONFORMANCE
getc(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
getc_unlocked():POSIX.1C
fgetc(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, XPG4.2, FIPS 151-2, POSIX.1, ANSI C
getchar(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
getchar_unlocked():POSIX.1C
Section 3350 Hewlett-Packard Company 2 HP-UX 11i Version 2: August 2003