xref: /freebsd/lib/libc/locale/setlocale.3 (revision 0b5e953b91b36a5d1c7744a9a78a7edc48612f2d)
158f0484fSRodney W. Grimes.\" Copyright (c) 1993
258f0484fSRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
358f0484fSRodney W. Grimes.\"
458f0484fSRodney W. Grimes.\" This code is derived from software contributed to Berkeley by
558f0484fSRodney W. Grimes.\" Donn Seeley at BSDI.
658f0484fSRodney W. Grimes.\"
758f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
858f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions
958f0484fSRodney W. Grimes.\" are met:
1058f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
1158f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
1258f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
1358f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
1458f0484fSRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
1558f0484fSRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software
1658f0484fSRodney W. Grimes.\"    must display the following acknowledgement:
1758f0484fSRodney W. Grimes.\"	This product includes software developed by the University of
1858f0484fSRodney W. Grimes.\"	California, Berkeley and its contributors.
1958f0484fSRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors
2058f0484fSRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
2158f0484fSRodney W. Grimes.\"    without specific prior written permission.
2258f0484fSRodney W. Grimes.\"
2358f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2458f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2558f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2658f0484fSRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2758f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2858f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2958f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3058f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3158f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3258f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3358f0484fSRodney W. Grimes.\" SUCH DAMAGE.
3458f0484fSRodney W. Grimes.\"
3558f0484fSRodney W. Grimes.\"	@(#)setlocale.3	8.1 (Berkeley) 6/9/93
3658f0484fSRodney W. Grimes.\"
3758f0484fSRodney W. Grimes.Dd June 9, 1993
3858f0484fSRodney W. Grimes.Dt SETLOCALE 3
3958f0484fSRodney W. Grimes.Os
4058f0484fSRodney W. Grimes.Sh NAME
4158f0484fSRodney W. Grimes.Nm setlocale ,
4258f0484fSRodney W. Grimes.Nm localeconv
4358f0484fSRodney W. Grimes.Nd natural language formatting for C
4458f0484fSRodney W. Grimes.Sh SYNOPSIS
4558f0484fSRodney W. Grimes.Fd #include <locale.h>
4658f0484fSRodney W. Grimes.Ft char *
4758f0484fSRodney W. Grimes.Fn setlocale "int category" "const char *locale"
4858f0484fSRodney W. Grimes.Ft struct lconv *
4958f0484fSRodney W. Grimes.Fn localeconv "void"
5058f0484fSRodney W. Grimes.Sh DESCRIPTION
5158f0484fSRodney W. GrimesThe
5258f0484fSRodney W. Grimes.Fn setlocale
5358f0484fSRodney W. Grimesfunction sets the C library's notion
5458f0484fSRodney W. Grimesof natural language formatting style
5558f0484fSRodney W. Grimesfor particular sets of routines.
5658f0484fSRodney W. GrimesEach such style is called a
5758f0484fSRodney W. Grimes.Sq locale
5858f0484fSRodney W. Grimesand is invoked using an appropriate name passed as a C string.
5958f0484fSRodney W. GrimesThe
6058f0484fSRodney W. Grimes.Fn localeconv
6158f0484fSRodney W. Grimesroutine returns the current locale's parameters
6258f0484fSRodney W. Grimesfor formatting numbers.
6358f0484fSRodney W. Grimes.Pp
6458f0484fSRodney W. GrimesThe
6558f0484fSRodney W. Grimes.Fn setlocale
6658f0484fSRodney W. Grimesfunction recognizes several categories of routines.
6758f0484fSRodney W. GrimesThese are the categories and the sets of routines they select:
6858f0484fSRodney W. Grimes.Pp
6958f0484fSRodney W. Grimes.Bl -tag -width LC_MONETARY
7058f0484fSRodney W. Grimes.It Dv LC_ALL
7158f0484fSRodney W. GrimesSet the entire locale generically.
7258f0484fSRodney W. Grimes.It Dv LC_COLLATE
7358f0484fSRodney W. GrimesSet a locale for string collation routines.
7458f0484fSRodney W. GrimesThis controls alphabetic ordering in
7558f0484fSRodney W. Grimes.Fn strcoll
7658f0484fSRodney W. Grimesand
7758f0484fSRodney W. Grimes.Fn strxfrm .
7858f0484fSRodney W. Grimes.It Dv LC_CTYPE
7958f0484fSRodney W. GrimesSet a locale for the
8058f0484fSRodney W. Grimes.Xr ctype 3 ,
8158f0484fSRodney W. Grimes.Xr mbrune 3 ,
8258f0484fSRodney W. Grimes.Xr multibyte 3
8358f0484fSRodney W. Grimesand
8458f0484fSRodney W. Grimes.Xr rune 3
8558f0484fSRodney W. Grimesfunctions.
8658f0484fSRodney W. GrimesThis controls recognition of upper and lower case,
8758f0484fSRodney W. Grimesalphabetic or non-alphabetic characters,
8858f0484fSRodney W. Grimesand so on.  The real work is done by the
8958f0484fSRodney W. Grimes.Fn setrunelocale
9058f0484fSRodney W. Grimesfunction.
910b5e953bSAndrey A. Chernov.It Dv LC_MESSAGES
920b5e953bSAndrey A. ChernovSet a locale for message catalogs.
9358f0484fSRodney W. Grimes.It Dv LC_MONETARY
9458f0484fSRodney W. GrimesSet a locale for formatting monetary values;
9558f0484fSRodney W. Grimesthis affects the
9658f0484fSRodney W. Grimes.Fn localeconv
9758f0484fSRodney W. Grimesfunction.
9858f0484fSRodney W. Grimes.It Dv LC_NUMERIC
9958f0484fSRodney W. GrimesSet a locale for formatting numbers.
10058f0484fSRodney W. GrimesThis controls the formatting of decimal points
10158f0484fSRodney W. Grimesin input and output of floating point numbers
10258f0484fSRodney W. Grimesin functions such as
10358f0484fSRodney W. Grimes.Fn printf
10458f0484fSRodney W. Grimesand
10558f0484fSRodney W. Grimes.Fn scanf ,
10658f0484fSRodney W. Grimesas well as values returned by
10758f0484fSRodney W. Grimes.Fn localeconv .
10858f0484fSRodney W. Grimes.It Dv LC_TIME
10958f0484fSRodney W. GrimesSet a locale for formatting dates and times using the
11058f0484fSRodney W. Grimes.Fn strftime
11158f0484fSRodney W. Grimesfunction.
11258f0484fSRodney W. Grimes.El
11358f0484fSRodney W. Grimes.Pp
11458f0484fSRodney W. GrimesOnly three locales are defined by default,
11558f0484fSRodney W. Grimesthe empty string
11658f0484fSRodney W. Grimes.Li "\&""\|""
11758f0484fSRodney W. Grimeswhich denotes the native environment, and the
11858f0484fSRodney W. Grimes.Li "\&""C""
11958f0484fSRodney W. Grimesand
12058f0484fSRodney W. Grimes.LI "\&""POSIX""
12158f0484fSRodney W. Grimeslocales, which denote the C language environment.
12258f0484fSRodney W. GrimesA
12358f0484fSRodney W. Grimes.Fa locale
12458f0484fSRodney W. Grimesargument of
12558f0484fSRodney W. Grimes.Dv NULL
12658f0484fSRodney W. Grimescauses
12758f0484fSRodney W. Grimes.Fn setlocale
12858f0484fSRodney W. Grimesto return the current locale.
12958f0484fSRodney W. GrimesBy default, C programs start in the
13058f0484fSRodney W. Grimes.Li "\&""C""
13158f0484fSRodney W. Grimeslocale.
13258f0484fSRodney W. GrimesThe only function in the library that sets the locale is
13358f0484fSRodney W. Grimes.Fn setlocale ;
13458f0484fSRodney W. Grimesthe locale is never changed as a side effect of some other routine.
13558f0484fSRodney W. Grimes.Pp
13658f0484fSRodney W. GrimesThe
13758f0484fSRodney W. Grimes.Fn localeconv
13858f0484fSRodney W. Grimesfunction returns a pointer to a structure
13958f0484fSRodney W. Grimeswhich provides parameters for formatting numbers,
14058f0484fSRodney W. Grimesespecially currency values:
14158f0484fSRodney W. Grimes.Bd -literal -offset indent
14258f0484fSRodney W. Grimesstruct lconv {
14358f0484fSRodney W. Grimes	char	*decimal_point;
14458f0484fSRodney W. Grimes	char	*thousands_sep;
14558f0484fSRodney W. Grimes	char	*grouping;
14658f0484fSRodney W. Grimes	char	*int_curr_symbol;
14758f0484fSRodney W. Grimes	char	*currency_symbol;
14858f0484fSRodney W. Grimes	char	*mon_decimal_point;
14958f0484fSRodney W. Grimes	char	*mon_thousands_sep;
15058f0484fSRodney W. Grimes	char	*mon_grouping;
15158f0484fSRodney W. Grimes	char	*positive_sign;
15258f0484fSRodney W. Grimes	char	*negative_sign;
15358f0484fSRodney W. Grimes	char	int_frac_digits;
15458f0484fSRodney W. Grimes	char	frac_digits;
15558f0484fSRodney W. Grimes	char	p_cs_precedes;
15658f0484fSRodney W. Grimes	char	p_sep_by_space;
15758f0484fSRodney W. Grimes	char	n_cs_precedes;
15858f0484fSRodney W. Grimes	char	n_sep_by_space;
15958f0484fSRodney W. Grimes	char	p_sign_posn;
16058f0484fSRodney W. Grimes	char	n_sign_posn;
16158f0484fSRodney W. Grimes};
16258f0484fSRodney W. Grimes.Ed
16358f0484fSRodney W. Grimes.Pp
16458f0484fSRodney W. GrimesThe individual fields have the following meanings:
16558f0484fSRodney W. Grimes.Pp
16658f0484fSRodney W. Grimes.Bl -tag -width mon_decimal_point
16758f0484fSRodney W. Grimes.It Fa decimal_point
16858f0484fSRodney W. GrimesThe decimal point character, except for currency values.
16958f0484fSRodney W. Grimes.It Fa thousands_sep
17058f0484fSRodney W. GrimesThe separator between groups of digits
17158f0484fSRodney W. Grimesbefore the decimal point, except for currency values.
17258f0484fSRodney W. Grimes.It Fa grouping
17358f0484fSRodney W. GrimesThe sizes of the groups of digits, except for currency values.
17458f0484fSRodney W. GrimesThis is a pointer to a vector of integers, each of size
17558f0484fSRodney W. Grimes.Va char ,
17658f0484fSRodney W. Grimesrepresenting group size from low order digit groups
17758f0484fSRodney W. Grimesto high order (right to left).
17858f0484fSRodney W. GrimesThe list may be terminated with 0 or
17958f0484fSRodney W. Grimes.Dv CHAR_MAX .
18058f0484fSRodney W. GrimesIf the list is terminated with 0,
18158f0484fSRodney W. Grimesthe last group size before the 0 is repeated to account for all the digits.
18258f0484fSRodney W. GrimesIf the list is terminated with
18358f0484fSRodney W. Grimes.Dv CHAR_MAX ,
18458f0484fSRodney W. Grimesno more grouping is performed.
18558f0484fSRodney W. Grimes.It Fa int_curr_symbol
18658f0484fSRodney W. GrimesThe standardized international currency symbol.
18758f0484fSRodney W. Grimes.It Fa currency_symbol
18858f0484fSRodney W. GrimesThe local currency symbol.
18958f0484fSRodney W. Grimes.It Fa mon_decimal_point
19058f0484fSRodney W. GrimesThe decimal point character for currency values.
19158f0484fSRodney W. Grimes.It Fa mon_thousands_sep
19258f0484fSRodney W. GrimesThe separator for digit groups in currency values.
19358f0484fSRodney W. Grimes.It Fa mon_grouping
19458f0484fSRodney W. GrimesLike
19558f0484fSRodney W. Grimes.Fa grouping
19658f0484fSRodney W. Grimesbut for currency values.
19758f0484fSRodney W. Grimes.It Fa positive_sign
19858f0484fSRodney W. GrimesThe character used to denote nonnegative currency values,
19958f0484fSRodney W. Grimesusually the empty string.
20058f0484fSRodney W. Grimes.It Fa negative_sign
20158f0484fSRodney W. GrimesThe character used to denote negative currency values,
20258f0484fSRodney W. Grimesusually a minus sign.
20358f0484fSRodney W. Grimes.It Fa int_frac_digits
20458f0484fSRodney W. GrimesThe number of digits after the decimal point
20558f0484fSRodney W. Grimesin an international-style currency value.
20658f0484fSRodney W. Grimes.It Fa frac_digits
20758f0484fSRodney W. GrimesThe number of digits after the decimal point
20858f0484fSRodney W. Grimesin the local style for currency values.
20958f0484fSRodney W. Grimes.It Fa p_cs_precedes
21058f0484fSRodney W. Grimes1 if the currency symbol precedes the currency value
21158f0484fSRodney W. Grimesfor nonnegative values, 0 if it follows.
21258f0484fSRodney W. Grimes.It Fa p_sep_by_space
21358f0484fSRodney W. Grimes1 if a space is inserted between the currency symbol
21458f0484fSRodney W. Grimesand the currency value for nonnegative values, 0 otherwise.
21558f0484fSRodney W. Grimes.It Fa n_cs_precedes
21658f0484fSRodney W. GrimesLike
21758f0484fSRodney W. Grimes.Fa p_cs_precedes
21858f0484fSRodney W. Grimesbut for negative values.
21958f0484fSRodney W. Grimes.It Fa n_sep_by_space
22058f0484fSRodney W. GrimesLike
22158f0484fSRodney W. Grimes.Fa p_sep_by_space
22258f0484fSRodney W. Grimesbut for negative values.
22358f0484fSRodney W. Grimes.It Fa p_sign_posn
22458f0484fSRodney W. GrimesThe location of the
22558f0484fSRodney W. Grimes.Fa positive_sign
22658f0484fSRodney W. Grimeswith respect to a nonnegative quantity and the
22758f0484fSRodney W. Grimes.Fa currency_symbol ,
22858f0484fSRodney W. Grimescoded as follows:
22958f0484fSRodney W. Grimes.Bl -tag -width 3n -compact
23058f0484fSRodney W. Grimes.It Li 0
23158f0484fSRodney W. GrimesParentheses around the entire string.
23258f0484fSRodney W. Grimes.It Li 1
23358f0484fSRodney W. GrimesBefore the string.
23458f0484fSRodney W. Grimes.It Li 2
23558f0484fSRodney W. GrimesAfter the string.
23658f0484fSRodney W. Grimes.It Li 3
23758f0484fSRodney W. GrimesJust before
23858f0484fSRodney W. Grimes.Fa currency_symbol .
23958f0484fSRodney W. Grimes.It Li 4
24058f0484fSRodney W. GrimesJust after
24158f0484fSRodney W. Grimes.Fa currency_symbol .
24258f0484fSRodney W. Grimes.El
24358f0484fSRodney W. Grimes.It Fa n_sign_posn
24458f0484fSRodney W. GrimesLike
24558f0484fSRodney W. Grimes.Fa p_sign_posn
24658f0484fSRodney W. Grimesbut for negative currency values.
24758f0484fSRodney W. Grimes.El
24858f0484fSRodney W. Grimes.Pp
24958f0484fSRodney W. GrimesUnless mentioned above,
25058f0484fSRodney W. Grimesan empty string as a value for a field
25158f0484fSRodney W. Grimesindicates a zero length result or
25258f0484fSRodney W. Grimesa value that is not in the current locale.
25358f0484fSRodney W. GrimesA
25458f0484fSRodney W. Grimes.Dv CHAR_MAX
25558f0484fSRodney W. Grimesresult similarly denotes an unavailable value.
25658f0484fSRodney W. Grimes.Sh "RETURN VALUES
25758f0484fSRodney W. GrimesThe
25858f0484fSRodney W. Grimes.Fn setlocale
25958f0484fSRodney W. Grimesfunction returns
26058f0484fSRodney W. Grimes.Dv NULL
26158f0484fSRodney W. Grimesand fails to change the locale
26258f0484fSRodney W. Grimesif the given combination of
26358f0484fSRodney W. Grimes.Fa category
26458f0484fSRodney W. Grimesand
26558f0484fSRodney W. Grimes.Fa locale
26658f0484fSRodney W. Grimesmakes no sense.
26758f0484fSRodney W. GrimesThe
26858f0484fSRodney W. Grimes.Fn localeconv
26958f0484fSRodney W. Grimesfunction returns a pointer to a static object
27058f0484fSRodney W. Grimeswhich may be altered by later calls to
27158f0484fSRodney W. Grimes.Fn setlocale
27258f0484fSRodney W. Grimesor
27358f0484fSRodney W. Grimes.Fn localeconv .
27458f0484fSRodney W. Grimes.Sh FILES
27558f0484fSRodney W. Grimes.Bl -tag -width /usr/share/locale/locale/category -compact
27621b4da07SAndrey A. Chernov.It Pa $PATH_LOCALE/ Ns Em locale/category
2776a145130SMike Pritchard.It Pa /usr/share/locale/ Ns Em locale/category
2786a145130SMike Pritchardlocale file for the locale
2796a145130SMike Pritchard.Em locale
2806a145130SMike Pritchardand the category
2816a145130SMike Pritchard.Em category .
28258f0484fSRodney W. Grimes.El
28358f0484fSRodney W. Grimes.Sh "SEE ALSO
2848c9c6676SMike Pritchard.Xr colldef 1 ,
2858c9c6676SMike Pritchard.Xr mklocale 1 ,
286e69bcfc3SAlexander Langer.Xr ctype 3 ,
28758f0484fSRodney W. Grimes.Xr mbrune 3 ,
28858f0484fSRodney W. Grimes.Xr multibyte 3 ,
28958f0484fSRodney W. Grimes.Xr rune 3 ,
29058f0484fSRodney W. Grimes.Xr strcoll 3 ,
29158f0484fSRodney W. Grimes.Xr strxfrm 3 ,
2928c9c6676SMike Pritchard.Xr euc 4 ,
29358f0484fSRodney W. Grimes.Xr utf2 4
29458f0484fSRodney W. Grimes.Sh STANDARDS
29558f0484fSRodney W. GrimesThe
29658f0484fSRodney W. Grimes.Fn setlocale
29758f0484fSRodney W. Grimesand
29858f0484fSRodney W. Grimes.Fn localeconv
29958f0484fSRodney W. Grimesfunctions conform to
30058f0484fSRodney W. Grimes.St -ansiC .
30158f0484fSRodney W. Grimes.Sh HISTORY
30258f0484fSRodney W. GrimesThe
30358f0484fSRodney W. Grimes.Fn setlocale
30458f0484fSRodney W. Grimesand
30558f0484fSRodney W. Grimes.Fn localeconv
3067bdf80e5SMike Pritchardfunctions first appeared in
3077bdf80e5SMike Pritchard.Bx 4.4 .
30858f0484fSRodney W. Grimes.Sh BUGS
30958f0484fSRodney W. GrimesThe current implementation supports only the
31058f0484fSRodney W. Grimes.Li "\&""C""
31158f0484fSRodney W. Grimesand
31258f0484fSRodney W. Grimes.Li "\&""POSIX""
313c28fbb7bSGarrett Wollmanlocales for all but the
314c28fbb7bSGarrett Wollman.Dv LC_COLLATE ,
315c28fbb7bSGarrett Wollman.Dv LC_CTYPE ,
316c28fbb7bSGarrett Wollmanand
317c28fbb7bSGarrett Wollman.Dv LC_TIME
318c28fbb7bSGarrett Wollmancategories.
31958f0484fSRodney W. Grimes.Pp
32058f0484fSRodney W. GrimesIn spite of the gnarly currency support in
32158f0484fSRodney W. Grimes.Fn localeconv ,
32258f0484fSRodney W. Grimesthe standards don't include any functions
32358f0484fSRodney W. Grimesfor generalized currency formatting.
32458f0484fSRodney W. Grimes.Pp
32558f0484fSRodney W. GrimesUse of
32658f0484fSRodney W. Grimes.Dv LC_MONETARY
32758f0484fSRodney W. Grimescould lead to misleading results until we have a real time currency
32858f0484fSRodney W. Grimesconversion function.
32958f0484fSRodney W. Grimes.Dv LC_NUMERIC
33058f0484fSRodney W. Grimesand
33158f0484fSRodney W. Grimes.Dv LC_TIME
33258f0484fSRodney W. Grimesare personal choices and should not be wrapped up with the other categories.
333