Search code examples
clinuxlocalestrftime

How to get extended locale information by api


I want to getinformation about the current locale. The only interface I could find is:

locale.h: extern struct lconv *localeconv (void);

But the struct lconv only contains numeric and financial locale information. I also want to get the time related information that's used by strftime. In particular the names of days and date format.

Tracing locale abday I found "/usr/lib/locale/locale-archive" but I cannot find any information about its format.


Solution

  • Use nl_langinfo(3). From the glibc docs:

    7.7 Accessing Locale Information

    … To do this the C library provides two functions: localeconv and nl_langinfo. The former is part of ISO C and therefore portable, but has a brain-damaged interface. The second is part of the Unix interface and is portable in as far as the system follows the Unix standards.

    The Lame Way to Locale Data: ISO C’s localeconv.

    The Elegant and Fast Way: X/Open’s nl_langinfo.