wcrtomb

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

名前

wcrtomb - ワイド文字 1 つをマルチバイト列に変換する  

ライブラリ

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

書式

#include <wchar.h>

size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict ps);
 

説明

The main case for this function is when s is not NULL and wc is not a null wide character (L'\0'). In this case, the wcrtomb() function converts the wide character wc to its multibyte representation and stores it at the beginning of the character array pointed to by s. It updates the shift state *ps, and returns the length of said multibyte representation, that is, the number of bytes written at s.

A different case is when s is not NULL, but wc is a null wide character (L'\0'). In this case, the wcrtomb() function stores at the character array pointed to by s the shift sequence needed to bring *ps back to the initial state, followed by a '\0' byte. It updates the shift state *ps (i.e., brings it into the initial state), and returns the length of the shift sequence plus one, that is, the number of bytes written at s.

三番目のケースは、s が NULL の時である。 この場合には wc は無視され、関数の実際の動きとしては

wcrtomb(buf, L'\0', ps)

が返される。ここで、 buf は内部的な無名バッファーである。

以上のいずれの場合も、ps が NULL ならばシフト状態は用い られず、 wcrtomb() 関数だけが知っている静的な匿名の状態が使われる。

At most MB_CUR_MAX bytes will be written at s. The programmer must ensure that there is enough room to store the multibyte sequence at s.  

返り値

wcrtomb() 関数は、s が指すバイト列に書き込まれたバイト数、あ るいは書き込まれたであろうバイト数を返す。wc を(現在のロケールに 従って)マルチバイト列で表現できなければ、 (size_t) -1 が返され、 errno に EILSEQ が設定される。  

属性

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

標準規格

C11, POSIX.1-2008.  

歴史

POSIX.1-2001, C99.  

注意

wcrtomb() の動作は、現在のロケールの LC_CTYPE カテゴリーに依存する。

ps に NULL を渡した際の動作はマルチスレッドセーフでない。  

関連項目

mbsinit(3), wcsrtombs(3)


 

Index

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

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