Rev 4921 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4349 | Serge | 1 | /*- |
2 | * Copyright (c) 2002-2004 Tim J. Robbins. |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
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. |
||
13 | * |
||
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 |
||
24 | * SUCH DAMAGE. |
||
25 | */ |
||
26 | |||
27 | /* |
||
28 | FUNCTION |
||
6099 | serge | 29 | < |
4349 | Serge | 30 | |
31 | INDEX |
||
32 | fputwc |
||
33 | INDEX |
||
6099 | serge | 34 | fputwc_unlocked |
35 | INDEX |
||
4349 | Serge | 36 | _fputwc_r |
37 | INDEX |
||
6099 | serge | 38 | _fputwc_unlocked_r |
39 | INDEX |
||
4349 | Serge | 40 | putwc |
41 | INDEX |
||
6099 | serge | 42 | putwc_unlocked |
43 | INDEX |
||
4349 | Serge | 44 | _putwc_r |
6099 | serge | 45 | INDEX |
46 | _putwc_unlocked_r |
||
4349 | Serge | 47 | |
48 | ANSI_SYNOPSIS |
||
49 | #include |
||
50 | #include |
||
51 | wint_t fputwc(wchar_t <[wc]>, FILE *<[fp]>); |
||
52 | |||
6099 | serge | 53 | #define _GNU_SOURCE |
4349 | Serge | 54 | #include |
55 | #include |
||
6099 | serge | 56 | wint_t fputwc_unlocked(wchar_t <[wc]>, FILE *<[fp]>); |
57 | |||
58 | #include |
||
59 | #include |
||
4349 | Serge | 60 | wint_t _fputwc_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>); |
61 | |||
62 | #include |
||
63 | #include |
||
6099 | serge | 64 | wint_t _fputwc_unlocked_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>); |
65 | |||
66 | #include |
||
67 | #include |
||
4349 | Serge | 68 | wint_t putwc(wchar_t <[wc]>, FILE *<[fp]>); |
69 | |||
6099 | serge | 70 | #define _GNU_SOURCE |
4349 | Serge | 71 | #include |
72 | #include |
||
6099 | serge | 73 | wint_t putwc_unlocked(wchar_t <[wc]>, FILE *<[fp]>); |
74 | |||
75 | #include |
||
76 | #include |
||
4349 | Serge | 77 | wint_t _putwc_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>); |
78 | |||
6099 | serge | 79 | #include |
80 | #include |
||
81 | wint_t _putwc_unlocked_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>); |
||
82 | |||
4349 | Serge | 83 | TRAD_SYNOPSIS |
84 | #include |
||
85 | #include |
||
86 | wint_t fputwc(<[wc]>, <[fp]>) |
||
87 | wchar_t <[wc]>; |
||
88 | FILE *<[fp]>; |
||
89 | |||
6099 | serge | 90 | #define _GNU_SOURCE |
4349 | Serge | 91 | #include |
92 | #include |
||
6099 | serge | 93 | wint_t fputwc_unlocked(<[wc]>, <[fp]>) |
94 | wchar_t <[wc]>; |
||
95 | FILE *<[fp]>; |
||
96 | |||
97 | #include |
||
98 | #include |
||
4349 | Serge | 99 | wint_t _fputwc_r(<[ptr]>, <[wc]>, <[fp]>) |
100 | struct _reent *<[ptr]>; |
||
101 | wchar_t <[wc]>; |
||
102 | FILE *<[fp]>; |
||
103 | |||
104 | #include |
||
105 | #include |
||
6099 | serge | 106 | wint_t _fputwc_unlocked_r(<[ptr]>, <[wc]>, <[fp]>) |
107 | struct _reent *<[ptr]>; |
||
108 | wchar_t <[wc]>; |
||
109 | FILE *<[fp]>; |
||
110 | |||
111 | #include |
||
112 | #include |
||
4349 | Serge | 113 | wint_t putwc(<[wc]>, <[fp]>) |
114 | wchar_t <[wc]>; |
||
115 | FILE *<[fp]>; |
||
116 | |||
6099 | serge | 117 | #define _GNU_SOURCE |
4349 | Serge | 118 | #include |
119 | #include |
||
6099 | serge | 120 | wint_t putwc_unlocked(<[wc]>, <[fp]>) |
121 | wchar_t <[wc]>; |
||
122 | FILE *<[fp]>; |
||
123 | |||
124 | #include |
||
125 | #include |
||
4349 | Serge | 126 | wint_t _putwc_r(<[ptr]>, <[wc]>, <[fp]>) |
127 | struct _reent *<[ptr]>; |
||
128 | wchar_t <[wc]>; |
||
129 | FILE *<[fp]>; |
||
130 | |||
6099 | serge | 131 | #include |
132 | #include |
||
133 | wint_t _putwc_unlocked_r(<[ptr]>, <[wc]>, <[fp]>) |
||
134 | struct _reent *<[ptr]>; |
||
135 | wchar_t <[wc]>; |
||
136 | FILE *<[fp]>; |
||
137 | |||
4349 | Serge | 138 | DESCRIPTION |
139 | < |
||
140 | stream identified by <[fp]>. |
||
141 | |||
142 | If the file was opened with append mode (or if the stream cannot |
||
143 | support positioning), then the new wide character goes at the end of the |
||
144 | file or stream. Otherwise, the new wide character is written at the |
||
145 | current value of the position indicator, and the position indicator |
||
146 | oadvances by one. |
||
147 | |||
6099 | serge | 148 | < |
149 | < |
||
150 | protected by flockfile() (or ftrylockfile()) and funlockfile(). This |
||
151 | function may safely be used in a multi-threaded program if and only |
||
152 | if they are called while the invoking thread owns the (FILE *) |
||
153 | object, as is the case after a successful call to the flockfile() or |
||
154 | ftrylockfile() functions. If threads are disabled, then |
||
155 | < |
||
4349 | Serge | 156 | |
6099 | serge | 157 | The < |
158 | to < |
||
159 | may evaluate its argument more than once. There is no reason ever to use them. |
||
4349 | Serge | 160 | |
6099 | serge | 161 | The <<_fputwc_r>>, <<_putwc_r>>, <<_fputwc_unlocked_r>>, and |
162 | <<_putwc_unlocked_r>> functions are simply reentrant versions of the above |
||
163 | that take an additional reentrant structure argument: <[ptr]>. |
||
164 | |||
4349 | Serge | 165 | RETURNS |
166 | If successful, < |
||
167 | If an error intervenes, the result is < |
||
168 | `< |
||
169 | |||
170 | PORTABILITY |
||
6099 | serge | 171 | < |
172 | |||
173 | < |
||
4349 | Serge | 174 | */ |
175 | |||
176 | #include <_ansi.h> |
||
177 | #include |
||
178 | #include |
||
179 | #include |
||
180 | #include |
||
181 | #include |
||
182 | #include |
||
183 | #include "local.h" |
||
184 | |||
6099 | serge | 185 | wint_t |
4349 | Serge | 186 | _DEFUN(__fputwc, (ptr, wc, fp), |
187 | struct _reent *ptr _AND |
||
188 | wchar_t wc _AND |
||
189 | FILE *fp) |
||
190 | { |
||
191 | char buf[MB_LEN_MAX]; |
||
192 | size_t i, len; |
||
193 | |||
194 | if (MB_CUR_MAX == 1 && wc > 0 && wc <= UCHAR_MAX) |
||
195 | { |
||
196 | /* |
||
197 | * Assume single-byte locale with no special encoding. |
||
198 | * A more careful test would be to check |
||
199 | * _CurrentRuneLocale->encoding. |
||
200 | */ |
||
201 | *buf = (unsigned char)wc; |
||
202 | len = 1; |
||
203 | } |
||
204 | else |
||
205 | { |
||
206 | if ((len = _wcrtomb_r (ptr, buf, wc, &fp->_mbstate)) == (size_t) -1) |
||
207 | { |
||
208 | fp->_flags |= __SERR; |
||
209 | return WEOF; |
||
210 | } |
||
211 | } |
||
212 | |||
213 | for (i = 0; i < len; i++) |
||
214 | if (__sputc_r (ptr, (unsigned char) buf[i], fp) == EOF) |
||
215 | return WEOF; |
||
216 | |||
217 | return (wint_t) wc; |
||
218 | } |
||
219 | |||
220 | wint_t |
||
221 | _DEFUN(_fputwc_r, (ptr, wc, fp), |
||
222 | struct _reent *ptr _AND |
||
223 | wchar_t wc _AND |
||
224 | FILE *fp) |
||
225 | { |
||
226 | wint_t r; |
||
227 | |||
4921 | Serge | 228 | _newlib_flockfile_start (fp); |
4349 | Serge | 229 | ORIENT(fp, 1); |
230 | r = __fputwc(ptr, wc, fp); |
||
4921 | Serge | 231 | _newlib_flockfile_end (fp); |
4349 | Serge | 232 | return r; |
233 | } |
||
234 | |||
235 | wint_t |
||
236 | _DEFUN(fputwc, (wc, fp), |
||
237 | wchar_t wc _AND |
||
238 | FILE *fp) |
||
239 | { |
||
4921 | Serge | 240 | struct _reent *reent = _REENT; |
241 | |||
242 | CHECK_INIT(reent, fp); |
||
243 | return _fputwc_r (reent, wc, fp); |
||
4349 | Serge | 244 | }>=> |