369 lines
15 KiB
HTML
369 lines
15 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
|
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
|
<title>setlocale</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="setlocale"></a> <a name="tag_03_655"></a><!-- setlocale -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_03_655_01"></a>NAME</h4>
|
|
|
|
<blockquote>setlocale - set program locale</blockquote>
|
|
|
|
<h4><a name="tag_03_655_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<p><code><tt>#include <<a href="../basedefs/locale.h.html">locale.h</a>><br>
|
|
<br>
|
|
char *setlocale(int</tt> <i>category</i><tt>, const char *</tt><i>locale</i><tt>);<br>
|
|
</tt></code></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_655_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<div class="box"><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]"
|
|
border="0"> 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 IEEE Std 1003.1-2001 defers to
|
|
the ISO C standard. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></div>
|
|
|
|
<p>The <i>setlocale</i>() function selects the appropriate piece of the program's locale, as specified by the <i>category</i> and
|
|
<i>locale</i> arguments, and may be used to change or query the program's entire locale or portions thereof. The value
|
|
<i>LC_ALL</i> for <i>category</i> names the program's entire locale; other values for <i>category</i> name only a part of the
|
|
program's locale:</p>
|
|
|
|
<dl compact>
|
|
<dt><i>LC_COLLATE</i></dt>
|
|
|
|
<dd>Affects the behavior of regular expressions and the collation functions.</dd>
|
|
|
|
<dt><i>LC_CTYPE</i></dt>
|
|
|
|
<dd>Affects the behavior of regular expressions, character classification, character conversion functions, and wide-character
|
|
functions.</dd>
|
|
|
|
<dt><i>LC_MESSAGES</i></dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
Affects what strings are expected by commands and utilities as affirmative or negative responses. <img src="../images/opt-end.gif"
|
|
alt="[Option End]" border="0">
|
|
|
|
<p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
It also affects what strings are given by commands and utilities as affirmative or negative responses, and the content of messages.
|
|
<img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
|
|
</dd>
|
|
|
|
<dt><i>LC_MONETARY</i></dt>
|
|
|
|
<dd>Affects the behavior of functions that handle monetary values.</dd>
|
|
|
|
<dt><i>LC_NUMERIC</i></dt>
|
|
|
|
<dd>Affects the behavior of functions that handle numeric values.</dd>
|
|
|
|
<dt><i>LC_TIME</i></dt>
|
|
|
|
<dd>Affects the behavior of the time conversion functions.</dd>
|
|
</dl>
|
|
|
|
<p>The <i>locale</i> argument is a pointer to a character string containing the required setting of <i>category</i>. The contents
|
|
of this string are implementation-defined. In addition, the following preset values of <i>locale</i> are defined for all settings
|
|
of <i>category</i>:</p>
|
|
|
|
<dl compact>
|
|
<dt>"POSIX"</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
Specifies the minimal environment for C-language translation called the POSIX locale. If <i>setlocale</i>() is not invoked, the
|
|
POSIX locale is the default at entry to <i>main</i>(). <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
|
|
<dt>"C"</dt>
|
|
|
|
<dd>Equivalent to <tt>"POSIX"</tt> .</dd>
|
|
|
|
<dt>""</dt>
|
|
<dd>Specifies an implementation-defined native environment. <sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src=
|
|
"../images/opt-start.gif" alt="[Option Start]" border="0"> This corresponds to the value of the associated environment
|
|
variables, <i>LC_*</i> and <i>LANG ;</i> see the Base Definitions volume of IEEE Std 1003.1-2001, <a href=
|
|
"../basedefs/xbd_chap07.html">Chapter 7, Locale</a> and the Base Definitions volume of IEEE Std 1003.1-2001, <a href=
|
|
"../basedefs/xbd_chap08.html">Chapter 8, Environment Variables</a>. <img src="../images/opt-end.gif" alt="[Option End]" border=
|
|
"0"></dd>
|
|
|
|
<dt>A null pointer</dt>
|
|
|
|
<dd>Used to direct <i>setlocale</i>() to query the current internationalized environment and return the name of the
|
|
<i>locale</i>().</dd>
|
|
</dl>
|
|
|
|
<p><sup>[<a href="javascript:open_code('THR')">THR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The locale state is common to all threads within a process. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_655_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>Upon successful completion, <i>setlocale</i>() shall return the string associated with the specified category for the new
|
|
locale. Otherwise, <i>setlocale</i>() shall return a null pointer and the program's locale is not changed.</p>
|
|
|
|
<p>A null pointer for <i>locale</i> causes <i>setlocale</i>() to return a pointer to the string associated with the <i>category</i>
|
|
for the program's current locale. The program's locale shall not be changed.</p>
|
|
|
|
<p>The string returned by <i>setlocale</i>() is such that a subsequent call with that string and its associated <i>category</i>
|
|
shall restore that part of the program's locale. The application shall not modify the string returned which may be overwritten by a
|
|
subsequent call to <i>setlocale</i>().</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_655_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>No errors are defined.</p>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_03_655_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_655_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>The following code illustrates how a program can initialize the international environment for one language, while selectively
|
|
modifying the program's locale such that regular expressions and string operations can be applied to text recorded in a different
|
|
language:</p>
|
|
|
|
<pre>
|
|
<tt>setlocale(LC_ALL, "De");
|
|
setlocale(LC_COLLATE, "Fr@dict");
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>Internationalized programs must call <i>setlocale</i>() to initiate a specific language operation. This can be done by calling
|
|
<i>setlocale</i>() as follows:</p>
|
|
|
|
<pre>
|
|
<tt>setlocale(LC_ALL, "");
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>Changing the setting of <i>LC_MESSAGES</i> has no effect on catalogs that have already been opened by calls to <a href=
|
|
"../functions/catopen.html"><i>catopen</i>()</a>.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_655_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>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>international environment</i>. The international environment is a
|
|
repository of information that affects the behavior of certain functionality, namely:</p>
|
|
|
|
<ol>
|
|
<li>
|
|
<p>Character handling</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>Collating</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>Date/time formatting</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>Numeric editing</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>Monetary formatting</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>Messaging</p>
|
|
</li>
|
|
</ol>
|
|
|
|
<p>The <i>setlocale</i>() function provides the application developer with the ability to set all or portions, called
|
|
<i>categories</i>, of the international environment. These categories correspond to the areas of functionality mentioned above. The
|
|
syntax for <i>setlocale</i>() is as follows:</p>
|
|
|
|
<pre>
|
|
<tt>char *setlocale(int</tt> <i>category</i><tt>, const char *</tt><i>locale</i><tt>);
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>where <i>category</i> is the name of one of following categories, namely:</p>
|
|
|
|
<blockquote>
|
|
<pre>
|
|
<i>LC_COLLATE
|
|
|
|
LC_CTYPE
|
|
|
|
LC_MESSAGES
|
|
|
|
LC_MONETARY
|
|
|
|
LC_NUMERIC
|
|
|
|
LC_TIME</i>
|
|
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<p>In addition, a special value called <i>LC_ALL</i> directs <i>setlocale</i>() to set all categories.</p>
|
|
|
|
<p>There are two primary uses of <i>setlocale</i>():</p>
|
|
|
|
<ol>
|
|
<li>
|
|
<p>Querying the international environment to find out what it is set to</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>Setting the international environment, or <i>locale</i>, to a specific value</p>
|
|
</li>
|
|
</ol>
|
|
|
|
<p>The behavior of <i>setlocale</i>() 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.</p>
|
|
|
|
<p>To query the international environment, <i>setlocale</i>() is invoked with a specific category and the NULL pointer as the
|
|
locale. The NULL pointer is a special directive to <i>setlocale</i>() that tells it to query rather than set the international
|
|
environment. The following syntax is used to query the name of the international environment:</p>
|
|
|
|
<pre>
|
|
<tt>setlocale({LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY, \
|
|
LC_NUMERIC, LC_TIME},(char *) NULL);
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>The <i>setlocale</i>() function shall return the string corresponding to the current international environment. This value may
|
|
be used by a subsequent call to <i>setlocale</i>() to reset the international environment to this value. However, it should be
|
|
noted that the return value from <i>setlocale</i>() 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 <i>setlocale</i>()). Therefore, if the purpose of calling
|
|
<i>setlocale</i>() 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 <b>char</b> in the calling program.</p>
|
|
|
|
<p>There are three ways to set the international environment with <i>setlocale</i>():</p>
|
|
|
|
<dl compact>
|
|
<dt><i>setlocale</i>(<i>category</i>, <i>string</i>)</dt>
|
|
|
|
<dd><br>
|
|
This usage sets a specific <i>category</i> in the international environment to a specific value corresponding to the value of the
|
|
<i>string</i>. A specific example is provided below:
|
|
|
|
<pre>
|
|
<tt>setlocale(LC_ALL, "fr_FR.ISO-8859-1");
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>In this example, all categories of the international environment are set to the locale corresponding to the string
|
|
<tt>"fr_FR.ISO-8859-1"</tt> , or to the French language as spoken in France using the ISO/IEC 8859-1:1998 standard
|
|
codeset.</p>
|
|
|
|
<p>If the string does not correspond to a valid locale, <i>setlocale</i>() shall return a NULL pointer and the international
|
|
environment is not changed. Otherwise, <i>setlocale</i>() shall return the name of the locale just set.</p>
|
|
</dd>
|
|
|
|
<dt><i>setlocale</i>(<i>category</i>, "C")</dt>
|
|
|
|
<dd><br>
|
|
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.</dd>
|
|
|
|
<dt><i>setlocale</i>(<i>category</i>, "")</dt>
|
|
|
|
<dd><br>
|
|
This sets a specific category to an implementation-defined default. This corresponds to the value of the environment
|
|
variables.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_655_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_655_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="exec.html"><i><a href="../functions/exec.html">exec</a></i>()</a> , <a href="isalnum.html"><i>isalnum</i>()</a> , <a
|
|
href="isalpha.html"><i>isalpha</i>()</a> , <a href="isblank.html"><i>isblank</i>()</a> , <a href=
|
|
"iscntrl.html"><i>iscntrl</i>()</a> , <a href="isdigit.html"><i>isdigit</i>()</a> , <a href="isgraph.html"><i>isgraph</i>()</a> ,
|
|
<a href="islower.html"><i>islower</i>()</a> , <a href="isprint.html"><i>isprint</i>()</a> , <a href=
|
|
"ispunct.html"><i>ispunct</i>()</a> , <a href="isspace.html"><i>isspace</i>()</a> , <a href="isupper.html"><i>isupper</i>()</a> ,
|
|
<a href="iswalnum.html"><i>iswalnum</i>()</a> , <a href="iswalpha.html"><i>iswalpha</i>()</a> , <a href=
|
|
"iswblank.html"><i>iswblank</i>()</a> , <a href="iswcntrl.html"><i>iswcntrl</i>()</a> , <a href=
|
|
"iswctype.html"><i>iswctype</i>()</a> , <a href="iswdigit.html"><i>iswdigit</i>()</a> , <a href=
|
|
"iswgraph.html"><i>iswgraph</i>()</a> , <a href="iswlower.html"><i>iswlower</i>()</a> , <a href=
|
|
"iswprint.html"><i>iswprint</i>()</a> , <a href="iswpunct.html"><i>iswpunct</i>()</a> , <a href=
|
|
"iswspace.html"><i>iswspace</i>()</a> , <a href="iswupper.html"><i>iswupper</i>()</a> , <a href=
|
|
"iswxdigit.html"><i>iswxdigit</i>()</a> , <a href="isxdigit.html"><i>isxdigit</i>()</a> , <a href=
|
|
"localeconv.html"><i>localeconv</i>()</a> , <a href="mblen.html"><i>mblen</i>()</a> , <a href="mbstowcs.html"><i>mbstowcs</i>()</a>
|
|
, <a href="mbtowc.html"><i>mbtowc</i>()</a> , <a href="nl_langinfo.html"><i>nl_langinfo</i>()</a> , <a href=
|
|
"printf.html"><i>printf</i>()</a> , <a href="scanf.html"><i>scanf</i>()</a> , <a href="#">setlocale</a> , <a href=
|
|
"strcoll.html"><i>strcoll</i>()</a> , <a href="strerror.html"><i>strerror</i>()</a> , <a href="strfmon.html"><i>strfmon</i>()</a> ,
|
|
<a href="strtod.html"><i>strtod</i>()</a> , <a href="strxfrm.html"><i>strxfrm</i>()</a> , <a href=
|
|
"tolower.html"><i>tolower</i>()</a> , <a href="toupper.html"><i>toupper</i>()</a> , <a href="towlower.html"><i>towlower</i>()</a> ,
|
|
<a href="towupper.html"><i>towupper</i>()</a> , <a href="wcscoll.html"><i>wcscoll</i>()</a> , <a href=
|
|
"wcstod.html"><i>wcstod</i>()</a> , <a href="wcstombs.html"><i>wcstombs</i>()</a> , <a href="wcsxfrm.html"><i>wcsxfrm</i>()</a> ,
|
|
<a href="wctomb.html"><i>wctomb</i>()</a> , the Base Definitions volume of IEEE Std 1003.1-2001, <a href=
|
|
"../basedefs/langinfo.h.html"><i><langinfo.h></i></a>, <a href="../basedefs/locale.h.html"><i><locale.h></i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_655_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 3.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_655_12"></a>Issue 5</h4>
|
|
|
|
<blockquote>
|
|
<p>The DESCRIPTION is updated for alignment with the POSIX Threads Extension.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_655_13"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>Extensions beyond the ISO C standard are marked.</p>
|
|
|
|
<p>The DESCRIPTION is updated to avoid use of the term "must" for application requirements.</p>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
|
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
|
]</font></center>
|
|
|
|
<!--footer end-->
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|