diff options
Diffstat (limited to 'libc/misc/wchar')
-rw-r--r-- | libc/misc/wchar/Makefile | 18 | ||||
-rw-r--r-- | libc/misc/wchar/wchar.c | 41 | ||||
-rw-r--r-- | libc/misc/wchar/wstdio.c | 14 |
3 files changed, 39 insertions, 34 deletions
diff --git a/libc/misc/wchar/Makefile b/libc/misc/wchar/Makefile index a96dae2b4..b1db37293 100644 --- a/libc/misc/wchar/Makefile +++ b/libc/misc/wchar/Makefile @@ -33,17 +33,17 @@ ifeq ($(UCLIBC_HAS_LOCALE),y) MOBJ1 += iconv.o endif -MSRC2= wstdio.c -MOBJ2= fwide.o \ - fgetwc.o getwchar.o fgetws.o \ - fputwc.o putwchar.o fputws.o \ - ungetwc.o -# getwc (fgetwc alias) getwc_unlocked (fgetwc_unlocked alias) -# putwc (fputwc alias) putwc_unlocked (fputwc_unlocked alias) - +# The stdio and time related wide functions are now built in the normal +# directories. +# +# stdio: +# fwide fgetwc getwchar fgetws fputwc putwchar fputws ungetwc +# getwc (fgetwc alias) getwc_unlocked (fgetwc_unlocked alias) +# putwc (fputwc alias) putwc_unlocked (fputwc_unlocked alias) +# time: # wcsftime -OBJS=$(MOBJ1) $(MOBJ2) +OBJS=$(MOBJ1) all: $(OBJS) $(LIBC) diff --git a/libc/misc/wchar/wchar.c b/libc/misc/wchar/wchar.c index 4fc96f430..d1383c99f 100644 --- a/libc/misc/wchar/wchar.c +++ b/libc/misc/wchar/wchar.c @@ -1,5 +1,5 @@ -/* Copyright (C) 2002 Manuel Novoa III +/* Copyright (C) 2002, 2003, 2004 Manuel Novoa III * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -92,6 +92,9 @@ * Aug 18, 2003 * Bug fix: _wchar_utf8sntowcs and _wchar_wcsntoutf8s now set errno if EILSEQ. * + * Feb 11, 2004 + * Bug fix: Fix size check for remaining output space in iconv(). + * * Manuel */ @@ -193,7 +196,7 @@ wint_t btowc(int c) if (c != EOF) { *buf = (unsigned char) c; - mbstate.mask = 0; /* Initialize the mbstate. */ + mbstate.__mask = 0; /* Initialize the mbstate. */ if (mbrtowc(&wc, buf, 1, &mbstate) <= 1) { return wc; } @@ -251,7 +254,7 @@ int wctob(wint_t c) int mbsinit(const mbstate_t *ps) { - return !ps || !ps->mask; + return !ps || !ps->__mask; } #endif @@ -291,7 +294,8 @@ size_t mbrtowc(wchar_t *__restrict pwc, const char *__restrict s, s = empty_string; n = 1; } else if (!n) { - return (ps->mask && (ps->wc == 0xffffU)) /* TODO: change error code? */ + /* TODO: change error code? */ + return (ps->__mask && (ps->__wc == 0xffffU)) ? ((size_t) -1) : ((size_t) -2); } @@ -434,15 +438,15 @@ size_t _wchar_utf8sntowcs(wchar_t *__restrict pwc, size_t wn, return 0; } - if ((mask = (__uwchar_t) ps->mask) != 0) { /* A continuation... */ + if ((mask = (__uwchar_t) ps->__mask) != 0) { /* A continuation... */ #ifdef DECODER - wc = (__uwchar_t) ps->wc; + wc = (__uwchar_t) ps->__wc; if (n) { goto CONTINUE; } goto DONE; #else - if ((wc = (__uwchar_t) ps->wc) != 0xffffU) { + if ((wc = (__uwchar_t) ps->__wc) != 0xffffU) { /* TODO: change error code here and below? */ if (n) { goto CONTINUE; @@ -472,8 +476,8 @@ size_t _wchar_utf8sntowcs(wchar_t *__restrict pwc, size_t wn, wc = 0xfffdU; goto COMPLETE; #else - ps->mask = mask; - ps->wc = 0xffffU; + ps->__mask = mask; + ps->__wc = 0xffffU; __set_errno(EILSEQ); return (size_t) -1; /* Illegal start byte! */ #endif @@ -532,8 +536,8 @@ size_t _wchar_utf8sntowcs(wchar_t *__restrict pwc, size_t wn, } while ((mask >>= 5) >= 0x40); goto DONE; } - ps->mask = (wchar_t) mask; - ps->wc = (wchar_t) wc; + ps->__mask = (wchar_t) mask; + ps->__wc = (wchar_t) wc; *src = s; return (size_t) -2; } @@ -552,8 +556,8 @@ size_t _wchar_utf8sntowcs(wchar_t *__restrict pwc, size_t wn, #endif DONE: - /* ps->wc is irrelavent here. */ - ps->mask = 0; + /* ps->__wc is irrelavent here. */ + ps->__mask = 0; if (pwc != wcbuf) { *src = s; } @@ -1037,7 +1041,7 @@ int wcswidth(const wchar_t *pwcs, size_t n) else if (ENCODING == __ctype_encoding_8_bit) { mbstate_t mbstate; - mbstate.mask = 0; /* Initialize the mbstate. */ + mbstate.__mask = 0; /* Initialize the mbstate. */ if (__wcsnrtombs(NULL, &pwcs, n, SIZE_MAX, &mbstate) == ((size_t) - 1)) { return -1; } @@ -1282,7 +1286,8 @@ iconv_t weak_function iconv_open(const char *tocode, const char *fromcode) px->tobom0 = px->tobom = (tocodeset & 0x10) >> 4; px->fromcodeset0 = px->fromcodeset = fromcodeset; px->frombom0 = px->frombom = (fromcodeset & 0x10) >> 4; - px->skip_invalid_input = px->tostate.mask = px->fromstate.mask = 0; + px->skip_invalid_input = px->tostate.__mask + = px->fromstate.__mask = 0; return (iconv_t) px; } } else { @@ -1316,7 +1321,7 @@ size_t weak_function iconv(iconv_t cd, char **__restrict inbuf, * shift sequence to return to initial state! */ if ((px->fromcodeset & 0xf0) == 0xe0) { } - px->tostate.mask = px->fromstate.mask = 0; + px->tostate.__mask = px->fromstate.__mask = 0; px->fromcodeset = px->fromcodeset0; px->tobom = px->tobom0; px->frombom = px->frombom0; @@ -1398,7 +1403,7 @@ size_t weak_function iconv(iconv_t cd, char **__restrict inbuf, INVALID: __set_errno(EINVAL); } else { - px->fromstate.mask = 0; + px->fromstate.__mask = 0; inci = 1; ILLEGAL: if (px->skip_invalid_input) { @@ -1444,7 +1449,7 @@ size_t weak_function iconv(iconv_t cd, char **__restrict inbuf, if (px->tocodeset >= IC_MULTIBYTE) { inco = (px->tocodeset == IC_WCHAR_T) ? 4: (px->tocodeset & 6); - if (*outbytesleft < inci) goto TOO_BIG; + if (*outbytesleft < inco) goto TOO_BIG; if (px->tocodeset != IC_WCHAR_T) { if (((__uwchar_t) wc) > (((px->tocodeset & IC_UCS_4) == IC_UCS_4) ? 0x7fffffffUL : 0x10ffffUL) diff --git a/libc/misc/wchar/wstdio.c b/libc/misc/wchar/wstdio.c index e984bf837..b49494f35 100644 --- a/libc/misc/wchar/wstdio.c +++ b/libc/misc/wchar/wstdio.c @@ -57,7 +57,7 @@ #include <errno.h> #include <assert.h> -#ifndef __STDIO_THREADSAFE +#ifndef __UCLIBC_HAS_THREADS__ #ifdef __BCC__ #define UNLOCKED_STREAM(RETURNTYPE,NAME,PARAMS,ARGS,STREAM) \ @@ -85,7 +85,7 @@ void NAME PARAMS #define __STDIO_THREADLOCK_OPENLIST #define __STDIO_THREADUNLOCK_OPENLIST -#else /* __STDIO_THREADSAFE */ +#else /* __UCLIBC_HAS_THREADS__ */ #include <pthread.h> @@ -121,7 +121,7 @@ void NAME##_unlocked PARAMS #define __STDIO_THREADTRYLOCK_OPENLIST \ __pthread_mutex_trylock(&_stdio_openlist_lock) -#endif /* __STDIO_THREADSAFE */ +#endif /* __UCLIBC_HAS_THREADS__ */ #ifndef __STDIO_BUFFERS #error stdio buffers are currently required for wide i/o @@ -404,9 +404,9 @@ wint_t ungetwc(wint_t c, register FILE *stream) /* If can't read or c == WEOF or ungot slots already filled, then fail. */ if ((stream->modeflags & (__MASK_UNGOT2|__FLAG_WRITEONLY -#ifndef __STDIO_AUTO_RW_TRANSITION +#ifndef __UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__ |__FLAG_WRITING /* Note: technically no, but yes in spirit */ -#endif /* __STDIO_AUTO_RW_TRANSITION */ +#endif /* __UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__ */ )) || ((stream->modeflags & __MASK_UNGOT1) && (stream->ungot[1])) || (c == WEOF) ) { @@ -417,11 +417,11 @@ wint_t ungetwc(wint_t c, register FILE *stream) /* ungot_width */ #ifdef __STDIO_BUFFERS -#ifdef __STDIO_AUTO_RW_TRANSITION +#ifdef __UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__ if (stream->modeflags & __FLAG_WRITING) { fflush_unlocked(stream); /* Commit any write-buffered chars. */ } -#endif /* __STDIO_AUTO_RW_TRANSITION */ +#endif /* __UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__ */ #endif /* __STDIO_BUFFERS */ /* Clear EOF and WRITING flags, and set READING FLAG */ |