setlocaleのヘルプ・マニュアル
日本語 英語
setlocale --help
man setlocale
SETLOCALE(3) Linux Programmer’s Manual SETLOCALE(3)
名前
setlocale - 現在のロケール (locale) を設定する
書式
#include
char *setlocale(int category, const char *locale);
説明
setlocale() 関数はプログラムのカレントロケールを設定したり問い合わせた
りするのに用いられる。
locale が NULL でなければ、プログラムのカレントロケールは引き数に従って
変 更される。引き数 category はプログラムのカレントロケールのどの部分を
変更するかを決める。
LC_ALL 全てのロケール
LC_COLLATE
正規表現のマッチング (範囲表現と等価クラスのマッチングを決 定 す
る) と文字列の照合 (collation)
LC_CTYPE
正規表現のマッチング、文字の分類、文字の変換、大文字小文字比較、
ワイド文字関数
LC_MESSAGES
地域化可能な自然言語メッセージ
LC_MONETARY
通貨の書式
LC_NUMERIC
数値の書式 (小数点や 3 桁ごとの区切り)
LC_TIME
時刻と日付けの書式
引き数 locale は category に設定する文字列へのポインタである。この文 字
列はよく知られた定数である "C" や "da_DK" などでも良いし (以下を参照)、
他のときに setlocale() を呼び出した際に返された、内部用の文字列でも良い
。
locale が "" の場合、ロケールの各部分の設定には環境変数が参照される。そ
の詳細は実装依存である。 glibc の場合、まず最初に (どんな category に対
し ても) 環境変数 LC_ALL が検査される。次にカテゴリ (category) と同じ名
前 の 環 境 変 数 (LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY,
LC_NUMERIC, LC_TIME) が検査され、最後に環境変数 LANG が検査される。最初
に見つかった環境変数を使用する。その値がロケール指定として正しくなけ れ
ば、ロケールは変更されず、 setlocale() は NULL を返す。
"C" ロ ケ ー ル や "POSIX" ロケールは互換性のあるロケールである。この
LC_CTYPE の部分は 7 ビット ASCII 文字集合に相当している。
ロケール名の書式は、通常 language[_territory][.codeset][@modifier] とい
うものである。ここで language は ISO 639 の言語コードである。 territory
は ISO 3166 の国名コードである。 codeset は ISO-8859-1 や UTF-8 のよ う
な 文字集合や文字符号化識別子である。サポートされているロケールの一覧を
得るには、 "locale -a" を実行してみよ (locale(1) 参照のこと)。
locale が NULL ならば、現在のロケールを問い合わせるのみで変更はしない。
main プログラムの起動時には、互換性のある "C" ロケールがデフォルトで選
択される。プログラムをすべてのロケールに対して互換にしたければ、プロ グ
ラムの初期化の後に
setlocale(LC_ALL, "");
を 呼 び 出 し 、 ロケール依存の情報には localeconv(3) の返り値を用い、
MB_CUR_MAX > 1 の場合には文字列の操作には多バイト文字、ワイド文字関数を
使 用 し 、 文 字 列 の 比 較には strcoll(3), wcscoll(3) や strxfrm(3),
wcsxfrm(3) を用いる。
返り値
setlocale() の呼び出しに成功すると、そのロケール集合に対応する内部文 字
列 (opaque string) を返す。この文字列は静的な記憶域に割り当てられている
かもしれない。この返って来た文字列を、カテゴリ指定と共に、のちの setlo-
cale の呼び出しに指定すれば、プロセスのその部分のロケールが復元される。
設定に失敗した場合には、返り値は NULL になる。
準拠
C89, C99, POSIX.1-2001.
注意
Linux (というか glibc) は互換性のあるロケールとして "C" と "POSIX" をサ
ポ ートしている。古きよき時代には (例えば libc-4.5.21 と libc-4.6.27 な
どでは)、 European Latin-1 向けに "ISO-8859-1" ロケールがサポートされて
お り、ロシア語 (Russian) 向けに "KOI-8" (より正確には "koi-8r") ロケー
ルがサポートされていた。従って環境変数を LC_CTYPE=ISO-8859-1 と指定する
だ けで isprint(3) は正しい答えを返した。最近では、英語以外を使うヨーロ
ッパ人はもう少々やっかいな作業を必要とし、実際のロケールファイルをイ ン
ストールしなければならない。
関連項目
locale(1), localedef(1), isalpha(3), localeconv(3), nl_langinfo(3),
rpmatch(3), strcoll(3), strftime(3), charsets(7), locale(7)
GNU 2008-12-05 SETLOCALE(3)
SETLOCALE(3) Linux Programmer’s Manual SETLOCALE(3)
NAME
setlocale - set the current locale
SYNOPSIS
#include
char *setlocale(int category, const char *locale);
DESCRIPTION
The setlocale() function is used to set or query the program’s current
locale.
If locale is not NULL, the program’s current locale is modified accord-
ing to the arguments. The argument category determines which parts of
the program’s current locale should be modified.
LC_ALL for all of the locale.
LC_COLLATE
for regular expression matching (it determines the meaning of
range expressions and equivalence classes) and string collation.
LC_CTYPE
for regular expression matching, character classification, con-
version, case-sensitive comparison, and wide character func-
tions.
LC_MESSAGES
for localizable natural-language messages.
LC_MONETARY
for monetary formatting.
LC_NUMERIC
for number formatting (such as the decimal point and the thou-
sands separator).
LC_TIME
for time and date formatting.
The argument locale is a pointer to a character string containing the
required setting of category. Such a string is either a well-known
constant like "C" or "da_DK" (see below), or an opaque string that was
returned by another call of setlocale().
If locale is "", each part of the locale that should be modified is set
according to the environment variables. The details are implementa-
tion-dependent. For glibc, first (regardless of category), the envi-
ronment variable LC_ALL is inspected, next the environment variable
with the same name as the category (LC_COLLATE, LC_CTYPE, LC_MESSAGES,
LC_MONETARY, LC_NUMERIC, LC_TIME) and finally the environment variable
LANG. The first existing environment variable is used. If its value
is not a valid locale specification, the locale is unchanged, and set-
locale() returns NULL.
The locale "C" or "POSIX" is a portable locale; its LC_CTYPE part cor-
responds to the 7-bit ASCII character set.
A locale name is typically of the form language[_territory][.code-
set][@modifier], where language is an ISO 639 language code, territory
is an ISO 3166 country code, and codeset is a character set or encoding
identifier like ISO-8859-1 or UTF-8. For a list of all supported
locales, try "locale -a", cf. locale(1).
If locale is NULL, the current locale is only queried, not modified.
On startup of the main program, the portable "C" locale is selected as
default. A program may be made portable to all locales by calling:
setlocale(LC_ALL, "");
after program initialization, by using the values returned from a
localeconv(3) call for locale-dependent information, by using the
multi-byte and wide character functions for text processing if
MB_CUR_MAX > 1, and by using strcoll(3), wcscoll(3) or strxfrm(3),
wcsxfrm(3) to compare strings.
RETURN VALUE
A successful call to setlocale() returns an opaque string that corre-
sponds to the locale set. This string may be allocated in static stor-
age. The string returned is such that a subsequent call with that
string and its associated category will restore that part of the pro-
cess’s locale. The return value is NULL if the request cannot be hon-
ored.
CONFORMING TO
C89, C99, POSIX.1-2001.
NOTES
Linux (that is, glibc) supports the portable locales "C" and "POSIX".
In the good old days there used to be support for the European Latin-1
"ISO-8859-1" locale (e.g., in libc-4.5.21 and libc-4.6.27), and the
Russian "KOI-8" (more precisely, "koi-8r") locale (e.g., in
libc-4.6.27), so that having an environment variable
LC_CTYPE=ISO-8859-1 sufficed to make isprint(3) return the right
answer. These days non-English speaking Europeans have to work a bit
harder, and must install actual locale files.
SEE ALSO
locale(1), localedef(1), isalpha(3), localeconv(3), nl_langinfo(3),
rpmatch(3), strcoll(3), strftime(3), charsets(7), locale(7)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU 2008-12-05 SETLOCALE(3)