OSDN Git Service

Update release for LDP 3.67
[linuxjm/LDP_man-pages.git] / release / man3 / mbstowcs.3
index 67c4e9f..f5242d9 100644 (file)
@@ -1,9 +1,13 @@
+.\" t -*- coding: UTF-8 -*-
 .\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
+.\" and Copyright 2014 Michael Kerrisk <mtk.manpages@gmail.com>
 .\"
+.\" %%%LICENSE_START(GPLv2+_DOC_ONEPARA)
 .\" This is free documentation; you can redistribute it and/or
 .\" modify it under the terms of the GNU General Public License as
 .\" published by the Free Software Foundation; either version 2 of
 .\" the License, or (at your option) any later version.
+.\" %%%LICENSE_END
 .\"
 .\" References consulted:
 .\"   GNU glibc-2 source code and manual
 .\"   OpenGroup's Single UNIX specification http://www.UNIX-systems.org/online.html
 .\"   ISO/IEC 9899:1999
 .\"
+.\"*******************************************************************
+.\"
+.\" This file was generated with po4a. Translate the source file.
+.\"
+.\"*******************************************************************
+.\"
 .\" Japanese Version Copyright (c) 1999 HANATAKA Shinya
 .\"         all rights reserved.
 .\" Translated Tue Jan 11 00:56:04 JST 2000
 .\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
 .\"
-.TH MBSTOWCS 3  2011-09-28 "GNU" "Linux Programmer's Manual"
-.SH Ì¾Á°
-mbstowcs \- ¥Þ¥ë¥Á¥Ð¥¤¥Èʸ»úÎó¤ò¥ï¥¤¥Éʸ»úÎó¤ËÊÑ´¹¤¹¤ë
-.SH ½ñ¼°
+.TH MBSTOWCS 3 2014\-03\-18 GNU "Linux Programmer's Manual"
+.SH 名前
+mbstowcs \- マルチバイト文字列をワイド文字列に変換する
+.SH 書式
 .nf
-.B #include <stdlib.h>
+\fB#include <stdlib.h>\fP
 .sp
-.BI "size_t mbstowcs(wchar_t *" dest ", const char *" src ", size_t " n );
+\fBsize_t mbstowcs(wchar_t *\fP\fIdest\fP\fB, const char *\fP\fIsrc\fP\fB, size_t \fP\fIn\fP\fB);\fP
 .fi
-.SH ÀâÌÀ
-\fIdest\fP ¤¬ NULL ¥Ý¥¤¥ó¥¿¡¼¤Ç¤Ê¤±¤ì¤Ð
-.BR mbstowcs ()
-´Ø¿ô¤Ï
-¥Þ¥ë¥Á¥Ð¥¤¥Èʸ»úÎó \fI*src\fP ¤ò \fIdest\fP ¤«¤é»Ï¤Þ¤ë¥ï¥¤¥Éʸ»úÎó¤Ë
-ÊÑ´¹¤¹¤ë¡£\fIdest\fP ¤Ë¤ÏºÇÂç¤Ç \fIn\fP Ê¸»ú¤Î¥ï¥¤¥Éʸ»ú¤¬
-½ñ¤­¹þ¤Þ¤ì¤ë¡£ÊÑ´¹¤Ï½é´ü¾õÂ֤dz«»Ï¤µ¤ì¡¢
-°Ê²¼¤Î»°¤Ä¤Î¤¤¤º¤ì¤«¤Î¾ò·ï¤ÇÄä»ß¤¹¤ë:
+.SH 説明
+\fIdest\fP が NULL でなければ \fBmbstowcs\fP()  関数は マルチバイト文字列 \fI*src\fP を \fIdest\fP
+から始まるワイド文字列に 変換する。\fIdest\fP には最大で \fIn\fP 文字のワイド文字が 書き込まれる。変換は初期状態で開始され、
+以下の三つのいずれかの条件で停止する:
 .IP 1. 3
-ÉÔÀµ¤Ê¥Þ¥ë¥Á¥Ð¥¤¥ÈÎó¤ËÁø¶ø¤·¤¿¡£¤³¤Î¾ì¹ç¤Ë¤Ï
-.I (size_t)\ \-1
-¤òÊÖ¤¹¡£
+不正なマルチバイト列に遭遇した。この場合には \fI(size_t)\ \-1\fP を返す。
 .IP 2.
