summaryrefslogtreecommitdiffstats
path: root/lib/libc/locale/wctomb.c
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2004-04-06 13:14:03 +0000
committertjr <tjr@FreeBSD.org>2004-04-06 13:14:03 +0000
commit4212f9711ffee179c943b9f40b788b759a1ad9e6 (patch)
tree6779dc19a3df61ca545f851748ebd5f5de3a255e /lib/libc/locale/wctomb.c
parentfcc4fa555ff7fcd7b9e4327aa717b090a18361b5 (diff)
downloadFreeBSD-src-4212f9711ffee179c943b9f40b788b759a1ad9e6.zip
FreeBSD-src-4212f9711ffee179c943b9f40b788b759a1ad9e6.tar.gz
Prepare to handle state-dependent encodings. This mainly involves not
taking shortcuts when it comes to storing and passing around conversion states.
Diffstat (limited to 'lib/libc/locale/wctomb.c')
-rw-r--r--lib/libc/locale/wctomb.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/lib/libc/locale/wctomb.c b/lib/libc/locale/wctomb.c
index e212b96..9e6f183 100644
--- a/lib/libc/locale/wctomb.c
+++ b/lib/libc/locale/wctomb.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2002, 2003 Tim J. Robbins.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -36,20 +36,16 @@ __FBSDID("$FreeBSD$");
int
wctomb(char *s, wchar_t wchar)
{
- char buf[MB_LEN_MAX];
+ static const mbstate_t initial;
+ static mbstate_t mbs;
size_t rval;
- if (s == NULL)
+ if (s == NULL) {
/* No support for state dependent encodings. */
+ mbs = initial;
return (0);
- if (s == NULL)
- s = buf;
- /*
- * We pass NULL as the state pointer to wcrtomb() because we don't
- * support state-dependent encodings and don't want to waste time
- * creating a zeroed mbstate_t that will not be used.
- */
- if ((rval = wcrtomb(s, wchar, NULL)) == (size_t)-1)
+ }
+ if ((rval = wcrtomb(s, wchar, &mbs)) == (size_t)-1)
return (-1);
if (rval > INT_MAX) {
errno = ERANGE;
OpenPOWER on IntegriCloud