您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

188 行
9.2KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>setlocale (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="setlocale (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="setlocale (The Red Hat newlib C Library)">
  9. <meta name="resource-type" content="document">
  10. <meta name="distribution" content="global">
  11. <meta name="Generator" content="makeinfo">
  12. <link href="index.html#Top" rel="start" title="Top">
  13. <link href="Document-Index.html#Document-Index" rel="index" title="Document Index">
  14. <link href="Document-Index.html#SEC_Contents" rel="contents" title="Table of Contents">
  15. <link href="Locale.html#Locale" rel="up" title="Locale">
  16. <link href="Reentrancy.html#Reentrancy" rel="next" title="Reentrancy">
  17. <link href="Locale.html#Locale" rel="prev" title="Locale">
  18. <style type="text/css">
  19. <!--
  20. a.summary-letter {text-decoration: none}
  21. blockquote.indentedblock {margin-right: 0em}
  22. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  23. blockquote.smallquotation {font-size: smaller}
  24. div.display {margin-left: 3.2em}
  25. div.example {margin-left: 3.2em}
  26. div.lisp {margin-left: 3.2em}
  27. div.smalldisplay {margin-left: 3.2em}
  28. div.smallexample {margin-left: 3.2em}
  29. div.smalllisp {margin-left: 3.2em}
  30. kbd {font-style: oblique}
  31. pre.display {font-family: inherit}
  32. pre.format {font-family: inherit}
  33. pre.menu-comment {font-family: serif}
  34. pre.menu-preformatted {font-family: serif}
  35. pre.smalldisplay {font-family: inherit; font-size: smaller}
  36. pre.smallexample {font-size: smaller}
  37. pre.smallformat {font-family: inherit; font-size: smaller}
  38. pre.smalllisp {font-size: smaller}
  39. span.nolinebreak {white-space: nowrap}
  40. span.roman {font-family: initial; font-weight: normal}
  41. span.sansserif {font-family: sans-serif; font-weight: normal}
  42. ul.no-bullet {list-style: none}
  43. -->
  44. </style>
  45. </head>
  46. <body lang="en">
  47. <a name="setlocale"></a>
  48. <div class="header">
  49. <p>
  50. Up: <a href="Locale.html#Locale" accesskey="u" rel="up">Locale</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  51. </div>
  52. <hr>
  53. <a name="setlocale_002c-localeconv_002d_002d_002dselect-or-query-locale"></a>
  54. <h3 class="section">9.1 <code>setlocale</code>, <code>localeconv</code>&mdash;select or query locale</h3>
  55. <a name="index-setlocale"></a>
  56. <a name="index-localeconv"></a>
  57. <a name="index-_005fsetlocale_005fr"></a>
  58. <a name="index-_005flocaleconv_005fr"></a>
  59. <p><strong>Synopsis</strong>
  60. </p><div class="example">
  61. <pre class="example">#include &lt;locale.h&gt;
  62. char *setlocale(int <var>category</var>, const char *<var>locale</var>);
  63. lconv *localeconv(void);
  64. char *_setlocale_r(void *<var>reent</var>,
  65. int <var>category</var>, const char *<var>locale</var>);
  66. lconv *_localeconv_r(void *<var>reent</var>);
  67. </pre></div>
  68. <p><strong>Description</strong><br>
  69. <code>setlocale</code> is the facility defined by ANSI C to condition the
  70. execution environment for international collating and formatting
  71. information; <code>localeconv</code> reports on the settings of the current
  72. locale.
  73. </p>
  74. <p>This is a minimal implementation, supporting only the required <code>&quot;POSIX&quot;</code>
  75. and <code>&quot;C&quot;</code> values for <var>locale</var>; strings representing other locales are not
  76. honored unless _MB_CAPABLE is defined.
  77. </p>
  78. <p>If _MB_CAPABLE is defined, POSIX locale strings are allowed, following
  79. the form
  80. </p>
  81. <p>language[_TERRITORY][.charset][@modifier]
  82. </p>
  83. <p><code>&quot;language&quot;</code> is a two character string per ISO 639, or, if not available
  84. for a given language, a three character string per ISO 639-3.
  85. <code>&quot;TERRITORY&quot;</code> is a country code per ISO 3166. For <code>&quot;charset&quot;</code> and
  86. <code>&quot;modifier&quot;</code> see below.
  87. </p>
  88. <p>Additionally to the POSIX specifier, the following extension is supported
  89. for backward compatibility with older implementations using newlib:
  90. <code>&quot;C-charset&quot;</code>.
  91. Instead of <code>&quot;C-&quot;</code>, you can also specify <code>&quot;C.&quot;</code>. Both variations allow
  92. to specify language neutral locales while using other charsets than ASCII,
  93. for instance <code>&quot;C.UTF-8&quot;</code>, which keeps all settings as in the C locale,
  94. but uses the UTF-8 charset.
  95. </p>
  96. <p>The following charsets are recognized:
  97. <code>&quot;UTF-8&quot;</code>, <code>&quot;JIS&quot;</code>, <code>&quot;EUCJP&quot;</code>, <code>&quot;SJIS&quot;</code>, <code>&quot;KOI8-R&quot;</code>, <code>&quot;KOI8-U&quot;</code>,
  98. <code>&quot;GEORGIAN-PS&quot;</code>, <code>&quot;PT154&quot;</code>, <code>&quot;TIS-620&quot;</code>, <code>&quot;ISO-8859-x&quot;</code> with
  99. 1 &lt;= x &lt;= 16, or <code>&quot;CPxxx&quot;</code> with xxx in [437, 720, 737, 775, 850, 852, 855,
  100. 857, 858, 862, 866, 874, 932, 1125, 1250, 1251, 1252, 1253, 1254, 1255, 1256,
  101. 1257, 1258].
  102. </p>
  103. <p>Charsets are case insensitive. For instance, <code>&quot;EUCJP&quot;</code> and <code>&quot;eucJP&quot;</code>
  104. are equivalent. Charset names with dashes can also be written without
  105. dashes, as in <code>&quot;UTF8&quot;</code>, <code>&quot;iso88591&quot;</code> or <code>&quot;koi8r&quot;</code>. <code>&quot;EUCJP&quot;</code> and
  106. <code>&quot;EUCKR&quot;</code> are also recognized with dash, <code>&quot;EUC-JP&quot;</code> and <code>&quot;EUC-KR&quot;</code>.
  107. </p>
  108. <p>Full support for all of the above charsets requires that newlib has been
  109. build with multibyte support and support for all ISO and Windows Codepage.
  110. Otherwise all singlebyte charsets are simply mapped to ASCII. Right now,
  111. only newlib for Cygwin is built with full charset support by default.
  112. Under Cygwin, this implementation additionally supports the charsets
  113. <code>&quot;GBK&quot;</code>, <code>&quot;GB2312&quot;</code>, <code>&quot;eucCN&quot;</code>, <code>&quot;eucKR&quot;</code>, and <code>&quot;Big5&quot;</code>. Cygwin
  114. does not support <code>&quot;JIS&quot;</code>.
  115. </p>
  116. <p>Cygwin additionally supports locales from the file
  117. /usr/share/locale/locale.alias.
  118. </p>
  119. <p>(<code>&quot;&quot;</code> is also accepted; if given, the settings are read from the
  120. corresponding LC_* environment variables and $LANG according to POSIX rules.)
  121. </p>
  122. <p>This implementation also supports the modifiers <code>&quot;cjknarrow&quot;</code> and
  123. <code>&quot;cjkwide&quot;</code>, which affect how the functions <code>wcwidth</code> and <code>wcswidth</code>
  124. handle characters from the &quot;CJK Ambiguous Width&quot; category of characters
  125. described at http://www.unicode.org/reports/tr11/#Ambiguous.
  126. These characters have a width of 1 for singlebyte charsets and a width of 2
  127. for multibyte charsets other than UTF-8.
  128. For UTF-8, their width depends on the language specifier:
  129. it is 2 for <code>&quot;zh&quot;</code> (Chinese), <code>&quot;ja&quot;</code> (Japanese), and <code>&quot;ko&quot;</code> (Korean),
  130. and 1 for everything else. Specifying <code>&quot;cjknarrow&quot;</code> or <code>&quot;cjkwide&quot;</code>
  131. forces a width of 1 or 2, respectively, independent of charset and language.
  132. </p>
  133. <p>If you use <code>NULL</code> as the <var>locale</var> argument, <code>setlocale</code> returns a
  134. pointer to the string representing the current locale. The acceptable
  135. values for <var>category</var> are defined in &lsquo;<code>locale.h</code>&rsquo; as macros
  136. beginning with <code>&quot;LC_&quot;</code>.
  137. </p>
  138. <p><code>localeconv</code> returns a pointer to a structure (also defined in
  139. &lsquo;<code>locale.h</code>&rsquo;) describing the locale-specific conventions currently
  140. in effect.
  141. </p>
  142. <p><code>_localeconv_r</code> and <code>_setlocale_r</code> are reentrant versions of
  143. <code>localeconv</code> and <code>setlocale</code> respectively. The extra argument
  144. <var>reent</var> is a pointer to a reentrancy structure.
  145. </p>
  146. <br>
  147. <p><strong>Returns</strong><br>
  148. A successful call to <code>setlocale</code> returns a pointer to a string
  149. associated with the specified category for the new locale. The string
  150. returned by <code>setlocale</code> is such that a subsequent call using that
  151. string will restore that category (or all categories in case of LC_ALL),
  152. to that state. The application shall not modify the string returned
  153. which may be overwritten by a subsequent call to <code>setlocale</code>.
  154. On error, <code>setlocale</code> returns <code>NULL</code>.
  155. </p>
  156. <p><code>localeconv</code> returns a pointer to a structure of type <code>lconv</code>,
  157. which describes the formatting and collating conventions in effect (in
  158. this implementation, always those of the C locale).
  159. </p>
  160. <br>
  161. <p><strong>Portability</strong><br>
  162. ANSI C requires <code>setlocale</code>, but the only locale required across all
  163. implementations is the C locale.
  164. </p>
  165. <br>
  166. <p><strong>Notes</strong><br>
  167. There is no ISO-8859-12 codepage. It&rsquo;s also refused by this implementation.
  168. </p>
  169. <p>No supporting OS subroutines are required.
  170. </p>
  171. <br>
  172. <hr>
  173. <div class="header">
  174. <p>
  175. Up: <a href="Locale.html#Locale" accesskey="u" rel="up">Locale</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  176. </div>
  177. </body>
  178. </html>