[BACK]Return to setlocale.3 CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / locale

File: [cvs.NetBSD.org] / src / lib / libc / locale / setlocale.3 (download)

Revision 1.21, Sat Jan 24 16:58:54 2004 UTC (20 years, 2 months ago) by wiz
Branch: MAIN
CVS Tags: yamt-pf42-baseX, yamt-pf42-base4, yamt-pf42-base3, yamt-pf42-base2, yamt-pf42-base, yamt-pf42, yamt-pagecache-tag8, yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, yamt-pagecache, wrstuden-revivesa-base-3, wrstuden-revivesa-base-2, wrstuden-revivesa-base-1, wrstuden-revivesa-base, wrstuden-revivesa, wrstuden-fixsa-newbase, wrstuden-fixsa-base-1, wrstuden-fixsa-base, wrstuden-fixsa, tls-maxphys-base, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, phil-wifi, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-9-base, netbsd-9-3-RELEASE, netbsd-9-2-RELEASE, netbsd-9-1-RELEASE, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, netbsd-5-base, netbsd-5-2-RELEASE, netbsd-5-2-RC1, netbsd-5-2-3-RELEASE, netbsd-5-2-2-RELEASE, netbsd-5-2-1-RELEASE, netbsd-5-2, netbsd-5-1-RELEASE, netbsd-5-1-RC4, netbsd-5-1-RC3, netbsd-5-1-RC2, netbsd-5-1-RC1, netbsd-5-1-5-RELEASE, netbsd-5-1-4-RELEASE, netbsd-5-1-3-RELEASE, netbsd-5-1-2-RELEASE, netbsd-5-1-1-RELEASE, netbsd-5-1, netbsd-5-0-RELEASE, netbsd-5-0-RC4, netbsd-5-0-RC3, netbsd-5-0-RC2, netbsd-5-0-RC1, netbsd-5-0-2-RELEASE, netbsd-5-0-1-RELEASE, netbsd-5-0, netbsd-5, netbsd-4-base, netbsd-4-0-RELEASE, netbsd-4-0-RC5, netbsd-4-0-RC4, netbsd-4-0-RC3, netbsd-4-0-RC2, netbsd-4-0-RC1, netbsd-4-0-1-RELEASE, netbsd-4-0, netbsd-4, netbsd-3-base, netbsd-3-1-RELEASE, netbsd-3-1-RC4, netbsd-3-1-RC3, netbsd-3-1-RC2, netbsd-3-1-RC1, netbsd-3-1-1-RELEASE, netbsd-3-1, netbsd-3-0-RELEASE, netbsd-3-0-RC6, netbsd-3-0-RC5, netbsd-3-0-RC4, netbsd-3-0-RC3, netbsd-3-0-RC2, netbsd-3-0-RC1, netbsd-3-0-3-RELEASE, netbsd-3-0-2-RELEASE, netbsd-3-0-1-RELEASE, netbsd-3-0, netbsd-3, netbsd-2-base, netbsd-2-1-RELEASE, netbsd-2-1-RC6, netbsd-2-1-RC5, netbsd-2-1-RC4, netbsd-2-1-RC3, netbsd-2-1-RC2, netbsd-2-1-RC1, netbsd-2-1, netbsd-2-0-base, netbsd-2-0-RELEASE, netbsd-2-0-RC5, netbsd-2-0-RC4, netbsd-2-0-RC3, netbsd-2-0-RC2, netbsd-2-0-RC1, netbsd-2-0-3-RELEASE, netbsd-2-0-2-RELEASE, netbsd-2-0-1-RELEASE, netbsd-2-0, netbsd-2, mjf-devfs2-base, mjf-devfs2, matt-premerge-20091211, matt-nb8-mediatek-base, matt-nb8-mediatek, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, matt-nb5-pq3-base, matt-nb5-pq3, matt-nb5-mips64-u2-k2-k4-k7-k8-k9, matt-nb5-mips64-u1-k1-k5, matt-nb5-mips64-premerge-20101231, matt-nb5-mips64-premerge-20091211, matt-nb5-mips64-k15, matt-nb5-mips64, matt-nb4-mips64-k7-u2a-k9b, matt-mips64-premerge-20101231, matt-mips64-base2, matt-mips64-base, matt-mips64, matt-armv6-prevmlocking, matt-armv6-nbase, matt-armv6-base, matt-armv6, localcount-20160914, keiichi-mipv6-base, keiichi-mipv6, jym-xensuspend-nbase, jym-xensuspend-base, jym-xensuspend, is-mlppp-base, is-mlppp, hpcarm-cleanup-nbase, hpcarm-cleanup-base, hpcarm-cleanup, cube-autoconf-base, cube-autoconf, cjep_sun2x-base1, cjep_sun2x-base, cjep_sun2x, cjep_staticlib_x-base1, cjep_staticlib_x-base, cjep_staticlib_x, christos-time_t-nbase, christos-time_t-base, christos-time_t, cherry-xenmp-base, cherry-xenmp, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2, agc-symver-base, agc-symver, abandoned-netbsd-4-base, abandoned-netbsd-4
Branch point for: netbsd-9, netbsd-8
Changes since 1.20: +1 -3 lines

