2 * Copyright (c) 1990 The Regents of the University of California.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * and/or other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 <<fputc>>, <<fputc_unlocked>>---write a character on a stream or file
33 int fputc(int <[ch]>, FILE *<[fp]>);
37 int fputc_unlocked(int <[ch]>, FILE *<[fp]>);
40 int _fputc_r(struct _rent *<[ptr]>, int <[ch]>, FILE *<[fp]>);
43 int _fputc_unlocked_r(struct _rent *<[ptr]>, int <[ch]>, FILE *<[fp]>);
46 <<fputc>> converts the argument <[ch]> from an <<int>> to an
47 <<unsigned char>>, then writes it to the file or stream identified by
50 If the file was opened with append mode (or if the stream cannot
51 support positioning), then the new character goes at the end of the
52 file or stream. Otherwise, the new character is written at the
53 current value of the position indicator, and the position indicator
56 For a macro version of this function, see <<putc>>.
58 <<fputc_unlocked>> is a non-thread-safe version of <<fputc>>.
59 <<fputc_unlocked>> may only safely be used within a scope
60 protected by flockfile() (or ftrylockfile()) and funlockfile(). This
61 function may safely be used in a multi-threaded program if and only
62 if they are called while the invoking thread owns the (FILE *)
63 object, as is the case after a successful call to the flockfile() or
64 ftrylockfile() functions. If threads are disabled, then
65 <<fputc_unlocked>> is equivalent to <<fputc>>.
67 The <<_fputc_r>> and <<_fputc_unlocked_r>> functions are simply reentrant
68 versions of the above that take an additional reentrant structure
72 If successful, <<fputc>> returns its argument <[ch]>. If an error
73 intervenes, the result is <<EOF>>. You can use `<<ferror(<[fp]>)>>' to
77 <<fputc>> is required by ANSI C.
79 <<fputc_unlocked>> is a BSD extension also provided by GNU libc.
81 Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
82 <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
90 _fputc_r (struct _reent
*ptr
,
95 CHECK_INIT(ptr
, file
);
96 _newlib_flockfile_start (file
);
97 result
= _putc_r (ptr
, ch
, file
);
98 _newlib_flockfile_end (file
);
107 #if !defined(__OPTIMIZE_SIZE__) && !defined(PREFER_SIZE_OVER_SPEED)
109 struct _reent
*reent
= _REENT
;
111 CHECK_INIT(reent
, file
);
112 _newlib_flockfile_start (file
);
113 result
= _putc_r (reent
, ch
, file
);
114 _newlib_flockfile_end (file
);
117 return _fputc_r (_REENT
, ch
, file
);
120 #endif /* !_REENT_ONLY */