#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
+#include "u8-mbtouc.h"
static uint8_t *data;
static size_t n, pos;
return true;
}
+static bool
+all_utf8(const uint8_t *p)
+{
+ size_t len = strlen ((char *) p);
+ for (size_t ofs = 0, mblen; ofs < len; ofs += mblen)
+ {
+ ucs4_t uc;
+
+ mblen = u8_mbtouc (&uc, p + ofs, len - ofs);
+ if (uc < 32 || uc == 127 || uc == 0xfffd)
+ return false;
+ }
+ return true;
+}
+
static char *
get_fixed_string(int len, const char *where)
{
- if (pos + len > n || !memchr(&data[pos], 0, len) || !all_ascii(&data[pos]))
+ if (pos + len > n || !memchr(&data[pos], 0, len) || !all_utf8(&data[pos]))
{
fprintf(stderr, "%s: 0x%x: bad fixed-width string\n", where, pos);
exit(1);