Next: getdelim, Previous: getchar, Up: Stdio

### 4.35 `getchar_unlocked`—non-thread-safe version of getchar (macro)

Synopsis

         #include <stdio.h>
         int getchar_unlocked();

         #include <stdio.h>
         int _getchar_unlocked_r(struct _reent *ptr);

Description
`getchar_unlocked` is a non-thread-safe version of `getchar` declared in `stdio.h`. `getchar_unlocked` may only safely be used within a scope protected by flockfile() (or ftrylockfile()) and funlockfile(). These functions may safely be used in a multi-threaded program if and only if they are called while the invoking thread owns the ( FILE *) object, as is the case after a successful call to the flockfile() or ftrylockfile() functions. If threads are disabled, then `getchar_unlocked` is equivalent to `getchar`.

The `_getchar_unlocked_r` function is simply the reentrant version of `getchar_unlocked` which passes an addtional reentrancy structure pointer argument: ptr.

Returns
See `getchar`.

Portability
POSIX 1003.1 requires `getchar_unlocked`. `getchar_unlocked` may be implemented as a macro.

Supporting OS subroutines required: `close`, `fstat`, `isatty`, `lseek`, `read`, `sbrk`, `write`.