SETLOCALE(3)               POSIX Programmer's Manual              SETLOCALE(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.


NNAAMMEE
       setlocale -- set program locale

SSYYNNOOPPSSIISS
       #include <locale.h>

       char *setlocale(int _c_a_t_e_g_o_r_y, const char *_l_o_c_a_l_e);

DDEESSCCRRIIPPTTIIOONN
       The functionality described on this reference page is aligned with the
       ISO C standard. Any conflict between the requirements described here
       and the ISO C standard is unintentional. This volume of POSIX.1-2008
       defers to the ISO C standard.

       The _s_e_t_l_o_c_a_l_e() function selects the appropriate piece of the global
       locale, as specified by the _c_a_t_e_g_o_r_y and _l_o_c_a_l_e arguments, and can be
       used to change or query the entire global locale or portions thereof.
       The value LC_ALL for _c_a_t_e_g_o_r_y names the entire global locale; other
       values for _c_a_t_e_g_o_r_y name only a part of the global locale:

       LC_COLLATE  Affects the behavior of regular expressions and the
                   collation functions.

       LC_CTYPE    Affects the behavior of regular expressions, character
                   classification, character conversion functions, and wide-
                   character functions.

       LC_MESSAGES Affects the affirmative and negative response expressions
                   returned by _n_l___l_a_n_g_i_n_f_o() and the way message catalogs are
                   located. It may also affect the behavior of functions that
                   return or write message strings.

       LC_MONETARY Affects the behavior of functions that handle monetary
                   values.

       LC_NUMERIC  Affects the behavior of functions that handle numeric
                   values.

       LC_TIME     Affects the behavior of the time conversion functions.

       The _l_o_c_a_l_e argument is a pointer to a character string containing the
       required setting of _c_a_t_e_g_o_r_y.  The contents of this string are
       implementation-defined. In addition, the following preset values of
       _l_o_c_a_l_e are defined for all settings of _c_a_t_e_g_o_r_y:

       "POSIX"     Specifies the minimal environment for C-language
                   translation called the POSIX locale. The POSIX locale is
                   the default global locale at entry to _m_a_i_n().

       "C"         Equivalent to ""PPOOSSIIXX"".

       ""          Specifies an implementation-defined native environment.
                   The determination of the name of the new locale for the
                   specified category depends on the value of the associated
                   environment variables, _L_C___* and _L_A_N_G; see the Base
                   Definitions volume of POSIX.1-2008, _C_h_a_p_t_e_r _7, _L_o_c_a_l_e and
                   _C_h_a_p_t_e_r _8, _E_n_v_i_r_o_n_m_e_n_t _V_a_r_i_a_b_l_e_s.

       A null pointer
                   Directs _s_e_t_l_o_c_a_l_e() to query the current global locale
                   setting and return the name of the locale if _c_a_t_e_g_o_r_y is
                   not LC_ALL, or a string which encodes the locale name(s)
                   for all of the individual categories if _c_a_t_e_g_o_r_y is LC_ALL.

       Setting all of the categories of the global locale is similar to
       successively setting each individual category of the global locale,
       except that all error checking is done before any actions are
       performed. To set all the categories of the global locale, _s_e_t_l_o_c_a_l_e()
       can be invoked as:

           sseettllooccaallee((LLCC__AALLLL,, """"));;

       In this case, _s_e_t_l_o_c_a_l_e() shall first verify that the values of all the
       environment variables it needs according to the precedence rules
       (described in the Base Definitions volume of POSIX.1-2008, _C_h_a_p_t_e_r _8,
       _E_n_v_i_r_o_n_m_e_n_t _V_a_r_i_a_b_l_e_s) indicate supported locales. If the value of any
       of these environment variable searches yields a locale that is not
       supported (and non-null), _s_e_t_l_o_c_a_l_e() shall return a null pointer and
       the global locale shall not be changed. If all environment variables
       name supported locales, _s_e_t_l_o_c_a_l_e() shall proceed as if it had been
       called for each category, using the appropriate value from the
       associated environment variable or from the implementation-defined
       default if there is no such value.

       The global locale established using _s_e_t_l_o_c_a_l_e() shall only be used in
       threads for which no current locale has been set using _u_s_e_l_o_c_a_l_e() or
       whose current locale has been set to the global locale using
       _u_s_e_l_o_c_a_l_e(LC_GLOBAL_LOCALE)_.

       The implementation shall behave as if no function defined in this
       volume of POSIX.1-2008 calls _s_e_t_l_o_c_a_l_e().

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _s_e_t_l_o_c_a_l_e() shall return the string
       associated with the specified category for the new locale. Otherwise,
       _s_e_t_l_o_c_a_l_e() shall return a null pointer and the global locale shall not
       be changed.

       A null pointer for _l_o_c_a_l_e shall cause _s_e_t_l_o_c_a_l_e() to return a pointer
       to the string associated with the specified _c_a_t_e_g_o_r_y for the current
       global locale. The global locale shall not be changed.

       The string returned by _s_e_t_l_o_c_a_l_e() is such that a subsequent call with
       that string and its associated _c_a_t_e_g_o_r_y shall restore that part of the
       global locale. The application shall not modify the string returned.
       The returned string pointer might be invalidated or the string content
       might be overwritten by a subsequent call to _s_e_t_l_o_c_a_l_e().

EERRRROORRSS
       No errors are defined.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
       None.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       The following code illustrates how a program can initialize the
       international environment for one language, while selectively modifying
       the global locale such that regular expressions and string operations
       can be applied to text recorded in a different language:

           sseettllooccaallee((LLCC__AALLLL,, ""DDee""));;
           sseettllooccaallee((LLCC__CCOOLLLLAATTEE,, ""FFrr@@ddiicctt""));;

       Internationalized programs can initiate language operation according to
       environment variable settings (see the Base Definitions volume of
       POSIX.1-2008, _S_e_c_t_i_o_n _8_._2, _I_n_t_e_r_n_a_t_i_o_n_a_l_i_z_a_t_i_o_n _V_a_r_i_a_b_l_e_s) by calling
       _s_e_t_l_o_c_a_l_e() as follows:

           sseettllooccaallee((LLCC__AALLLL,, """"));;

       Changing the setting of _L_C___M_E_S_S_A_G_E_S has no effect on catalogs that have
       already been opened by calls to _c_a_t_o_p_e_n().

       In order to make use of different locale settings while multiple
       threads are running, applications should use _u_s_e_l_o_c_a_l_e() in preference
       to _s_e_t_l_o_c_a_l_e().

RRAATTIIOONNAALLEE
       References to the international environment or locale in the following
       text relate to the global locale for the process. This can be
       overridden for individual threads using _u_s_e_l_o_c_a_l_e().

       The ISO C standard defines a collection of functions to support
       internationalization.  One of the most significant aspects of these
       functions is a facility to set and query the _i_n_t_e_r_n_a_t_i_o_n_a_l _e_n_v_i_r_o_n_m_e_n_t.
       The international environment is a repository of information that
       affects the behavior of certain functionality, namely:

        1. Character handling

        2. Collating

        3. Date/time formatting

        4. Numeric editing

        5. Monetary formatting

        6. Messaging

       The _s_e_t_l_o_c_a_l_e() function provides the application developer with the
       ability to set all or portions, called _c_a_t_e_g_o_r_i_e_s, of the international
       environment.  These categories correspond to the areas of functionality
       mentioned above. The syntax for _s_e_t_l_o_c_a_l_e() is as follows:

           cchhaarr **sseettllooccaallee((iinntt _c_a_t_e_g_o_r_y,, ccoonnsstt cchhaarr **_l_o_c_a_l_e));;

       where _c_a_t_e_g_o_r_y is the name of one of following categories, namely:

              LC_COLLATE LC_CTYPE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME

       In addition, a special value called LC_ALL directs _s_e_t_l_o_c_a_l_e() to set
       all categories.

       There are two primary uses of _s_e_t_l_o_c_a_l_e():

        1. Querying the international environment to find out what it is set
           to

        2. Setting the international environment, or _l_o_c_a_l_e, to a specific
           value

       The behavior of _s_e_t_l_o_c_a_l_e() in these two areas is described below.
       Since it is difficult to describe the behavior in words, examples are
       used to illustrate the behavior of specific uses.

       To query the international environment, _s_e_t_l_o_c_a_l_e() is invoked with a
       specific category and the null pointer as the locale. The null pointer
       is a special directive to _s_e_t_l_o_c_a_l_e() that tells it to query rather
       than set the international environment.  The following syntax is used
       to query the name of the international environment:

           sseettllooccaallee(({{LLCC__AALLLL,, LLCC__CCOOLLLLAATTEE,, LLCC__CCTTYYPPEE,, LLCC__MMEESSSSAAGGEESS,, LLCC__MMOONNEETTAARRYY,, \\
               LLCC__NNUUMMEERRIICC,, LLCC__TTIIMMEE}},,((cchhaarr **)) NNUULLLL));;

       The _s_e_t_l_o_c_a_l_e() function shall return the string corresponding to the
       current international environment. This value may be used by a
       subsequent call to _s_e_t_l_o_c_a_l_e() to reset the international environment
       to this value. However, it should be noted that the return value from
       _s_e_t_l_o_c_a_l_e() may be a pointer to a static area within the function and
       is not guaranteed to remain unchanged (that is, it may be modified by a
       subsequent call to _s_e_t_l_o_c_a_l_e()).  Therefore, if the purpose of calling
       _s_e_t_l_o_c_a_l_e() is to save the value of the current international
       environment so it can be changed and reset later, the return value
       should be copied to an array of cchhaarr in the calling program.

       There are three ways to set the international environment with
       _s_e_t_l_o_c_a_l_e():

       _s_e_t_l_o_c_a_l_e(_c_a_t_e_g_o_r_y, _s_t_r_i_n_g)
             This usage sets a specific _c_a_t_e_g_o_r_y in the international
             environment to a specific value corresponding to the value of the
             _s_t_r_i_n_g.  A specific example is provided below:

                 sseettllooccaallee((LLCC__AALLLL,, ""ffrr__FFRR..IISSOO--88885599--11""));;

             In this example, all categories of the international environment
             are set to the locale corresponding to the string
             ""ffrr__FFRR..IISSOO--88885599--11"", or to the French language as spoken in France
             using the ISO/IEC 8859-1:1998 standard codeset.

             If the string does not correspond to a valid locale, _s_e_t_l_o_c_a_l_e()
             shall return a null pointer and the international environment is
             not changed. Otherwise, _s_e_t_l_o_c_a_l_e() shall return the name of the
             locale just set.

       _s_e_t_l_o_c_a_l_e(_c_a_t_e_g_o_r_y, "C")
             The ISO C standard states that one locale must exist on all
             conforming implementations. The name of the locale is C and
             corresponds to a minimal international environment needed to
             support the C programming language.

       _s_e_t_l_o_c_a_l_e(_c_a_t_e_g_o_r_y, "")
             This sets a specific category to an implementation-defined
             default.  This corresponds to the value of the environment
             variables.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _c_a_t_o_p_e_n(), _e_x_e_c, _f_p_r_i_n_t_f(), _f_s_c_a_n_f(), _i_s_a_l_n_u_m(), _i_s_a_l_p_h_a(), _i_s_b_l_a_n_k(),
       _i_s_c_n_t_r_l(), _i_s_d_i_g_i_t(), _i_s_g_r_a_p_h(), _i_s_l_o_w_e_r(), _i_s_p_r_i_n_t(), _i_s_p_u_n_c_t(),
       _i_s_s_p_a_c_e(), _i_s_u_p_p_e_r(), _i_s_w_a_l_n_u_m(), _i_s_w_a_l_p_h_a(), _i_s_w_b_l_a_n_k(), _i_s_w_c_n_t_r_l(),
       _i_s_w_c_t_y_p_e(), _i_s_w_d_i_g_i_t(), _i_s_w_g_r_a_p_h(), _i_s_w_l_o_w_e_r(), _i_s_w_p_r_i_n_t(), _i_s_w_p_u_n_c_t(),
       _i_s_w_s_p_a_c_e(), _i_s_w_u_p_p_e_r(), _i_s_w_x_d_i_g_i_t(), _i_s_x_d_i_g_i_t(), _l_o_c_a_l_e_c_o_n_v(), _m_b_l_e_n(),
       _m_b_s_t_o_w_c_s(), _m_b_t_o_w_c(), _n_l___l_a_n_g_i_n_f_o(), _p_e_r_r_o_r(), _p_s_i_g_i_n_f_o(), _s_e_t_l_o_c_a_l_e(),
       _s_t_r_c_o_l_l(), _s_t_r_e_r_r_o_r(), _s_t_r_f_m_o_n(), _s_t_r_s_i_g_n_a_l(), _s_t_r_t_o_d(), _s_t_r_x_f_r_m(),
       _t_o_l_o_w_e_r(), _t_o_u_p_p_e_r(), _t_o_w_l_o_w_e_r(), _t_o_w_u_p_p_e_r(), _u_s_e_l_o_c_a_l_e(), _w_c_s_c_o_l_l(),
       _w_c_s_t_o_d(), _w_c_s_t_o_m_b_s(), _w_c_s_x_f_r_m(), _w_c_t_o_m_b()

       The Base Definitions volume of POSIX.1-2008, _C_h_a_p_t_e_r _7, _L_o_c_a_l_e, _C_h_a_p_t_e_r
       _8, _E_n_v_i_r_o_n_m_e_n_t _V_a_r_i_a_b_l_e_s, <<llaannggiinnffoo..hh>>, <<llooccaallee..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
       event of any discrepancy between this version and the original IEEE and
       The Open Group Standard, the original IEEE and The Open Group Standard
       is the referee document. The original Standard can be obtained online
       at http://www.unix.org/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2013                         SETLOCALE(3)
