1994-05-27 05:00:24 +00:00
|
|
|
.\" 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.
|
2017-02-28 23:42:47 +00:00
|
|
|
.\" 3. Neither the name of the University nor the names of its contributors
|
1994-05-27 05:00:24 +00:00
|
|
|
.\" 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
|
1999-08-28 00:22:10 +00:00
|
|
|
.\" $FreeBSD$
|
1994-05-27 05:00:24 +00:00
|
|
|
.\"
|
2020-08-07 17:25:56 +00:00
|
|
|
.Dd August 7, 2020
|
1994-05-27 05:00:24 +00:00
|
|
|
.Dt SETLOCALE 3
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
2003-12-07 06:00:00 +00:00
|
|
|
.Nm setlocale
|
1994-05-27 05:00:24 +00:00
|
|
|
.Nd natural language formatting for C
|
2000-04-21 09:42:15 +00:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libc
|
1994-05-27 05:00:24 +00:00
|
|
|
.Sh SYNOPSIS
|
2001-10-01 16:09:29 +00:00
|
|
|
.In locale.h
|
1994-05-27 05:00:24 +00:00
|
|
|
.Ft char *
|
|
|
|
.Fn setlocale "int category" "const char *locale"
|
|
|
|
.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.
|
|
|
|
.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
|
2004-10-17 06:51:50 +00:00
|
|
|
.Xr ctype 3
|
1994-05-27 05:00:24 +00:00
|
|
|
and
|
2004-10-17 06:51:50 +00:00
|
|
|
.Xr multibyte 3
|
1994-05-27 05:00:24 +00:00
|
|
|
functions.
|
|
|
|
This controls recognition of upper and lower case,
|
|
|
|
alphabetic or non-alphabetic characters,
|
2004-07-02 23:52:20 +00:00
|
|
|
and so on.
|
1998-04-29 22:39:56 +00:00
|
|
|
.It Dv LC_MESSAGES
|
1998-04-30 16:07:54 +00:00
|
|
|
Set a locale for message catalogs, see
|
|
|
|
.Xr catopen 3
|
|
|
|
function.
|
1994-05-27 05:00:24 +00:00
|
|
|
.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.
|
2020-08-07 17:25:56 +00:00
|
|
|
.It Dv LANG
|
|
|
|
Sets the generic locale category for native language, local customs
|
|
|
|
and coded character set in the absence of more specific locale
|
|
|
|
variables.
|
1994-05-27 05:00:24 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
Only three locales are defined by default,
|
|
|
|
the empty string
|
2010-08-02 13:11:41 +00:00
|
|
|
.Li \&"\|"
|
1994-05-27 05:00:24 +00:00
|
|
|
which denotes the native environment, and the
|
2010-08-02 13:11:41 +00:00
|
|
|
.Li \&"C"
|
1994-05-27 05:00:24 +00:00
|
|
|
and
|
2010-08-02 13:11:41 +00:00
|
|
|
.Li \&"POSIX"
|
1994-05-27 05:00:24 +00:00
|
|
|
locales, which denote the C language environment.
|
|
|
|
A
|
|
|
|
.Fa locale
|
|
|
|
argument of
|
|
|
|
.Dv NULL
|
|
|
|
causes
|
|
|
|
.Fn setlocale
|
|
|
|
to return the current locale.
|
2020-06-27 20:55:47 +00:00
|
|
|
.Pp
|
|
|
|
The option
|
|
|
|
.Fl a
|
|
|
|
to the
|
|
|
|
.Xr locale 1
|
|
|
|
command can be used to display all further possible names for the
|
|
|
|
.Fa locale
|
|
|
|
argument that are recognized.
|
|
|
|
Specifying any unrecognized value for
|
|
|
|
.Fa locale
|
|
|
|
makes
|
|
|
|
.Fn setlocale
|
|
|
|
fail.
|
|
|
|
.Pp
|
1994-05-27 05:00:24 +00:00
|
|
|
By default, C programs start in the
|
2010-08-02 13:11:41 +00:00
|
|
|
.Li \&"C"
|
1994-05-27 05:00:24 +00:00
|
|
|
locale.
|
2020-06-27 20:55:47 +00:00
|
|
|
.Pp
|
1994-05-27 05:00:24 +00:00
|
|
|
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.
|
2001-07-04 10:53:15 +00:00
|
|
|
.Sh RETURN VALUES
|
|
|
|
Upon successful completion,
|
2001-06-25 20:50:06 +00:00
|
|
|
.Fn setlocale
|
2001-07-04 10:53:15 +00:00
|
|
|
returns the string associated with the specified
|
2001-06-25 20:50:06 +00:00
|
|
|
.Fa category
|
|
|
|
for the requested
|
2001-07-04 10:53:15 +00:00
|
|
|
.Fa locale .
|
1994-05-27 05:00:24 +00:00
|
|
|
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.
|
2020-08-07 17:25:56 +00:00
|
|
|
.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
|
1994-05-27 05:00:24 +00:00
|
|
|
.Sh FILES
|
|
|
|
.Bl -tag -width /usr/share/locale/locale/category -compact
|
1997-04-07 08:54:38 +00:00
|
|
|
.It Pa $PATH_LOCALE/ Ns Em locale/category
|
1997-01-31 01:00:12 +00:00
|
|
|
.It Pa /usr/share/locale/ Ns Em locale/category
|
2001-07-15 07:53:42 +00:00
|
|
|
locale file for the locale
|
1997-01-31 01:00:12 +00:00
|
|
|
.Em locale
|
2001-07-15 07:53:42 +00:00
|
|
|
and the category
|
1997-01-31 01:00:12 +00:00
|
|
|
.Em category .
|
1994-05-27 05:00:24 +00:00
|
|
|
.El
|
2005-01-20 09:17:07 +00:00
|
|
|
.Sh ERRORS
|
|
|
|
No errors are defined.
|
2001-07-04 10:53:15 +00:00
|
|
|
.Sh SEE ALSO
|
2020-06-27 20:55:47 +00:00
|
|
|
.Xr locale 1 ,
|
2019-09-10 07:47:52 +00:00
|
|
|
.Xr localedef 1 ,
|
1998-08-31 16:41:09 +00:00
|
|
|
.Xr catopen 3 ,
|
1998-01-02 19:22:52 +00:00
|
|
|
.Xr ctype 3 ,
|
2003-12-07 06:00:00 +00:00
|
|
|
.Xr localeconv 3 ,
|
1994-05-27 05:00:24 +00:00
|
|
|
.Xr multibyte 3 ,
|
|
|
|
.Xr strcoll 3 ,
|
|
|
|
.Xr strxfrm 3 ,
|
2003-11-15 02:26:04 +00:00
|
|
|
.Xr euc 5 ,
|
2004-01-29 09:27:24 +00:00
|
|
|
.Xr utf8 5 ,
|
|
|
|
.Xr environ 7
|
1994-05-27 05:00:24 +00:00
|
|
|
.Sh STANDARDS
|
|
|
|
The
|
|
|
|
.Fn setlocale
|
2003-12-07 06:00:00 +00:00
|
|
|
function conforms to
|
2002-10-09 09:19:28 +00:00
|
|
|
.St -isoC-99 .
|
1994-05-27 05:00:24 +00:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Fn setlocale
|
2003-12-07 06:00:00 +00:00
|
|
|
function first appeared in
|
1996-08-22 23:31:07 +00:00
|
|
|
.Bx 4.4 .
|