logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

setlocale.3p (13318B)


  1. '\" et
  2. .TH SETLOCALE "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. setlocale
  12. \(em set program locale
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <locale.h>
  17. .P
  18. char *setlocale(int \fIcategory\fP, const char *\fIlocale\fP);
  19. .fi
  20. .SH DESCRIPTION
  21. The functionality described on this reference page is aligned with the
  22. ISO\ C standard. Any conflict between the requirements described here and the
  23. ISO\ C standard is unintentional. This volume of POSIX.1\(hy2017 defers to the ISO\ C standard.
  24. .P
  25. The
  26. \fIsetlocale\fR()
  27. function selects the appropriate piece of the global locale, as specified
  28. by the
  29. .IR category
  30. and
  31. .IR locale
  32. arguments, and can be used to change or query the entire global locale
  33. or portions thereof. The value LC_ALL for
  34. .IR category
  35. names the entire global locale; other values for
  36. .IR category
  37. name only a part of the global locale:
  38. .IP LC_COLLATE 12
  39. Affects the behavior of regular expressions and the collation
  40. functions.
  41. .IP LC_CTYPE 12
  42. Affects the behavior of regular expressions, character classification,
  43. character conversion functions, and wide-character functions.
  44. .IP LC_MESSAGES 12
  45. Affects the affirmative and negative response expressions returned by
  46. \fInl_langinfo\fR()
  47. and the way message catalogs are located. It may also affect the
  48. behavior of functions that return or write message strings.
  49. .IP LC_MONETARY 12
  50. Affects the behavior of functions that handle monetary values.
  51. .IP LC_NUMERIC 12
  52. Affects the behavior of functions that handle numeric values.
  53. .IP LC_TIME 12
  54. Affects the behavior of the time conversion functions.
  55. .P
  56. The
  57. .IR locale
  58. argument is a pointer to a character string containing the required
  59. setting of
  60. .IR category .
  61. The contents of this string are implementation-defined. In addition,
  62. the following preset values of
  63. .IR locale
  64. are defined for all settings of
  65. .IR category :
  66. .IP "\&\(dqPOSIX\(dq" 12
  67. Specifies the minimal environment for C-language translation called the
  68. POSIX locale. The POSIX locale is the default global locale at entry to
  69. \fImain\fR().
  70. .IP "\&\(dqC\(dq" 12
  71. Equivalent to
  72. .BR \(dqPOSIX\(dq .
  73. .IP "\&\(dq\|\(dq" 12
  74. Specifies an implementation-defined native environment.
  75. The determination of the name of the new locale for the specified
  76. category depends on the value of the associated environment
  77. variables,
  78. .IR LC_*
  79. and
  80. .IR LANG ;
  81. see the Base Definitions volume of POSIX.1\(hy2017,
  82. .IR "Chapter 7" ", " "Locale"
  83. and
  84. .IR "Chapter 8" ", " "Environment Variables".
  85. .IP "A\ null\ pointer" 12
  86. Directs
  87. \fIsetlocale\fR()
  88. to query the current global locale setting and return the name
  89. of the locale if
  90. .IR category
  91. is not LC_ALL, or a string which encodes the locale name(s) for all of
  92. the individual categories if
  93. .IR category
  94. is LC_ALL.
  95. .P
  96. Setting all of the categories of the global locale is similar to
  97. successively setting each individual category of the global locale, except
  98. that all error checking is done before any actions are performed. To
  99. set all the categories of the global locale,
  100. \fIsetlocale\fR()
  101. can be invoked as:
  102. .sp
  103. .RS 4
  104. .nf
  105. setlocale(LC_ALL, "");
  106. .fi
  107. .P
  108. .RE
  109. .P
  110. In this case,
  111. \fIsetlocale\fR()
  112. shall first verify that the values of all the environment variables it
  113. needs according to the precedence rules (described in the Base Definitions volume of POSIX.1\(hy2017,
  114. .IR "Chapter 8" ", " "Environment Variables")
  115. indicate supported locales. If the value of any of these environment
  116. variable searches yields a locale that is not supported (and non-null),
  117. \fIsetlocale\fR()
  118. shall return a null pointer and the global locale shall not be changed. If
  119. all environment variables name supported locales,
  120. \fIsetlocale\fR()
  121. shall proceed as if it had been called for each category, using the
  122. appropriate value from the associated environment variable or from the
  123. implementation-defined default if there is no such value.
  124. .P
  125. The global locale established using
  126. \fIsetlocale\fR()
  127. shall only be used in threads for which no current locale has been
  128. set using
  129. \fIuselocale\fR()
  130. or whose current locale has been set to the global locale using
  131. .IR uselocale (LC_GLOBAL_LOCALE) .
  132. .P
  133. The implementation shall behave as if no function defined in this volume of POSIX.1\(hy2017 calls
  134. \fIsetlocale\fR().
  135. .P
  136. The
  137. \fIsetlocale\fR()
  138. function need not be thread-safe.
  139. .SH "RETURN VALUE"
  140. Upon successful completion,
  141. \fIsetlocale\fR()
  142. shall return the string associated with the specified category for the
  143. new locale. Otherwise,
  144. \fIsetlocale\fR()
  145. shall return a null pointer and the global locale shall not be changed.
  146. .P
  147. A null pointer for
  148. .IR locale
  149. shall cause
  150. \fIsetlocale\fR()
  151. to return a pointer to the string associated with the specified
  152. .IR category
  153. for the current global locale. The global locale shall not be changed.
  154. .P
  155. The string returned by
  156. \fIsetlocale\fR()
  157. is such that a subsequent call with that string and its associated
  158. .IR category
  159. shall restore that part of the global locale. The application shall
  160. not modify the string returned.
  161. The returned string pointer might be invalidated or
  162. the string content might be overwritten by a subsequent call to
  163. \fIsetlocale\fR().
  164. The returned pointer might also be invalidated if the calling
  165. thread is terminated.
  166. .SH ERRORS
  167. No errors are defined.
  168. .LP
  169. .IR "The following sections are informative."
  170. .SH EXAMPLES
  171. None.
  172. .SH "APPLICATION USAGE"
  173. The following code illustrates how a program can initialize the
  174. international environment for one language, while selectively modifying
  175. the global locale such that regular expressions and string operations
  176. can be applied to text recorded in a different language:
  177. .sp
  178. .RS 4
  179. .nf
  180. setlocale(LC_ALL, "De");
  181. setlocale(LC_COLLATE, "Fr@dict");
  182. .fi
  183. .P
  184. .RE
  185. .P
  186. Internationalized programs can initiate language operation according
  187. to environment variable settings (see the Base Definitions volume of POSIX.1\(hy2017,
  188. .IR "Section 8.2" ", " "Internationalization Variables")
  189. by calling
  190. \fIsetlocale\fR()
  191. as follows:
  192. .sp
  193. .RS 4
  194. .nf
  195. setlocale(LC_ALL, "");
  196. .fi
  197. .P
  198. .RE
  199. .P
  200. Changing the setting of
  201. .IR LC_MESSAGES
  202. has no effect on catalogs that have already been opened by calls to
  203. \fIcatopen\fR().
  204. .P
  205. In order to make use of different locale settings while multiple
  206. threads are running, applications should use
  207. \fIuselocale\fR()
  208. in preference to
  209. \fIsetlocale\fR().
  210. .SH RATIONALE
  211. References to the international environment or locale in the following
  212. text relate to the global locale for the process. This can be overridden
  213. for individual threads using
  214. \fIuselocale\fR().
  215. .P
  216. The ISO\ C standard
  217. defines a collection of functions to support internationalization.
  218. One of the most significant aspects of these functions is a facility
  219. to set and query the \fIinternational environment\fP.
  220. The international environment is a repository of information that
  221. affects the behavior of certain functionality, namely:
  222. .IP " 1." 4
  223. Character handling
  224. .IP " 2." 4
  225. Collating
  226. .IP " 3." 4
  227. Date/time formatting
  228. .IP " 4." 4
  229. Numeric editing
  230. .IP " 5." 4
  231. Monetary formatting
  232. .IP " 6." 4
  233. Messaging
  234. .P
  235. The
  236. \fIsetlocale\fR()
  237. function provides the application developer with the ability to set all
  238. or portions, called \fIcategories\fP, of the international environment.
  239. These categories correspond to the areas of functionality mentioned
  240. above. The syntax for
  241. \fIsetlocale\fR()
  242. is as follows:
  243. .sp
  244. .RS 4
  245. .nf
  246. char *setlocale(int \fIcategory\fP, const char *\fIlocale\fP);
  247. .fi
  248. .P
  249. .RE
  250. .P
  251. where
  252. .IR category
  253. is the name of one of following categories, namely:
  254. .sp
  255. .RS
  256. LC_COLLATE
  257. LC_CTYPE
  258. LC_MESSAGES
  259. LC_MONETARY
  260. LC_NUMERIC
  261. LC_TIME
  262. .RE
  263. .P
  264. In addition, a special value called LC_ALL
  265. directs
  266. \fIsetlocale\fR()
  267. to set all categories.
  268. .P
  269. There are two primary uses of
  270. \fIsetlocale\fR():
  271. .IP " 1." 4
  272. Querying the international environment to find out what it is set to
  273. .IP " 2." 4
  274. Setting the international environment, or
  275. .IR locale ,
  276. to a specific value
  277. .P
  278. The behavior of
  279. \fIsetlocale\fR()
  280. in these two areas is described below. Since it is difficult to
  281. describe the behavior in words, examples are used to illustrate the
  282. behavior of specific uses.
  283. .P
  284. To query the international environment,
  285. \fIsetlocale\fR()
  286. is invoked with a specific category and the null pointer as the
  287. locale. The null pointer is a special directive to
  288. \fIsetlocale\fR()
  289. that tells it to query rather than set the international environment.
  290. The following syntax is used to query the name of the international
  291. environment:
  292. .sp
  293. .RS 4
  294. .nf
  295. setlocale({LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY, \e
  296. LC_NUMERIC, LC_TIME},(char *) NULL);
  297. .fi
  298. .P
  299. .RE
  300. .P
  301. The
  302. \fIsetlocale\fR()
  303. function shall return the string corresponding to the current
  304. international environment. This value may be used by a subsequent call to
  305. \fIsetlocale\fR()
  306. to reset the international environment to this value. However, it
  307. should be noted that the return value from
  308. \fIsetlocale\fR()
  309. may be a pointer to a static area within the function and is not
  310. guaranteed to remain unchanged (that is, it may be modified by a
  311. subsequent call to
  312. \fIsetlocale\fR()).
  313. Therefore, if the purpose of calling
  314. \fIsetlocale\fR()
  315. is to save the value of the current international environment so it can
  316. be changed and reset later, the return value should be copied to an
  317. array of
  318. .BR char
  319. in the calling program.
  320. .P
  321. There are three ways to set the international environment with
  322. \fIsetlocale\fR():
  323. .IP "\fIsetlocale\fP(\fIcategory\fP,\ \fIstring\fP)" 6
  324. .br
  325. This usage sets a specific
  326. .IR category
  327. in the international environment to a specific value corresponding to
  328. the value of the
  329. .IR string .
  330. A specific example is provided below:
  331. .RS 6
  332. .sp
  333. .RS 4
  334. .nf
  335. setlocale(LC_ALL, "fr_FR.ISO-8859-1");
  336. .fi
  337. .P
  338. .RE
  339. .P
  340. In this example, all categories of the international environment are
  341. set to the locale corresponding to the string
  342. .BR \(dqfr_FR.ISO-8859-1\(dq ,
  343. or to the French language as spoken in France using the ISO/IEC\ 8859\(hy1:\|1998 standard codeset.
  344. .P
  345. If the string does not correspond to a valid locale,
  346. \fIsetlocale\fR()
  347. shall return a null pointer and the international environment is not
  348. changed. Otherwise,
  349. \fIsetlocale\fR()
  350. shall return the name of the locale just set.
  351. .RE
  352. .IP "\&\fIsetlocale\fP(\fIcategory\fP,\ \(dqC\(dq)" 6
  353. .br
  354. The ISO\ C standard states that one locale must exist on all conforming
  355. implementations. The name of the locale is C and corresponds to a
  356. minimal international environment needed to support the C programming
  357. language.
  358. .IP "\&\fIsetlocale\fP(\fIcategory\fP,\ \(dq\^\(dq)" 6
  359. .br
  360. This sets a specific category to an implementation-defined default.
  361. This corresponds to the value of the environment variables.
  362. .SH "FUTURE DIRECTIONS"
  363. None.
  364. .SH "SEE ALSO"
  365. .ad l
  366. .IR "\fIcatopen\fR\^(\|)",
  367. .IR "\fIexec\fR\^",
  368. .IR "\fIfprintf\fR\^(\|)",
  369. .IR "\fIfscanf\fR\^(\|)",
  370. .IR "\fIisalnum\fR\^(\|)",
  371. .IR "\fIisalpha\fR\^(\|)",
  372. .IR "\fIisblank\fR\^(\|)",
  373. .IR "\fIiscntrl\fR\^(\|)",
  374. .IR "\fIisdigit\fR\^(\|)",
  375. .IR "\fIisgraph\fR\^(\|)",
  376. .IR "\fIislower\fR\^(\|)",
  377. .IR "\fIisprint\fR\^(\|)",
  378. .IR "\fIispunct\fR\^(\|)",
  379. .IR "\fIisspace\fR\^(\|)",
  380. .IR "\fIisupper\fR\^(\|)",
  381. .IR "\fIiswalnum\fR\^(\|)",
  382. .IR "\fIiswalpha\fR\^(\|)",
  383. .IR "\fIiswblank\fR\^(\|)",
  384. .IR "\fIiswcntrl\fR\^(\|)",
  385. .IR "\fIiswctype\fR\^(\|)",
  386. .IR "\fIiswdigit\fR\^(\|)",
  387. .IR "\fIiswgraph\fR\^(\|)",
  388. .IR "\fIiswlower\fR\^(\|)",
  389. .IR "\fIiswprint\fR\^(\|)",
  390. .IR "\fIiswpunct\fR\^(\|)",
  391. .IR "\fIiswspace\fR\^(\|)",
  392. .IR "\fIiswupper\fR\^(\|)",
  393. .IR "\fIiswxdigit\fR\^(\|)",
  394. .IR "\fIisxdigit\fR\^(\|)",
  395. .IR "\fIlocaleconv\fR\^(\|)",
  396. .IR "\fImblen\fR\^(\|)",
  397. .IR "\fImbstowcs\fR\^(\|)",
  398. .IR "\fImbtowc\fR\^(\|)",
  399. .IR "\fInewlocale\fR\^(\|)",
  400. .IR "\fInl_langinfo\fR\^(\|)",
  401. .IR "\fIperror\fR\^(\|)",
  402. .IR "\fIpsiginfo\fR\^(\|)",
  403. .IR "\fIstrcoll\fR\^(\|)",
  404. .IR "\fIstrerror\fR\^(\|)",
  405. .IR "\fIstrfmon\fR\^(\|)",
  406. .IR "\fIstrsignal\fR\^(\|)",
  407. .IR "\fIstrtod\fR\^(\|)",
  408. .IR "\fIstrxfrm\fR\^(\|)",
  409. .IR "\fItolower\fR\^(\|)",
  410. .IR "\fItoupper\fR\^(\|)",
  411. .IR "\fItowlower\fR\^(\|)",
  412. .IR "\fItowupper\fR\^(\|)",
  413. .IR "\fIuselocale\fR\^(\|)",
  414. .IR "\fIwcscoll\fR\^(\|)",
  415. .IR "\fIwcstod\fR\^(\|)",
  416. .IR "\fIwcstombs\fR\^(\|)",
  417. .IR "\fIwcsxfrm\fR\^(\|)",
  418. .IR "\fIwctomb\fR\^(\|)"
  419. .ad b
  420. .P
  421. The Base Definitions volume of POSIX.1\(hy2017,
  422. .IR "Chapter 7" ", " "Locale",
  423. .IR "Chapter 8" ", " "Environment Variables",
  424. .IR "\fB<langinfo.h>\fP",
  425. .IR "\fB<locale.h>\fP"
  426. .\"
  427. .SH COPYRIGHT
  428. Portions of this text are reprinted and reproduced in electronic form
  429. from IEEE Std 1003.1-2017, Standard for Information Technology
  430. -- Portable Operating System Interface (POSIX), The Open Group Base
  431. Specifications Issue 7, 2018 Edition,
  432. Copyright (C) 2018 by the Institute of
  433. Electrical and Electronics Engineers, Inc and The Open Group.
  434. In the event of any discrepancy between this version and the original IEEE and
  435. The Open Group Standard, the original IEEE and The Open Group Standard
  436. is the referee document. The original Standard can be obtained online at
  437. http://www.opengroup.org/unix/online.html .
  438. .PP
  439. Any typographical or formatting errors that appear
  440. in this page are most likely
  441. to have been introduced during the conversion of the source files to
  442. man page format. To report such errors, see
  443. https://www.kernel.org/doc/man-pages/reporting_bugs.html .