.\" Copyright (C) 2014 Michael Kerrisk .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH DUPLOCALE 3 2020\-11\-01 Linux "Linux Programmer's Manual" .SH 名前 duplocale \- ロケールオブジェクトを複製する .SH 書式 .nf \fB#include \fP .PP \fBlocale_t duplocale(locale_t \fP\fIlocobj\fP\fB);\fP .fi .PP .RS -4 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .RE .PP \fBduplocale\fP(): .PD 0 .RS 4 .TP glibc 2.10 以降: _XOPEN_SOURCE\ >=\ 700 .TP glibc 2.10 より前: _GNU_SOURCE .RE .PD .SH 説明 \fBduplocale\fP() 関数は \fIlocobj\fP が参照するロケールオブジェクトの複製を作成する。 .PP \fIlocobj\fP が \fBLC_GLOBAL_LOCALE\fP の場合、 \fBduplocale\fP() は \fBsetlocale\fP(3) により判定されたグローバルロケールのコピーを含むロケールオブジェクトを作成する。 .SH 返り値 成功すると、 \fBduplocale\fP() は新しいロケールオブジェクトのハンドルを返す。 エラーの場合、 \fI(locale_t)\ 0\fP を返し、 \fIerrno\fP にエラーの原因を示す値を設定する。 .SH エラー .TP \fBENOMEM\fP ロケールオブジェクトの複製を作成するのに十分なメモリーがない。 .SH バージョン \fBduplocale\fP() 関数は GNU C ライブラリのバージョン 2.3 で初めて登場した。 .SH 準拠 POSIX.1\-2008. .SH 注意 ロケールの複製は以下のことを行う際に役立つ。 .IP * 3 ロケールオブジェクトのコピーを作成し、 (\fBnewlocale\fP(3) を使って) いくつかのカテゴリーだけを変更する。 .IP * 現在のロケールに対するハンドルを取得する。 このハンドルはロケールハンドルを受け取る他の関数 (\fBtoupper_l\fP(3) など) で使用できる。 これを行うには、 以下の呼び出しが返した値を \fBduplocale\fP() に渡せばよい。 .IP loc = uselocale((locale_t) 0); .IP 上記の \fBuselocale\fP(3) の呼び出しは値 \fBLC_GLOBAL_LOCALE\fP を返すことがあり、 この値を \fBtoupper_l\fP(3) などの関数に渡した場合の動作は不定なので、 この方法は必要である。 \fBduplocale\fP() を呼び出すことで、確実に \fBLC_GLOBAL_LOCALE\fP が使用可能なロケールオブジェクトに変換することができる。 下記の「例」を参照。 .PP \fBduplocale\fP() で作成された各ロケールオブジェクトは \fBfreelocale\fP(3) を使って解放すべきである。 .SH 例 以下のプログラムでは、 \fBtoupper_l\fP(3) に渡す現在のロケールのハンドルを取得するのに \fBuselocale\fP(3) と \fBduplocale\fP() を使用する。 このプログラムはコマンドライン引数として文字列を一つ取る。この文字列は、大文字に変換され、標準出力に表示される。 以下は使用例である。 .PP .in +4n .EX $ \fB./a.out abc\fP ABC .EE .in .SS プログラムのソース \& .EX #define _XOPEN_SOURCE 700 #include #include #include #include #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e } while (0) int main(int argc, char *argv[]) { locale_t loc, nloc; if (argc != 2) { fprintf(stderr, "Usage: %s string\en", argv[0]); exit(EXIT_FAILURE); } /* この一連の処理は必要である。 uselocale() は toupper_l() の 引数として渡すことができない値 LC_GLOBAL_LOCALE を返す 可能性があるからである。 */ loc = uselocale((locale_t) 0); if (loc == (locale_t) 0) errExit("uselocale"); nloc = duplocale(loc); if (nloc == (locale_t) 0) errExit("duplocale"); for (char *p = argv[1]; *p; p++) putchar(toupper_l(*p, nloc)); printf("\en"); freelocale(nloc); exit(EXIT_SUCCESS); } .EE .SH 関連項目 \fBfreelocale\fP(3), \fBnewlocale\fP(3), \fBsetlocale\fP(3), \fBuselocale\fP(3), \fBlocale\fP(5), \fBlocale\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。