2 * Copyright (c) 2002-2004 Tim J. Robbins.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 <<fputwc>>, <<putwc>>, <<fputwc_unlocked>>, <<putwc_unlocked>>---write a wide character on a stream or file
51 wint_t fputwc(wchar_t <[wc]>, FILE *<[fp]>);
56 wint_t fputwc_unlocked(wchar_t <[wc]>, FILE *<[fp]>);
60 wint_t _fputwc_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>);
64 wint_t _fputwc_unlocked_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>);
68 wint_t putwc(wchar_t <[wc]>, FILE *<[fp]>);
73 wint_t putwc_unlocked(wchar_t <[wc]>, FILE *<[fp]>);
77 wint_t _putwc_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>);
81 wint_t _putwc_unlocked_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>);
84 <<fputwc>> writes the wide character argument <[wc]> to the file or
85 stream identified by <[fp]>.
87 If the file was opened with append mode (or if the stream cannot
88 support positioning), then the new wide character goes at the end of the
89 file or stream. Otherwise, the new wide character is written at the
90 current value of the position indicator, and the position indicator
93 <<fputwc_unlocked>> is a non-thread-safe version of <<fputwc>>.
94 <<fputwc_unlocked>> may only safely be used within a scope
95 protected by flockfile() (or ftrylockfile()) and funlockfile(). This
96 function may safely be used in a multi-threaded program if and only
97 if they are called while the invoking thread owns the (FILE *)
98 object, as is the case after a successful call to the flockfile() or
99 ftrylockfile() functions. If threads are disabled, then
100 <<fputwc_unlocked>> is equivalent to <<fputwc>>.
102 The <<putwc>> and <<putwc_unlocked>> functions or macros function identically
103 to <<fputwc>> and <<fputwc_unlocked>>. They may be implemented as a macro, and
104 may evaluate its argument more than once. There is no reason ever to use them.
106 The <<_fputwc_r>>, <<_putwc_r>>, <<_fputwc_unlocked_r>>, and
107 <<_putwc_unlocked_r>> functions are simply reentrant versions of the above
108 that take an additional reentrant structure argument: <[ptr]>.
111 If successful, <<fputwc>> and <<putwc>> return their argument <[wc]>.
112 If an error intervenes, the result is <<EOF>>. You can use
113 `<<ferror(<[fp]>)>>' to query for errors.
116 <<fputwc>> and <<putwc>> are required by C99 and POSIX.1-2001.
118 <<fputwc_unlocked>> and <<putwc_unlocked>> are GNU extensions.
131 __fputwc (struct _reent
*ptr
,
135 char buf
[MB_LEN_MAX
];
138 if (MB_CUR_MAX
== 1 && wc
> 0 && wc
<= UCHAR_MAX
)
141 * Assume single-byte locale with no special encoding.
142 * A more careful test would be to check
143 * _CurrentRuneLocale->encoding.
145 *buf
= (unsigned char)wc
;
150 if ((len
= _wcrtomb_r (ptr
, buf
, wc
, &fp
->_mbstate
)) == (size_t) -1)
152 fp
->_flags
|= __SERR
;
157 for (i
= 0; i
< len
; i
++)
158 if (__swputc_r (ptr
, (unsigned char) buf
[i
], fp
) == EOF
)
165 _fputwc_r (struct _reent
*ptr
,
171 _newlib_flockfile_start (fp
);
172 r
= __fputwc(ptr
, wc
, fp
);
173 _newlib_flockfile_end (fp
);
181 struct _reent
*reent
= _REENT
;
183 CHECK_INIT(reent
, fp
);
186 _newlib_flockfile_start (fp
);
187 r
= __fputwc(reent
, wc
, fp
);
188 _newlib_flockfile_end (fp
);