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 #ifdef __UCLIBC_MJN3_ONLY__
16 #warning TODO: Fix prototype.
20 size_t attribute_hidden _wstdio_fwrite(const wchar_t *__restrict ws, size_t n,
21 register FILE *__restrict stream)
27 __STDIO_STREAM_VALIDATE(stream);
29 #ifdef __STDIO_BUFFERS
30 if (__STDIO_STREAM_IS_FAKE_VSWPRINTF(stream)) {
31 /* We know buffer is wchar aligned for fake streams. */
32 count = (((wchar_t *)(stream->__bufend))
33 - ((wchar_t *)(stream->__bufpos)));
38 wmemcpy((wchar_t *)(stream->__bufpos), ws, count);
39 stream->__bufpos = (unsigned char *)(((wchar_t *)(stream->__bufpos)) + count);
41 __STDIO_STREAM_VALIDATE(stream);
48 if (__STDIO_STREAM_IS_WIDE_WRITING(stream)
49 || !__STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_WIDE)
54 r = wcsnrtombs(buf, &pw, n-count, sizeof(buf), &stream->__state);
55 if (r != ((size_t) -1)) { /* No encoding errors */
57 ++r; /* 0 is returned when nul is reached. */
58 pw = ws + count + r; /* pw was set to NULL, so correct. */
60 if (__stdio_fwrite((const unsigned char *)buf, r, stream) == r) {
68 /* Note: The count is incorrect if 0 < __stdio_fwrite return < r!!! */
71 __STDIO_STREAM_VALIDATE(stream);