nl_langinfo(CODESET) seems to always return US-ASCII whatever environment values

As the subject line says, it always returns US-ASCII when I expected UTF-8 on my FreeBSD 10.1 system.

Here is a sample program to test this function:

Code:
/* Compile with "gcc48 -W -Wall -o langinfo langinfo_test.c" */
#include <stdio.h>
#include <langinfo.h>

int main()
{
  printf("%s\n", nl_langinfo(CODESET));
  return 0;
}

These are the environment variables setup on my system.
Code:
[tmp]$ locale
LANG=en_GB.UTF-8
LC_CTYPE="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_TIME=en_DK.UTF-8
LC_NUMERIC="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_ALL=
[tmp]$ export LC_TYPE=en_GB.UTF-8
[tmp]$ ./langinfo
US-ASCII

From the FreeBSD man page:

HISTORY
The nl_langinfo() function first appeared in FreeBSD 4.6.

FreeBSD 4.6 was released back in 2002. So I'm puzzled as to why it doesn't seem to work on my system.
 
KPA, that seems to do the trick. :)

My update test program:

Code:
/* Compile with "gcc48 -W -Wall -o langinfo langinfo_test.c" */
#include <stdio.h>
#include <langinfo.h>
#include <locale.h>

int main()
{
   setlocale(LC_ALL,"");
  printf("%s\n", nl_langinfo(CODESET));
   return 0;
}

I'm actually an Object Pascal [http://www.freepascal.org] developer. In the Object Pascal unit we do call setlocale(LC_ALL,""); first, and then nl_langinfo(), but it doesn't seem to work there. Anyway, now that I know the C library indeed functions correctly under FreeBSD, I'll turn my attention back to the Object Pascal unit in question.

Many thanks for the quick response.
 
Back
Top