summaryrefslogtreecommitdiff
path: root/src/multibyte/mbtowc.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2015-06-16 04:44:17 +0000
committerRich Felker <dalias@aerifal.cx>2015-06-16 05:28:48 +0000
commit1507ebf837334e9e07cfab1ca1c2e88449069a80 (patch)
tree92bad1f861e442f7e2d2fa4e178f471f4371509a /src/multibyte/mbtowc.c
parent38e2f727237230300fea6aff68802db04625fd23 (diff)
downloadmusl-1507ebf837334e9e07cfab1ca1c2e88449069a80.tar.gz
musl-1507ebf837334e9e07cfab1ca1c2e88449069a80.tar.bz2
musl-1507ebf837334e9e07cfab1ca1c2e88449069a80.tar.xz
musl-1507ebf837334e9e07cfab1ca1c2e88449069a80.zip
byte-based C locale, phase 1: multibyte character handling functions
this patch makes the functions which work directly on multibyte characters treat the high bytes as individual abstract code units rather than as multibyte sequences when MB_CUR_MAX is 1. since MB_CUR_MAX is presently defined as a constant 4, all of the new code added is dead code, and optimizing compilers' code generation should not be affected at all. a future commit will activate the new code. as abstract code units, bytes 0x80 to 0xff are represented by wchar_t values 0xdf80 to 0xdfff, at the end of the surrogates range. this ensures that they will never be misinterpreted as Unicode characters, and that all wctype functions return false for these "characters" without needing locale-specific logic. a high range outside of Unicode such as 0x7fffff80 to 0x7fffffff was also considered, but since C11's char16_t also needs to be able to represent conversions of these bytes, the surrogate range was the natural choice.
Diffstat (limited to 'src/multibyte/mbtowc.c')
-rw-r--r--src/multibyte/mbtowc.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/multibyte/mbtowc.c b/src/multibyte/mbtowc.c
index 803d2213..71a95066 100644
--- a/src/multibyte/mbtowc.c
+++ b/src/multibyte/mbtowc.c
@@ -4,6 +4,7 @@
* unnecessary.
*/
+#include <stdlib.h>
#include <wchar.h>
#include <errno.h>
#include "internal.h"
@@ -19,6 +20,7 @@ int mbtowc(wchar_t *restrict wc, const char *restrict src, size_t n)
if (!wc) wc = &dummy;
if (*s < 0x80) return !!(*wc = *s);
+ if (MB_CUR_MAX==1) return (*wc = CODEUNIT(*s)), 1;
if (*s-SA > SB-SA) goto ilseq;
c = bittab[*s++-SA];