-#include <stddef.h>
+#include <stdlib.h>
+#include "locale_impl.h"
size_t __ctype_get_mb_cur_max()
{
- return 4;
+ return MB_CUR_MAX;
}
int idx = item & 65535;
const char *str;
- if (item == CODESET) return "UTF-8";
+ if (item == CODESET)
+ return MB_CUR_MAX==1 ? "UTF-8-CODE-UNITS" : "UTF-8";
switch (cat) {
case LC_NUMERIC:
#include <stdio.h>
#include <wchar.h>
+#include <stdlib.h>
+#include "internal.h"
wint_t btowc(int c)
{
- c = (unsigned char)c;
- return c<128U ? c : EOF;
+ int b = (unsigned char)c;
+ return b<128U ? b : (MB_CUR_MAX==1 && c!=EOF) ? CODEUNIT(c) : WEOF;
}
#define SA 0xc2u
#define SB 0xf4u
+
+/* Arbitrary encoding for representing code units instead of characters. */
+#define CODEUNIT(c) (0xdfff & (signed char)(c))
+#define IS_CODEUNIT(c) ((unsigned)(c)-0xdf80 < 0x80)
+
+/* Get inline definition of MB_CUR_MAX. */
+#include "locale_impl.h"
* unnecessary.
*/
+#include <stdlib.h>
#include <wchar.h>
#include <errno.h>
#include "internal.h"
if (!n) return -2;
if (!c) {
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]; n--;
}
#include <stdint.h>
#include <wchar.h>
#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
#include "internal.h"
size_t mbsrtowcs(wchar_t *restrict ws, const char **restrict src, size_t wn, mbstate_t *restrict st)
}
}
+ if (MB_CUR_MAX==1) {
+ if (!ws) return strlen((const char *)s);
+ for (;;) {
+ if (!wn) {
+ *src = (const void *)s;
+ return wn0;
+ }
+ if (!*s) break;
+ c = *s++;
+ *ws++ = CODEUNIT(c);
+ wn--;
+ }
+ *ws = 0;
+ *src = 0;
+ return wn0-wn;
+ }
+
if (!ws) for (;;) {
if (*s-1u < 0x7f && (uintptr_t)s%4 == 0) {
while (!(( *(uint32_t*)s | *(uint32_t*)s-0x01010101) & 0x80808080)) {
* unnecessary.
*/
+#include <stdlib.h>
#include <wchar.h>
#include <errno.h>
#include "internal.h"
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];
* unnecessary.
*/
+#include <stdlib.h>
#include <wchar.h>
#include <errno.h>
+#include "internal.h"
size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict st)
{
if ((unsigned)wc < 0x80) {
*s = wc;
return 1;
+ } else if (MB_CUR_MAX == 1) {
+ if (!IS_CODEUNIT(wc)) {
+ errno = EILSEQ;
+ return -1;
+ }
+ *s = wc;
+ return 1;
} else if ((unsigned)wc < 0x800) {
*s++ = 0xc0 | (wc>>6);
*s = 0x80 | (wc&0x3f);
-#include <stdio.h>
#include <wchar.h>
+#include <stdlib.h>
+#include "internal.h"
int wctob(wint_t c)
{
if (c < 128U) return c;
+ if (MB_CUR_MAX==1 && IS_CODEUNIT(c)) return (unsigned char)c;
return EOF;
}
#include <stdlib.h>
#include <wchar.h>
#include <wctype.h>
+#include "locale_impl.h"
#define END 0
#define UNMATCHABLE -2
* On illegal sequences we may get it wrong, but in that case
* we necessarily have a matching failure anyway. */
for (s=endstr; s>str && tailcnt; tailcnt--) {
- if (s[-1] < 128U) s--;
+ if (s[-1] < 128U || MB_CUR_MAX==1) s--;
else while ((unsigned char)*--s-0x80U<0x40 && s>str);
}
if (tailcnt) return FNM_NOMATCH;