summaryrefslogtreecommitdiff
path: root/libc/stdio/stdio.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2002-11-22 03:05:27 +0000
committerManuel Novoa III <mjn3@codepoet.org>2002-11-22 03:05:27 +0000
commitc386ddb4d8a1b076d94ebe8b85ca5d0dd124892b (patch)
treee30c9d77393721491f4a3a42e223980352b72ff8 /libc/stdio/stdio.c
parent2b8a8dc7144328f301390f13fa560d29a410e34f (diff)
Ok... here's the summary:
Hopefully locale support will build when cross compiling now. Collation is still not supported, but that's what I'm currently working on. In the next couple of days, I'll probably put up a couple of files for download that will save people the trouble of generating all the glibc locales. Added *wprintf functions, although they currently don't support floating point. That will be fixed when I rewrite _dtostr... or possibly before. Added the wcsto{inttype} functions. Added iconv() and a mini iconv utility. The require locale support and only provide for conversions involving the various unicode encodings { UCS-4*, UCS-2*, UTF-32*, UTF-16*, UTF-8 }, the 8-bit codesets built with the locale data, and the internal WCHAR_T.
Diffstat (limited to 'libc/stdio/stdio.c')
-rw-r--r--libc/stdio/stdio.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/libc/stdio/stdio.c b/libc/stdio/stdio.c
index 8b9b3167c..cf72a5ccc 100644
--- a/libc/stdio/stdio.c
+++ b/libc/stdio/stdio.c
@@ -45,6 +45,9 @@
* function pointers are set to that it is a "normal" file with a
* file descriptor of -1. Note: The cookie pointer is reset to NULL
* if the FILE struct is free'd by fclose.
+ *
+ * Nov 21, 2002
+ * Added internal function _wstdio_fwrite.
*/
/* Before we include anything, convert L_ctermid to L_ctermid_function
@@ -3449,3 +3452,58 @@ char *_uintmaxtostr(register char * __restrict bufend, uintmax_t uval,
#endif
/**********************************************************************/
+#ifdef L__wstdio_fwrite
+
+#include <wchar.h>
+
+size_t _wstdio_fwrite(const wchar_t *__restrict ws, size_t n,
+ register FILE *__restrict stream)
+{
+ size_t r, count;
+ char buf[64];
+ const wchar_t *pw;
+
+#ifdef __STDIO_BUFFERS
+ if (stream->filedes == -3) { /* Special case to support {v}swprintf. */
+ count = ((wchar_t *)(stream->bufend)) - ((wchar_t *)(stream->bufpos));
+ if (count > n) {
+ count = n;
+ }
+ if (count) {
+ wmemcpy((wchar_t *)(stream->bufpos), ws, count);
+ stream->bufpos = (char *)(((wchar_t *)(stream->bufpos)) + count);
+ }
+ return n;
+ }
+#endif
+
+ if (stream->modeflags & __FLAG_NARROW) {
+ stream->modeflags |= __FLAG_ERROR;
+ __set_errno(EBADF);
+ return 0;
+ }
+ stream->modeflags |= __FLAG_WIDE;
+
+ pw = ws;
+ count = 0;
+ while (n > count) {
+ r = wcsnrtombs(buf, &pw, n, sizeof(buf), &stream->state);
+ if (r != ((size_t) -1)) { /* No encoding errors */
+ if (!r) {
+ ++r; /* 0 is returned when nul is reached. */
+ pw = ws + count + r; /* pw was set to NULL, so correct. */
+ }
+ if (_stdio_fwrite(buf, r, stream) == r) {
+ count = pw - ws;
+ continue;
+ }
+ }
+ break;
+ }
+
+ /* Note: The count is incorrect if 0 < _stdio_fwrite return < r!!! */
+ return count;
+}
+
+#endif
+/**********************************************************************/