Hi,
Stefan answered this completely, except for one minor detail
which i'm adding:
Stefan Sperling wrote on Mon, Mar 19, 2018 at 12:16:20PM +0100:
> Invalid input can only occur in the first argument:
> setlocale(0xdeadbeef, NULL) returned 'NULL'
Not true. In addition to that, the CHARSET (i.e. the part after
the last dot if any) is also checked for validity - ".UTG-8" is
valid, any other suffix is invalid and causes NULL to be returned.
Besides, setlocale(3) can return NULL in case of ENOMEM.
Yours,
Ingo
$ make setlocale
cc -O2 -pipe -o setlocale setlocale.c
$ LC_CTYPE=en_US.UTF-8 ./setlocale
en_US.UTF-8
$ LC_CTYPE=en_US.UTF-9 ./setlocale
setlocale: setlocale failed
$ cat setlocale.c
#include <err.h>
#include <locale.h>
#include <stdio.h>
int
main(void)
{
char *retval;
retval = setlocale(LC_CTYPE, "");
if (retval == NULL)
errx(1, "setlocale failed");
puts(retval);
return 0;
}