Lots of grammar and wording changes from jmc@openbsd, with some
additional consistency changes by me.

.\"	$NetBSD: setlocale.3,v 1.21 2004/01/24 16:58:54 wiz Exp $
.\"
.\" Copyright (c) 1993
.\"	The Regents of the University of California.  All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Donn Seeley at BSDI.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\"	@(#)setlocale.3	8.1 (Berkeley) 6/9/93
.\"
.Dd May 30, 2003
.Dt SETLOCALE 3
.Os
.Sh NAME
.Nm setlocale ,
.Nm localeconv
.Nd natural language formatting for C
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In locale.h
.Ft char *
.Fn setlocale "int category" "const char *locale"
.Ft struct lconv *
.Fn localeconv "void"
.Sh DESCRIPTION
The
.Fn setlocale
function sets the C library's notion
of natural language formatting style
for particular sets of routines.
Each such style is called a
.Sq locale
and is invoked using an appropriate name passed as a C string.
The
.Fn localeconv
routine returns the current locale's parameters
for formatting numbers.
.Pp
The
.Fn setlocale
function recognizes several categories of routines.
These are the categories and the sets of routines they select:
.Bl -tag -width LC_MONETARY
.It Dv LC_ALL
Set the entire locale generically.
.It Dv LC_COLLATE
Set a locale for string collation routines.
This controls alphabetic ordering in
.Fn strcoll
and
.Fn strxfrm .
.It Dv LC_CTYPE
Set a locale for the
.Xr ctype 3
functions.
This controls recognition of upper and lower case,
alphabetic or non-alphabetic characters,
and so on.
The real work is done by the
.Fn setrunelocale
function.
.It Dv LC_MESSAGES
Set a locale for message catalogs.
This controls the selection of message catalogs by the
.Xr catgets 3
and
.Xr gettext 3
families of functions.
.It Dv LC_MONETARY
Set a locale for formatting monetary values;
this affects the
.Fn localeconv
function.
.It Dv LC_NUMERIC
Set a locale for formatting numbers.
This controls the formatting of decimal points
in input and output of floating point numbers
in functions such as
.Fn printf
and
.Fn scanf ,
as well as values returned by
.Fn localeconv .
.It Dv LC_TIME
Set a locale for formatting dates and times using the
.Fn strftime
function.
.El
.Pp
Only three locales are defined by default,
the empty string
.Li "\&""\|""
which denotes the native environment, and the
.Li "\&""C""
and
.Li "\&""POSIX""
locales, which denote the C language environment.
A
.Fa locale
argument of
.Dv NULL
causes
.Fn setlocale
to return the current locale.
By default, C programs start in the
.Li "\&""C""
locale.
The format of the locale string is described in
.Xr nls 7 .
.Pp
The only function in the library that sets the locale is
.Fn setlocale ;
the locale is never changed as a side effect of some other routine.
.Pp
Changing the setting of
.Dv LC_MESSAGES
has no effect on catalogs that have already been opened by
.Xr catopen 3 .
.Pp
The
.Fn localeconv
function returns a pointer to a structure
which provides parameters for formatting numbers,
especially currency values:
.Bd -literal -offset indent
struct lconv {
	char	*decimal_point;
	char	*thousands_sep;
	char	*grouping;
	char	*int_curr_symbol;
	char	*currency_symbol;
	char	*mon_decimal_point;
	char	*mon_thousands_sep;
	char	*mon_grouping;
	char	*positive_sign;
	char	*negative_sign;
	char	int_frac_digits;
	char	frac_digits;
	char	p_cs_precedes;
	char	p_sep_by_space;
	char	n_cs_precedes;
	char	n_sep_by_space;
	char	p_sign_posn;
	char	n_sign_posn;
	char	int_p_cs_precedes;
	char	int_n_cs_precedes;
	char	int_p_sep_by_space;
	char	int_n_sep_by_space;
	char	int_p_sign_posn;
	char	int_n_sign_posn;
};
.Ed
.Pp
The individual fields have the following meanings:
.Bl -tag -width int_p_sep_by_space
.It Fa decimal_point
The decimal point character, except for monetary values.
.It Fa thousands_sep
The separator between groups of digits
before the decimal point, except for monetary values.
.It Fa grouping
The sizes of the groups of digits, except for monetary values.
This is a pointer to a vector of integers, each of size
.Va char ,
representing group size from low order digit groups
to high order (right to left).
The list may be terminated with 0 or
.Dv CHAR_MAX .
If the list is terminated with 0,
the last group size before the 0 is repeated to account for all the digits.
If the list is terminated with
.Dv CHAR_MAX ,
no more grouping is performed.
.It Fa int_curr_symbol
The standardized (ISO 4217:1995) international currency symbol.
.It Fa currency_symbol
The local currency symbol.
.It Fa mon_decimal_point
The decimal point character for monetary values.
.It Fa mon_thousands_sep
The separator for digit groups in monetary values.
.It Fa mon_grouping
Like
.Fa grouping
but for monetary values.
.It Fa positive_sign
The character used to denote nonnegative monetary values,
usually the empty string.
.It Fa negative_sign
The character used to denote negative monetary values,
usually a minus sign.
.It Fa int_frac_digits
The number of digits after the decimal point
in an internationally formatted monetary value.
.It Fa frac_digits
The number of digits after the decimal point
in an locally formatted monetary value.
.It Fa p_cs_precedes
1 if the currency symbol precedes the monetary value
for nonnegative values, 0 if it follows.
.It Fa p_sep_by_space
1 if a space is inserted between the currency symbol
and the monetary value for nonnegative values, 0 otherwise.
.It Fa n_cs_precedes
Like
.Fa p_cs_precedes
but for negative values.
.It Fa n_sep_by_space
Like
.Fa p_sep_by_space
but for negative values.
.It Fa p_sign_posn
The location of the
.Fa positive_sign
with respect to a nonnegative quantity and the
.Fa currency_symbol .
.It Fa n_sign_posn
Like
.Fa p_sign_posn
but for negative currency values.
.It Fa int_p_cs_precedes
1 if the currency symbol precedes the internationally
formatted monetary value for nonnegative values, 0 if it follows.
.It Fa int_n_cs_precedes
Like
.Fa int_p_cs_precedes
but for negative values.
.It Fa int_p_sep_by_space
1 if a space is inserted between the currency symbol
and the internationally formatted monetary value for
nonnegative values, 0 otherwise.
.It Fa int_n_sep_by_space
Like
.Fa int_p_sep_by_space
but for negative values.
.It Fa int_p_sign_posn
The location of the
.Fa positive_sign
with respect to a nonnegative quantity and the
.Fa currency_symbol ,
for internationally formatted nonnegative monetary values.
.It Fa int_n_sign_posn
Like
.Fa int_p_sign_posn
but for negative values.
.El
.Pp
The positional parameters in
.Fa p_sign_posn ,
.Fa n_sign_posn ,
.Fa int_p_sign_posn
and
.Fa int_n_sign_posn
are encoded as follows:
.Bl -tag -width 3n -compact
.It Li 0
Parentheses around the entire string.
.It Li 1
Before the string.
.It Li 2
After the string.
.It Li 3
Just before
.Fa currency_symbol .
.It Li 4
Just after
.Fa currency_symbol .
.El
.Pp
Unless mentioned above,
an empty string as a value for a field
indicates a zero length result or
a value that is not in the current locale.
A
.Dv CHAR_MAX
result similarly denotes an unavailable value.
.Sh RETURN VALUES
The
.Fn setlocale
function returns
.Dv NULL
and fails to change the locale
if the given combination of
.Fa category
and
.Fa locale
makes no sense.
The
.Fn localeconv
function returns a pointer to a static object
which may be altered by later calls to
.Fn setlocale
or
.Fn localeconv .
.Sh EXAMPLES
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:
.Bd -literal
	setlocale(LC_ALL, "de");
	setlocale(LC_COLLATE, "fr");
