In the C locale all byte sequences are valid, however using the
following test programme:
#include <stdio.h>
#include <wchar.h>
#include <errno.h>
#include <stdlib.h>
#include <locale.h>
int main() {
size_t buflen = 512;
wchar_t *p = malloc(buflen*sizeof(wchar_t));
setlocale(LC_ALL, "");
fgetws(p, buflen, stdin);
if (ferror(stdin)) {
printf("%s\n", strerror(errno));
return(1);
}
else {
printf("OK\n");
return(0);
}
}
we get:
: ; perl -e 'printf "%c", 0xa1' | env - LC_ALL=C ~/test
Invalid or incomplete multibyte or wide character
0xa1 is of course neither a multibyte or wide character in the C
locale, and fgetws should just read it in the appropriate manner to
allow propagation of it in the same form throughout the programme.