-\fIn\fP Ê¸»ú¤Î L\(aq\\0\(aq °Ê³°¤Î¥ï¥¤¥Éʸ»ú¤ò \fIdest\fP ¤Ë³ÊǼ¤·¤¿¾ì¹ç¡£
-¤³¤Î¾ì¹ç¤Ï \fI*src\fP ¤¬¼¡¤ËÊÑ´¹¤µ¤ì¤ë¥Þ¥ë¥Á¥Ð¥¤¥ÈÎó¤ò»Ø¤¹¤è¤¦¤Ë¤·¤Æ¡¢
-\fIdest\fP ¤Ë½ñ¤­¹þ¤Þ¤ì¤¿¥ï¥¤¥Éʸ»ú¤Î¿ô¤òÊÖ¤¹¡£¤·¤«¤·¤³¤Î»Ø¤·¤Æ¤¤¤ë
-¾ì½ê¤Î¥·¥Õ¥È¾õÂ֤ϼº¤ï¤ì¤ë¡£
+\fIn\fP 文字の L\(aq\e0\(aq 以外のワイド文字を \fIdest\fP に格納した場合。 この場合は \fI*src\fP
+が次に変換されるマルチバイト列を指すようにして、 \fIdest\fP に書き込まれたワイド文字の数を返す。しかしこの指している 場所のシフト状態は失われる。
 .IP 3.
-¥Þ¥ë¥Á¥Ð¥¤¥Èʸ»úÎ󤬽ªÃ¼¤Î NULL ¥ï¥¤¥Éʸ»ú (\(aq\\0\(aq) ¤Þ¤Ç´Þ¤á¤Æ´°Á´¤Ë
-ÊÑ´¹¤µ¤ì¤¿¾ì¹ç¡£¤³¤Î¾ì¹ç¤Ï½ªÃ¼¤Î NULL ¥ï¥¤¥Éʸ»ú¤ò½ü¤¤¤Æ
-\fIdest\fP ¤Ë½ñ¤­¹þ¤Þ¤ì¤¿Ê¸»ú¿ô¤òÊÖ¤¹¡£
+マルチバイト文字列が終端のヌルワイド文字 (\(aq\e0\(aq) まで含めて完全に 変換された場合。この場合は終端のヌルワイド文字を除いて
+\fIdest\fP に書き込まれた文字数を返す。
 .PP
-¥×¥í¥°¥é¥Þ¡¼¤Ï \fIdest\fP ¤ËºÇÄã¤Ç¤â \fIn\fP ¥ï¥¤¥Éʸ»ú¤ò½ñ¤­¹þ¤à¤³
-¤È¤¬¤Ç¤­¤ë¶õ´Ö¤¬¤¢¤ë¤³¤È¤òÊݾڤ·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
+プログラマーは \fIdest\fP に最低でも \fIn\fP ワイド文字を書き込むこ とができる空間があることを保証しなければならない。
 .PP
-\fIdest\fP ¤¬ NULL ¤Î¾ì¹ç¡¢\fIn\fP ¤Ï̵»ë¤µ¤ì¡¢¾åµ­¤ÈƱÍͤÎÊÑ´¹¤¬
-¹Ô¤ï¤ì¤ë¤¬¡¢ÊÑ´¹¤µ¤ì¤¿¥ï¥¤¥Éʸ»ú¤Ï¥á¥â¥ê¤Ë½ñ¤­¹þ¤Þ¤ì¤º¡¢ÊÑ´¹Àè¤Î¾å¸Â
-¤¬Â¸ºß¤·¤Ê¤¤¡£
+\fIdest\fP が NULL の場合、\fIn\fP は無視され、上記と同様の変換が 行われるが、変換されたワイド文字はメモリに書き込まれず、変換先の上限
+が存在しない。
 .PP
-¾åµ­¤Î 2. ¤Î¾ì¹ç¤òÈò¤±¤ë¤¿¤á¤Ë¥×¥í¥°¥é¥Þ¡¼¤Ï \fIn\fP ¤¬
-\fImbstowcs(NULL,src,0)+1\fP °Ê¾å¤Ç¤¢¤ë¤³¤È¤òÊݾڤ¹¤Ù¤­¤Ç¤¢¤ë¡£
-.SH ÊÖ¤êÃÍ
-.BR mbstowcs ()
-´Ø¿ô¤Ï¥ï¥¤¥Éʸ»úÎó¤ËÊÑ´¹´°Î»¤·¤¿¥ï¥¤¥Éʸ»ú¤Î¿ô¤òÊÖ¤¹¡£
-½ªÃ¼¤Î¥Ê¥ë¥ï¥¤¥Éʸ»ú¤Ï´Þ¤Þ¤Ê¤¤¡£ÉÔÀµ¤Ê¥Þ¥ë¥Á¥Ð¥¤¥ÈÎó¤ËÁø¶ø¤·¤¿¾ì¹ç¤Ë¤Ï
-.I (size_t)\ \-1
-¤òÊÖ¤¹¡£
-.SH ½àµò
+上記の 2. の場合を避けるためにプログラマーは \fIn\fP が \fImbstowcs(NULL,src,0)+1\fP 以上であることを保証すべきである。
+.SH 返り値
+\fBmbstowcs\fP()  関数はワイド文字列に変換完了したワイド文字の数を返す。
+終端のヌルワイド文字は含まない。不正なマルチバイト列に遭遇した場合には \fI(size_t)\ \-1\fP を返す。
+.SH 準拠
 C99.
-.SH Ãí°Õ
-.BR mbstowcs ()
-¤ÎÆ°ºî¤Ï¸½ºß¤Î¥í¥±¡¼¥ë¤Î
-.B LC_CTYPE
-¥«¥Æ¥´¥ê¤Ë°Í¸¤·¤Æ¤¤¤ë¡£
+.SH 注意
+\fBmbstowcs\fP()  の動作は現在のロケールの \fBLC_CTYPE\fP カテゴリに依存している。
 .PP
-.BR mbsrtowcs (3)
-´Ø¿ô¤ÏƱ¤¸µ¡Ç½¤Î¤è¤êÎɤ¤¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤òÄ󶡤¹¤ë¡£
-.SH ´ØÏ¢¹àÌÜ
-.BR mbsrtowcs (3),
-.BR wcstombs(3)
+\fBmbsrtowcs\fP(3)  関数は同じ機能のより良いインターフェースを提供する。
+.SH 例
+下記のプログラムは \fBmbstowcs\fP() といくつかのワイド文字分類関数の使用方法を示したものである。実行例は以下のようになる。
+.in +4n
+.nf
+
+$ ./t_mbstowcs de_DE.UTF\-8 Grüße!
+Length of source string (excluding terminator):
+    8 bytes
+    6 multibyte characters
+
+Wide character string is: Grüße! (6 characters)
+    G alpha upper
+    r alpha lower
+    ü alpha lower
+    ß alpha lower
+    e alpha lower
+    ! !alpha
+.fi
+.in
+.SS プログラムのソース
+.nf
+#include <locale.h>
+#include <wchar.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+int
+main(int argc, char *argv[])
+{
+    size_t mbslen;      /* Number of multibyte characters in source */
+    wchar_t *wcs;       /* Pointer to converted wide character string */
+    wchar_t *wp;
+
+    if (argc < 3) {
+        fprintf(stderr, "Usage: %s <locale> <string>\en", argv[0]);
+        exit(EXIT_FAILURE);
+    }
+
+    /* Apply the specified locale */
+
+    if (setlocale(LC_ALL, argv[1]) == NULL) {
+        perror("setlocale");
+        exit(EXIT_FAILURE);
+    }
+
+    /* Calculate the length required to hold argv[2] converted to
+       a wide character string */
+
+    mbslen = mbstowcs(NULL, argv[2], 0);
+    if (mbslen == (size_t) \-1) {
+        perror("mbstowcs");
+        exit(EXIT_FAILURE);
+    }
+
+    /* Describe the source string to the user */
+
+    printf("Length of source string (excluding terminator):\en");
+    printf("    %zu bytes\en", strlen(argv[2]));
+    printf("    %zu multibyte characters\en\en", mbslen);
+
+    /* Allocate wide character string of the desired size.  Add 1
+       to allow for terminating null wide character (L\(aq\e0\(aq). */
+
+    wcs = calloc(mbslen + 1, sizeof(wchar_t));
+    if (wcs == NULL) {
+        perror("calloc");
+        exit(EXIT_FAILURE);
+    }
+
+    /* Convert the multibyte character string in argv[2] to a
+       wide character string */
+
+    if (mbstowcs(wcs, argv[2], mbslen + 1) == (size_t) \-1) {
+        perror("mbstowcs");
+        exit(EXIT_FAILURE);
+    }
+
+    printf("Wide character string is: %ls (%zu characters)\en",
+            wcs, mbslen);
+
+    /* Now do some inspection of the classes of the characters in
+       the wide character string */
+
+    for (wp = wcs; *wp != 0; wp++) {
+        printf("    %lc ", (wint_t) *wp);
+
+        if (!iswalpha(*wp))
+            printf("!");
+        printf("alpha ");
+
+        if (iswalpha(*wp)) {
+            if (iswupper(*wp))
+                printf("upper ");
+
+            if (iswlower(*wp))
+                printf("lower ");
+        }
+
+        putchar(\(aq\en\(aq);
+    }
+
+    exit(EXIT_SUCCESS);
+}
+.fi
+.SH 関連項目
+\fBmblen\fP(3), \fBmbsrtowcs\fP(3), \fBmbtowc\fP(3), \fBwctomb\fP(3), \fBwcstombs\fP(3)
+.SH この文書について
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.67 の一部
+である。プロジェクトの説明とバグ報告に関する情報は
+http://www.kernel.org/doc/man\-pages/ に書かれている。