setlocale

Section: C Library Functions (3)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

setlocale - 現在のロケール (locale) を設定する  

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#include <locale.h>

char *setlocale(int category, const char *_Nullable locale);
 

説明

setlocale() 関数はプログラムのカレントロケールを設定したり 問い合わせたりするのに用いられる。

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:

•
using the values returned from a localeconv(3) call for locale-dependent information;
•
using the multibyte and wide character functions for text processing if MB_CUR_MAX > 1;
•
using strcoll(3) and strxfrm(3) to compare strings; and
•
using wcscoll(3) and wcsxfrm(3) to compare wide-character strings.
 

返り値

setlocale() の呼び出しに成功すると、 そのロケール集合に対応する内部文字列 (opaque string) を返す。 この文字列は静的な記憶域に割り当てられているかもしれない。 この返って来た文字列を、カテゴリー指定と共に、 のちの setlocale の呼び出しに指定すれば、 プロセスのその部分のロケールが復元される。 設定に失敗した場合には、返り値は NULL になる。  

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース属性値
setlocale() Thread safetyMT-Unsafe const:locale env
 

標準規格

C11, POSIX.1-2008.  

Categories

LC_ALL
LC_COLLATE
LC_CTYPE
LC_MONETARY
LC_NUMERIC
LC_TIME
C11, POSIX.1-2008.
LC_MESSAGES
POSIX.1-2008.
Others:
GNU.
 

歴史

POSIX.1-2001, C89.  

Categories

LC_ALL
LC_COLLATE
LC_CTYPE
LC_MONETARY
LC_NUMERIC
LC_TIME
C89, POSIX.1-2001.
LC_MESSAGES
POSIX.1-2001.
Others:
GNU.
 

関連項目

locale(1), localedef(1), isalpha(3), localeconv(3), nl_langinfo(3), rpmatch(3), strcoll(3), strftime(3), charsets(7), locale(7)


 

Index

名前
ライブラリ
書式
説明
返り値
属性
標準規格
Categories
歴史
Categories
関連項目

This document was created by man2html, using the manual pages.