#include <stdio.h>int getc(FILE *stream);
int getc_unlocked(FILE *stream);
int getchar(void);
int getchar_unlocked(void);
int fgetc(FILE *stream);
int getw(FILE *stream);
getc_unlocked and getchar_unlocked provide unsynchronized character I/O that require explicit synchronization around their use when multiple threads are performing I/O. These two are defined as macros when cc(1) is invoked with -Kthread. getchar_unlocked is defined as getc_unlocked(stdin). They may be used safely in a multi-threaded application if and only if they are called while the calling thread has exclusive access to stream for getc_unlocked and stdin for getchar_unlocked. Exclusive access is granted using the lockfile or ftrylockfile functions.
fgetc behaves like getc, but is a function rather than a macro. fgetc runs more slowly than getc, but it takes less space per invocation and its name can be passed as an argument to a function.
getw returns the next word (that is, integer) from the named input stream. getw increments the associated file pointer, if defined, to point to the next word. The size of a word is the size of an integer and varies from machine to machine. getw assumes no special alignment in the file.
EOF
, the EOF
indicator for the
stream is set and getc and getc_unlocked return EOF
.
If a read error occurs, the error indicator for the stream is set,
getc and getc_unlocked return EOF
and set
errno to identify the error.
Under the following conditions, the functions getc, getchar, fgetc and getw fail and set errno to:
EOF
, the comparison may never succeed, because sign-extension
of a character on widening to integer is implementation dependent.
The macro version of getc evaluates a stream argument more than once and may treat side effects incorrectly. In particular, getc(*f++) does not work sensibly. Use fgetc instead.
Because of possible differences in word length and byte ordering, files written using putw are implementation dependent, and may not be read using getw on a different processor.
Functions exist for all the above-defined macros. To get the function form, the macro name must be undefined (for example, #undef getc).