putc(3S) SDK R4.11 putc(3S)
NAME
putc, putcunlocked, putchar, putcharunlocked, fputc, putw - put
character or word on a stream
SYNOPSIS
#include <stdio.h>
int putc(int c, FILE *stream);
int putcunlocked(int c, FILE *stream);
int putchar(int c);
int putcharunlocked(int c);
int fputc(int c, FILE *stream);
int putw(int w, FILE *stream);
DESCRIPTION
putc and putcunlocked write c (converted to an unsigned char) onto
the output stream [see intro(3)] at the position where the file
pointer (if defined) is pointing, and advances the file pointer
appropriately. If the file cannot support positioning requests, or
stream was opened with append mode, the character is appended to the
output stream. putchar(c) is defined as putc(c, stdout).
putcunlocked and putcharunlocked provide unsynchronized character
I/O that require explicit synchronization around their use when
multiple threads are performing I/O. 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 putcunlocked and
stdout for putcharunlocked. Exclusive access is granted using the
flockfile or ftrylockfile functions.
fputc behaves like putc, but is a function rather than a macro.
fputc runs more slowly than putc, but it takes less space per
invocation and its name can be passed as an argument to a function.
putw writes the word (that is, integer) w to the output stream (where
the file pointer, if defined, is pointing). The size of a word is
the size of an integer and varies from machine to machine. putw
neither assumes nor causes special alignment in the file.
Errors
On success, these functions (with the exception of putw) each return
the value they have written. putw returns ferror (stream).
Otherwise, these functions return the constant EOF and set errno to
indicate the error. If a write error occurs, the error indicator for
the stream is also set. This result will occur, for example, if the
file stream is not open for writing or if the output file cannot
grow.
Considerations for Threads Programming
+-----------------+-----------------------------+
| | async- |
|function | reentrant cancel cancel |
| | point safe |
+-----------------+-----------------------------+
|fputc | Y Y N |
|putc | Y Y N |
|putcunlocked | N - - |
|putchar | Y Y N |
|putcharunlocked | N - - |
|putw | Y N N |
+-----------------+-----------------------------+
REFERENCES
exit(2), lseek(2), write(2), reentrant(3), abort(3C), flockfile(3C),
ftrylockfile(3C), fclose(3S), ferror(3S), fopen(3S), fread(3S),
printf(3S), puts(3S), setbuf(3S), stdio(3S)
NOTICES
Because it is implemented as a macro, putc evaluates a stream
argument more than once. In particular, putc(c, *f++); doesn't work
sensibly. fputc should be used instead.
Because of possible differences in word length and byte ordering,
files written using putw are machine-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
putc).
Licensed material--property of copyright holder(s)