Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the current locale's charset in C?

Tags:

c

locale

How can I find the current locale's charset in C?

setlocale(LC_ALL, NULL) returns "en_US.UTF8", but is there a way to get the charset? In /etc/locale.gen on my system it lists the locales and the charsets, so it's not in the name.

like image 460
Jookia Avatar asked Oct 04 '11 07:10

Jookia


1 Answers

You can query various parameters of the current locale using the nl_langinfo(3) function. The charset is obtained by calling nl_langinfo(CODESET).

Note, that you have to call setlocale before using nl_langinfo to make your program locale-aware.

like image 123
Jan Hudec Avatar answered Oct 13 '22 12:10

Jan Hudec