#include <locale.h> char *setlocale(int category, const char *_Nullable locale);
locale が NULL でなければ、プログラムのカレントロケールは引数に従って変更される。 引数 category はプログラムのカレントロケールのどの部分を変更するかを決める。
| カテゴリー | 制御対象 |
| LC_ALL | 全てのロケール |
| LC_ADDRESS |
Formatting of addresses and
geography-related items (*)
|
| LC_COLLATE | 文字の照合順序 |
| LC_CTYPE | 文字の分類 |
| LC_IDENTIFICATION |
ロケールの説明メタデータ (*)
|
| LC_MEASUREMENT |
Settings related to measurements
(metric versus US customary) (*)
|
| LC_MESSAGES |
地域化可能な自然言語メッセージ
|
| LC_MONETARY |
金額の表示方法
|
| LC_NAME |
人へのあいさつの言葉
|
| LC_NUMERIC |
金額以外の数値の表示方法
|
| LC_PAPER |
標準の紙のサイズに関する設定 (*)
|
| LC_TELEPHONE |
電話サービスで使用されるフォーマット (*)
|
| LC_TIME |
日付と時刻の表示方法
|
上の表でアスタリスクが付い ているたカテゴリーは GNU 拡張である。 ロケールのカテゴリーの詳細な情報は locale(7) を参照。
引数 locale は category に設定する文字列へのポインターである。 この文字列はよく知られた定数である "C" や "da_DK" などでも良いし (以下を参照)、他のときに setlocale() を呼び出した際に返された、内部用の文字列でも良い。
If locale is an empty string, "", each part of the locale that should be modified is set according to the environment variables. The details are implementation-dependent. For glibc, first (regardless of category), the environment variable LC_ALL is inspected, next the environment variable with the same name as the category (see the table above), 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 setlocale() returns NULL.
The locale "C" or "POSIX" is a portable locale; it exists on all conforming systems.
A locale name is typically of the form language[_territory][.codeset][@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" (see locale(1)).
locale が NULL ならば、現在のロケールを問い合わせるのみで変更はしない。
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, and then:
| インターフェース | 属性 | 値 |
| setlocale() | Thread safety | MT-Unsafe const:locale env |