.Ed
.Pp
When a process is started, its current locale is set to the C or POSIX
locale.
An internationalized program that depends on locale data not defined in
the C or POSIX locale must invoke the setlocale subroutine in the
following manner before using any of the locale-specific information:
.Bd -literal
	setlocale(LC_ALL, "");
.Ed
.\" .Sh FILES							XXX
.\" .Bl -tag -width /usr/share/locale/locale/category -compact	XXX
.\" .It Pa $PATH_LOCALE/\fIlocale\fP/\fIcategory\fP		XXX
.\" .It Pa /usr/share/locale/\fIlocale\fP/\fIcategory\fP	XXX
.\" locale file for the locale \fIlocale\fP			XXX
.\" and the category \fIcategory\fP.				XXX
.\" .El
.Sh SEE ALSO
.Xr catopen 3 ,
.Xr gettext 3 ,
.Xr nl_langinfo 3 ,
.Xr nls 7
.\" .Xr strcoll 3 ,						XXX
.\" .Xr strxfrm 3						XXX
.Sh STANDARDS
The
.Fn setlocale
and
.Fn localeconv
functions conform to
.St -ansiC
and
.St -isoC-90 .
.Pp
The
.Fa int_p_cs_precedes ,
.Fa int_n_cs_precedes ,
.Fa int_p_sep_by_space ,
.Fa int_n_sep_by_space ,
.Fa int_p_sign_posn
and
.Fa int_n_sign_posn
members of
.Ft struct lconv
were introduced in
.St -isoC-99 .
.Sh HISTORY
The
.Fn setlocale
and
.Fn localeconv
functions first appeared in
.Bx 4.4 .
.Sh BUGS
The current implementation supports only the
.Li "\&""C""
and
.Li "\&""POSIX""
locales for all but the
.Dv LC_CTYPE
locale.
.Pp
In spite of the gnarly currency support in
.Fn localeconv ,
the standards don't include any functions
for generalized currency formatting.
.Pp
.Dv LC_COLLATE
does not make sense for many languages.
Use of
.Dv LC_MONETARY
could lead to misleading results until we have a real time currency
conversion function.
.Dv LC_NUMERIC
and
.Dv LC_TIME
are personal choices and should not be wrapped up with the other categories.
.Pp
Multibyte locales aren't supported for static binaries.