getc_unlocked(), getchar_unlocked(), putc_unlocked(), putchar_unlocked() — Stdio with explicit client locking
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
Single UNIX Specification, Version 3 |
both | z/OS V1R8 |
Format
#define _UNIX03_SOURCE
#include <stdio.h>
int getc_unlocked(FILE *stream);
int getchar_unlocked(void);
int putc_unlocked(int c, FILE *stream);
int putchar_unlocked(int c);
General description
Versions of the functions getc(), getchar(), putc(), and putchar() respectively named getc_unlocked(), getchar_unlocked(), putc_unlocked(), and putchar_unlocked() are functionally equivalent to the original versions, with the exception that they are not thread-safe. 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.
getc_unlocked, getchar_unlocked, putc_unlocked, putchar_unlocked are provided in a highly efficient macro form. For performance purposes, it is recommended that the macro forms be used rather than the functional forms. By default, stdio.h provides the macro versions of these functions.
- Surround the call statement by parentheses, for example, (getc_unlocked)
- Specify #undef, for example, #undef getc_unlocked
- For C only: do not include stdio.h.
getc_unlocked, getchar_unlocked, putc_unlocked, putchar_unlocked are not supported for files that are opened with type=record or type=blocked.
Returned value
See getc(), getchar() — Read a character and putc(), putchar() — Write a character.