mbrtowc
Section: C Library Functions (3)
Updated: 2026-02-08
Index
JM Home Page
roff page
名前
mbrtowc - マルチバイト列をワイド文字に変換する
ライブラリ
標準 C ライブラリ (libc,~-lc)
書式
#include <wchar.h>
size_t mbrtowc(size_t n;
wchar_t *restrict pwc, const char s[restrict n],
size_t n, mbstate_t *restrict ps);
説明
The main case for this function is when s is not NULL and pwc is not
NULL. In this case, the mbrtowc() function inspects at most n bytes
of the multibyte string starting at s, extracts the next complete
multibyte character, converts it to a wide character and stores it at
*pwc. It updates the shift state *ps. If the converted wide
character is not L'\0' (the null wide character), it returns the
number of bytes that were consumed from s. If the converted wide
character is L'\0', it resets the shift state *ps to the
initial state and returns 0.
s から始まる n バイトが完全なマルチバイト文字を含んでいない 場合には、 mbrtowc() は (size_t) -2
を返す。 マルチバイト文字列に冗長なシフトシーケンスが含まれていると、 n >= MB_CUR_MAX
の時にもこのようなことが起こりえる。
s から始まるマルチバイト文字列が、次の完全な文字の前に 不正なマルチバイト列を含んでいる場合には、 mbrtowc() は
(size_t) -1 を返し、errno に EILSEQ を設定する。 この場合は *ps への影響は未定義である。
s が NULL でなく pwc が NULL の場合は mbrtowc() 関数は
上記と同様に動作するが、変換したワイド文字はメモリーには書き込まれない。
puts *ps in the initial state and returns 0. 三番目の場合として s が NULL の場合、
pwc と n は 無視される。 *ps が表現する変換状態が不完全なマルチバイト文字変換を示している場合は、
mbrtowc() 関数は (size_t) -1 を返し、 errno に EILSEQ をセットし、 *ps
は未定義状態のままにする。 さもなければ、 mbrtowc() 関数は *ps を初期状態にして 0 を返す。
上記の全ての場合において、ps が NULL ならば代わりに mbrtowc() 関数のみが使用する静的で名前のない状態が使用される。
さもなければ、*ps は有効な mbstate_t オブジェクトで なければならない。 mbstate_t オブジェクトである
a はゼロで埋めることによって 初期状態に初期化できる。以下に例を示す。
memset(&a, 0, sizeof(a));
返り値
The mbrtowc() function returns the number of bytes parsed from the
multibyte sequence starting at s, if a non-L'\0' wide
character was recognized. It returns 0, if a L'\0' wide
character was recognized. It returns (size_t) -1 and sets errno to
EILSEQ, if an invalid multibyte sequence was encountered. It returns
(size_t) -2 if the consumed n bytes form a valid partial character
sequence; more subsequent data needs to be fed in.
属性
この節で使用されている用語の説明については、 attributes(7) を参照。
| インターフェース | 属性 | 値
|
|
mbrtowc()
| Thread safety | MT-Unsafe race:mbrtowc/!ps
|
標準規格
C11, POSIX.1-2008.
歴史
POSIX.1-2001, C99.
注意
mbrtowc() の動作は現在のロケールの LC_CTYPE カテゴリーに依存している。
関連項目
mbsinit(3), mbsrtowcs(3)
Index
- 名前
-
- ライブラリ
-
- 書式
-
- 説明
-
- 返り値
-
- 属性
-
- 標準規格
-
- 歴史
-
- 注意
-
- 関連項目
-
This document was created by
man2html,
using the manual pages.