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>>---write a wide character on a stream or file
43 wint_t fputwc(wchar_t <[wc]>, FILE *<[fp]>);
47 wint_t _fputwc_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>);
51 wint_t putwc(wchar_t <[wc]>, FILE *<[fp]>);
55 wint_t _putwc_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>);
60 wint_t fputwc(<[wc]>, <[fp]>)
66 wint_t _fputwc_r(<[ptr]>, <[wc]>, <[fp]>)
67 struct _reent *<[ptr]>;
73 wint_t putwc(<[wc]>, <[fp]>)
79 wint_t _putwc_r(<[ptr]>, <[wc]>, <[fp]>)
80 struct _reent *<[ptr]>;
85 <<fputwc>> writes the wide character argument <[wc]> to the file or
86 stream identified by <[fp]>.
88 If the file was opened with append mode (or if the stream cannot
89 support positioning), then the new wide character goes at the end of the
90 file or stream. Otherwise, the new wide character is written at the
91 current value of the position indicator, and the position indicator
94 The <<putwc>> function or macro functions identically to <<fputwc>>. It
95 may be implemented as a macro, and may evaluate its argument more than
96 once. There is no reason ever to use it.
98 The <<_fputwc_r>> and <<_putwc_r>> functions are simply reentrant versions
99 of <<fputwc>> and <<putwc>> that take an additional reentrant structure
103 If successful, <<fputwc>> and <<putwc>> return their argument <[wc]>.
104 If an error intervenes, the result is <<EOF>>. You can use
105 `<<ferror(<[fp]>)>>' to query for errors.
121 _DEFUN(__fputwc, (ptr, wc, fp),
122 struct _reent *ptr _AND
126 char buf[MB_LEN_MAX];
129 if (MB_CUR_MAX == 1 && wc > 0 && wc <= UCHAR_MAX)
132 * Assume single-byte locale with no special encoding.
133 * A more careful test would be to check
134 * _CurrentRuneLocale->encoding.
136 *buf = (unsigned char)wc;
141 if ((len = _wcrtomb_r (ptr, buf, wc, &fp->_mbstate)) == (size_t) -1)
143 fp->_flags |= __SERR;
148 for (i = 0; i < len; i++)
149 if (__sputc_r (ptr, (unsigned char) buf[i], fp) == EOF)
156 _DEFUN(_fputwc_r, (ptr, wc, fp),
157 struct _reent *ptr _AND
165 r = __fputwc(ptr, wc, fp);
171 _DEFUN(fputwc, (wc, fp),
175 CHECK_INIT(_REENT, fp);
176 return _fputwc_r (_REENT, wc, fp);