#include #include #include #include #include static void check(char *s, int exp_ret) { wchar_t res; size_t ret; ret = mbrtowc(&res, s, strlen(s) + 1, NULL); if (ret != exp_ret) fprintf(stderr, "got %d, expected %d\n", ret, exp_ret); assert(ret == exp_ret); if (ret != -1) printf("converted %d byte(s) at start of '%s' to %x\n", ret, s, res); } int main(int argc, char **argv) { setlocale(LC_CTYPE, "de_DE.UTF-8"); check("\xc3\xb6", 2); // this is an invalid utf-8 sequence, since it expands to // U+2f43580 check("\xfa\xbd\x83\x96\x80", -1); }