1 /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
3 * GNU Library General Public License (LGPL) version 2 or later.
5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
11 #ifndef __UCLIBC_HAS_WCHAR__
12 #error wide function when no wide support!
15 size_t attribute_hidden
_wstdio_fwrite(const wchar_t *__restrict ws
, size_t n
,
16 register FILE *__restrict stream
)
22 __STDIO_STREAM_VALIDATE(stream
);
24 #ifdef __STDIO_BUFFERS
25 if (__STDIO_STREAM_IS_FAKE_VSWPRINTF(stream
)) {
26 /* We know buffer is wchar aligned for fake streams. */
27 count
= (((wchar_t *)(stream
->__bufend
))
28 - ((wchar_t *)(stream
->__bufpos
)));
33 wmemcpy((wchar_t *)(stream
->__bufpos
), ws
, count
);
34 stream
->__bufpos
= (unsigned char *)(((wchar_t *)(stream
->__bufpos
)) + count
);
36 __STDIO_STREAM_VALIDATE(stream
);
43 if (__STDIO_STREAM_IS_WIDE_WRITING(stream
)
44 || !__STDIO_STREAM_TRANS_TO_WRITE(stream
, __FLAG_WIDE
)
49 r
= wcsnrtombs(buf
, &pw
, n
-count
, sizeof(buf
), &stream
->__state
);
50 if (r
!= ((size_t) -1)) { /* No encoding errors */
52 ++r
; /* 0 is returned when nul is reached. */
53 pw
= ws
+ count
+ r
; /* pw was set to NULL, so correct. */
55 if (__stdio_fwrite((const unsigned char *)buf
, r
, stream
) == r
) {
63 /* Note: The count is incorrect if 0 < __stdio_fwrite return < r!!! */
66 __STDIO_STREAM_VALIDATE(stream
);