Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2010-05-02 15:55:01 +0400
committerCorinna Vinschen <corinna@vinschen.de>2010-05-02 15:55:01 +0400
commitffa42cf6a0aa8835f832027c7545e2476b89b834 (patch)
treed31c67e411c2e62198836716809ec3560fcbff75 /newlib/libc/stdlib
parentbe129c26e2144ba97518217d91f1d695e32217a5 (diff)
* libc/stdlib/wctob.c (wctob): Reorganize and fix WEOF check. Rename
pwc to pmb and convert to array to avoid buffer overflow. Rename c to wc. Check wc for WEOF instead of for EOF. Return first byte of pmb if __wctomb conversion returned exactly one byte, EOF otherwise.
Diffstat (limited to 'newlib/libc/stdlib')
-rw-r--r--newlib/libc/stdlib/wctob.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/newlib/libc/stdlib/wctob.c b/newlib/libc/stdlib/wctob.c
index 927c1a7a8..d97c01f24 100644
--- a/newlib/libc/stdlib/wctob.c
+++ b/newlib/libc/stdlib/wctob.c
@@ -1,26 +1,24 @@
#include <reent.h>
#include <wchar.h>
-#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <limits.h>
#include "local.h"
int
-wctob (wint_t c)
+wctob (wint_t wc)
{
mbstate_t mbs;
- int retval = 0;
- unsigned char pwc;
+ unsigned char pmb[MB_LEN_MAX];
+
+ if (wc == WEOF)
+ return EOF;
/* Put mbs in initial state. */
memset (&mbs, '\0', sizeof (mbs));
_REENT_CHECK_MISC(_REENT);
- retval = __wctomb (_REENT, &pwc, c, __locale_charset (), &mbs);
-
- if (c == EOF || retval != 1)
- return WEOF;
- else
- return (int)pwc;
+ return __wctomb (_REENT, (char *) pmb, wc, __locale_charset (), &mbs) == 1
+ ? (int) pmb[0] : EOF;
}