mbrtowcのヘルプ・マニュアル
日本語 英語
mbrtowc --help
man mbrtowc
MBRTOWC(3) Linux Programmer’s Manual MBRTOWC(3)
名前
mbrtowc - マルチバイト列をワイド文字に変換する
書式
#include
size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
説明
こ の関数が用いられる場合、通常 s が NULL でなく pwc も NULL でない。こ
の場合は、 mbrtowc() 関数は s から始まる最大 n バイトのマルチバイト文字
を 検査して、次の完全なマルチバイト文字列を取り出し、それをワイド文字に
変換して *pwc に格納する。同時にシフト状態 *ps を更新する。変換したワイ
ド文字が L'\0' でなければ、s から消費するバイト数を返す。変換したワイド
文字が L'\0' の場合にはシフト状態 *ps を初期状態に戻して 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));
返り値
L'\0' 以外のワイド文字を認識した場合には mbrtowc() 関数は s から始ま る
マルチバイト列から解析したバイト数を返す。 L'\0' ワイド文字を認識した場
合には 0 を返す。不正なマルチバイト列に遭遇した場合には (size_t) -1 を
返し、 errno に EILSEQ を設定する。完全なマルチバイト文字を解析できなか
った場合には (size_t) -2 を返し n を増加させる必要があることを示す。
準拠
C99.
注意
mbrtowc() の動作は現在のロケールの LC_CTYPE カテゴリに依存している。
関連項目
mbsrtowcs(3)
GNU 2001-11-22 MBRTOWC(3)
MBRTOWC(3) Linux Programmer’s Manual MBRTOWC(3)
NAME
mbrtowc - convert a multibyte sequence to a wide character
SYNOPSIS
#include
size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
DESCRIPTION
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 multi-
byte 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', 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.
If the n bytes starting at s do not contain a complete multibyte char-
acter, mbrtowc() returns (size_t) -2. This can happen even if n >=
MB_CUR_MAX, if the multibyte string contains redundant shift sequences.
If the multibyte string starting at s contains an invalid multibyte
sequence before the next complete character, mbrtowc() returns
(size_t) -1 and sets errno to EILSEQ. In this case, the effects on *ps
are undefined.
A different case is when s is not NULL but pwc is NULL. In this case
the mbrtowc() function behaves as above, except that it does not store
the converted wide character in memory.
A third case is when s is NULL. In this case, pwc and n are ignored.
If the conversion state represented by *ps denotes an incomplete multi-
byte character conversion, the mbrtowc() function returns (size_t) -1,
sets errno to EILSEQ, and leaves *ps in an undefined state. Otherwise,
the mbrtowc() function puts *ps in the initial state and returns 0.
In all of the above cases, if ps is a NULL pointer, a static anonymous
state only known to the mbrtowc function is used instead. Otherwise,
*ps must be a valid mbstate_t object. An mbstate_t object a can be
initialized to the initial state by zeroing it, for example using
memset(&a, 0, sizeof(a));
RETURN VALUE
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 multi-
byte sequence was encountered. It returns (size_t) -2 if it couldn’t
parse a complete multibyte character, meaning that n should be
increased.
CONFORMING TO
C99.
NOTES
The behavior of mbrtowc() depends on the LC_CTYPE category of the cur-
rent locale.
SEE ALSO
mbsrtowcs(3)
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 2001-11-22 MBRTOWC(3)