Nan Xiao Nan Xiao - 3 months ago 19
Linux Question

Is the default locale of a program in *nix "posix"?

From the The Linux Programming Interface:

There are two different methods of setting the locale using setlocale(). The locale
argument may be a string specifying one of the locales defined on the system (i.e.,
the name of one of the subdirectories under /usr/lib/locale), such as de_DE or en_US.
Alternatively, locale may be specified as an empty string, meaning that locale settings should be taken from environment variables:

setlocale(LC_ALL, "");

We must make this call in order for a program to be cognizant of the locale environment variables. If the call is omitted, these environment variables will have no effect on the program.

So per my understaning, if my program doesn't call
function explicitly, my program will use the default
, which is
systems, right? I can't search the specified document.


Looking at the man

7.4 How Programs Set the Locale

A C program inherits its locale environment variables when it starts up. This happens automatically. However, these variables do not automatically control the locale used by the library functions, because ISO C says that all programs start by default in the standard ā€˜Cā€™ locale. To use the locales specified by the environment, you must call setlocale. Call it as follows:

setlocale (LC_ALL, "");

Emphasis mine