Search code examples
c++macoslocale

setlocale() returns 'C' when running as root


I'm using the following to get the system locale:

currentLocale = setlocale(LC_ALL,"");

This works great normally, I get (for example) en_GB.UTF-8.

However, when running the same program as root, I get C. How can I get the system locale when running as root?


Solution

  • There is no "system locale." Each user can set the locale by itself and it may differ for each program (e.g. execute LC_ALL="en_US" locale). A return value of C means that the user has not set any locale and the default locale is active.