man-pages/man3/setlocale.3.html
2021-03-31 01:06:50 +01:00

298 lines
7.4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of SETLOCALE</TITLE>
</HEAD><BODY>
<H1>SETLOCALE</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
setlocale - set the current locale
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/locale.h">locale.h</A>&gt;</B>
<B>char *setlocale(int </B><I>category</I><B>, const char *</B><I>locale</I><B>);</B>
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>setlocale</B>()
function is used to set or query the program's current locale.
<P>
If
<I>locale</I>
is not NULL,
the program's current locale is modified according to the arguments.
The argument
<I>category</I>
determines which parts of the program's current locale should be modified.
<TABLE>
<TR VALIGN=top><TD><B>Category</B></TD><TD><B>Governs</B><BR></TD></TR>
<TR VALIGN=top><TD><B>LC_ALL</B></TD><TD>All of the locale<BR></TD></TR>
<TR VALIGN=top><TD><B>LC_ADDRESS</B></TD><TD>
Formatting of addresses and
<BR>
geography-related items (*)
<BR></TD></TR>
<TR VALIGN=top><TD><B>LC_COLLATE</B></TD><TD>String collation<BR></TD></TR>
<TR VALIGN=top><TD><B>LC_CTYPE</B></TD><TD>Character classification<BR></TD></TR>
<TR VALIGN=top><TD><B>LC_IDENTIFICATION</B></TD><TD>Metadata describing the locale (*)<BR></TD></TR>
<TR VALIGN=top><TD><B>LC_MEASUREMENT</B></TD><TD>
Settings related to measurements
<BR>
(metric versus US customary) (*)
<BR></TD></TR>
<TR VALIGN=top><TD><B>LC_MESSAGES</B></TD><TD>Localizable natural-language messages<BR></TD></TR>
<TR VALIGN=top><TD><B>LC_MONETARY</B></TD><TD>Formatting of monetary values<BR></TD></TR>
<TR VALIGN=top><TD><B>LC_NAME</B></TD><TD>Formatting of salutations for persons (*)<BR></TD></TR>
<TR VALIGN=top><TD><B>LC_NUMERIC</B></TD><TD>Formatting of nonmonetary numeric values<BR></TD></TR>
<TR VALIGN=top><TD><B>LC_PAPER</B></TD><TD>Settings related to the standard paper size (*)<BR></TD></TR>
<TR VALIGN=top><TD><B>LC_TELEPHONE</B></TD><TD>Formats to be used with telephone services (*)<BR></TD></TR>
<TR VALIGN=top><TD><B>LC_TIME</B></TD><TD>Formatting of date and time values<BR></TD></TR>
</TABLE>
<P>
The categories marked with an asterisk in the above table
are GNU extensions.
For further information on these locale categories, see
<B><A HREF="/cgi-bin/man/man2html?7+locale">locale</A></B>(7).
<P>
The argument
<I>locale</I>
is a pointer to a character string containing the
required setting of
<I>category</I>.
Such a string is either a well-known constant like &quot;C&quot; or &quot;da_DK&quot;
(see below), or an opaque string that was returned by another call of
<B>setlocale</B>().
<P>
If
<I>locale</I>
is an empty string,
<B>&quot;&quot;</B>,
each part of the locale that should be modified is set according to the
environment variables.
The details are implementation-dependent.
For glibc, first (regardless of
<I>category</I>),
the environment variable
<B>LC_ALL</B>
is inspected,
next the environment variable with the same name as the category
(see the table above),
and finally the environment variable
<B>LANG</B>.
The first existing environment variable is used.
If its value is not a valid locale specification, the locale
is unchanged, and
<B>setlocale</B>()
returns NULL.
<P>
The locale
<B>C</B>
or
<B>POSIX</B>
is a portable locale;
it exists on all conforming systems.
<P>
A locale name is typically of the form
<I>language</I>[_<I>territory</I>][.<I>codeset</I>][@<I>modifier</I>],
where
<I>language</I>
is an ISO 639 language code,
<I>territory</I>
is an ISO 3166 country code, and
<I>codeset</I>
is a character set or encoding identifier like
<B>ISO-8859-1</B>
or
<B>UTF-8</B>.
For a list of all supported locales, try &quot;locale -a&quot; (see
<B><A HREF="/cgi-bin/man/man2html?1+locale">locale</A></B>(1)).
<P>
If
<I>locale</I>
is NULL, the current locale is only queried, not modified.
<P>
On startup of the main program, the portable
<B>C</B>
locale is selected as default.
A program may be made portable to all locales by calling:
<P>
setlocale(LC_ALL, &quot;&quot;);
<P>
after program initialization, by using the values returned
from a
<B><A HREF="/cgi-bin/man/man2html?3+localeconv">localeconv</A></B>(3)
call
for locale-dependent information, by using the multibyte and wide
character functions for text processing if
<B>MB_CUR_MAX &gt; 1</B>,
and by using
<B><A HREF="/cgi-bin/man/man2html?3+strcoll">strcoll</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+wcscoll">wcscoll</A></B>(3)
or
<B><A HREF="/cgi-bin/man/man2html?3+strxfrm">strxfrm</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+wcsxfrm">wcsxfrm</A></B>(3)
to compare strings.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
A successful call to
<B>setlocale</B>()
returns an opaque string that corresponds to the locale set.
This string may be allocated in static storage.
The string returned is such that a subsequent call with that string
and its associated category will restore that part of the process's
locale.
The return value is NULL if the request cannot be honored.
<A NAME="lbAF">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>setlocale</B>()
</TD><TD>Thread safety</TD><TD>MT-Unsafe const:locale env<BR></TD></TR>
</TABLE>
<P>
<A NAME="lbAG">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008, C89, C99.
<P>
The C standards specify only the categories
<B>LC_ALL</B>,
<B>LC_COLLATE</B>,
<B>LC_CTYPE</B>,
<B>LC_MONETARY</B>,
<B>LC_NUMERIC</B>,
and
<B>LC_TIME</B>.
POSIX.1 adds
<B>LC_MESSAGES</B>.
The remaining categories are GNU extensions.
<A NAME="lbAH">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?1+locale">locale</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?1+localedef">localedef</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?3+isalpha">isalpha</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+localeconv">localeconv</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+nl_langinfo">nl_langinfo</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+rpmatch">rpmatch</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+strcoll">strcoll</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+strftime">strftime</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?7+charsets">charsets</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?7+locale">locale</A></B>(7)
<A NAME="lbAI">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="4"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="5"><A HREF="#lbAF">ATTRIBUTES</A><DD>
<DT id="6"><A HREF="#lbAG">CONFORMING TO</A><DD>
<DT id="7"><A HREF="#lbAH">SEE ALSO</A><DD>
<DT id="8"><A HREF="#lbAI">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:56 GMT, March 31, 2021
</BODY>
</HTML>