summaryrefslogtreecommitdiffstats
path: root/lib/libc/locale/wctob.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/wctob.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/wctob.c')
-rw-r--r--lib/libc/locale/wctob.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/libc/locale/wctob.c b/lib/libc/locale/wctob.c
index da7afcf..4f4d295 100644
--- a/lib/libc/locale/wctob.c
+++ b/lib/libc/locale/wctob.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
@@ -29,20 +29,16 @@ __FBSDID("$FreeBSD$");
#include <limits.h>
#include <stdio.h>
-#include <string.h>
#include <wchar.h>
int
wctob(wint_t c)
{
+ static const mbstate_t initial;
+ mbstate_t mbs = initial;
char buf[MB_LEN_MAX];
- /*
- * 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 (c == WEOF || wcrtomb(buf, c, NULL) != 1)
+ if (c == WEOF || wcrtomb(buf, c, &mbs) != 1)
return (EOF);
return ((unsigned char)*buf);
}
OpenPOWER on IntegriCloud