OSDN Git Service

Update draft for LDP 3.67
[linuxjm/LDP_man-pages.git] / draft / man3 / printf.3
index 6cd5346..d6c2cc4 100644 (file)
 .\" This file was generated with po4a. Translate the source file.
 .\"
 .\"*******************************************************************
-.TH PRINTF 3 2013\-03\-05 GNU "Linux Programmer's Manual"
+.\"
+.\" Japanese Version Copyright (c) 1997 YOSHINO Takashi all rights reserved.
+.\" Translated 1998-02-17, YOSHINO Takashi <yoshino@civil.jcn.nihon-u.ac.jp>
+.\" Updated 2000-10-02, Kentaro Shirakata <argrath@ub32.org>
+.\" Updated 2001-01-29, Kentaro Shirakata <argrath@ub32.org>
+.\" Updated 2002-01-03, Kentaro Shirakata <argrath@ub32.org>
+.\" Updated 2002-10-17, Kentaro Shirakata <argrath@ub32.org>
+.\" Updated 2005-03-15, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
+.\" Updated 2006-07-20, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
+.\" Updated 2008-02-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.77
+.\" Updated 2009-03-03, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.19
+.\" Updated 2012-05-29, Akihiro MOTOKI <amotoki@gmail.com>
+.\" Updated 2013-05-06, Akihiro MOTOKI <amotoki@gmail.com>
+.\" Updated 2013-07-22, Akihiro MOTOKI <amotoki@gmail.com>
+.\"
+.TH PRINTF 3 2013\-12\-30 GNU "Linux Programmer's Manual"
 .SH 名前
 printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf \-
 指定された書式に変換して出力を行う
@@ -75,7 +90,7 @@ glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参
 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _ISOC99_SOURCE ||
 _POSIX_C_SOURCE\ >=\ 200112L;
 .br
-or \fIcc \-std=c99\fP
+または \fIcc \-std=c99\fP
 .RE
 .ad
 .SH 説明
@@ -85,7 +100,7 @@ or \fIcc \-std=c99\fP
 \fBvsprintf\fP(), \fBvsnprintf\fP()  は出力を文字列 \fIstr\fP に書き込む。
 .PP
 \fBsnprintf\fP()  と \fBvsnprintf\fP()  は最大で \fIsize\fP バイトを \fIstr\fP に書き込む (\fIsize\fP
-には文字列を終端する NULL バイト (\(aq\e0\(aq) もを含まれる)。
+には文字列を終端するヌルバイト (\(aq\e0\(aq) もを含まれる)。
 .PP
 \fBvprintf\fP(), \fBvfprintf\fP(), \fBvsprintf\fP(), \fBvsnprintf\fP()  の各関数はそれぞれ
 \fBprintf\fP(), \fBfprintf\fP(), \fBsprintf\fP(), \fBsnprintf\fP(),
@@ -100,11 +115,11 @@ C99 と POSIX.1\-2001 では、 \fBsprintf\fP(), \fBsnprintf\fP(), \fBvsprintf\f
 \fBvsnprintf\fP()  の呼び出しで、範囲が重複するオブジェクト間でコピーが発生する場合の 結果は不定であると規定されている
 (例えば、出力先の文字列と入力された 引き数の一つが同じバッファを参照している場合などである)。 「注意」の節を参照。
 .SS "Return Values"
-成功時には、上記の関数は書き込まれた文字数を返す (文字列の最後を示すために使用する NULL バイトは数に含まれない)。
+成功時には、上記の関数は書き込まれた文字数を返す (文字列の最後を示すために使用するヌルバイトは数に含まれない)。
 
 \fBsnprintf\fP()  と \fBvsnprintf\fP()  は、 \fIsize\fP バイトを越える文字数を書き込まない (\fIsize\fP
-には文字列を終端する NULL バイト (\(aq\e0\(aq) も含まれる)。 この制限によって出力が切り詰められた場合には、
-もし十分なスペースがあれば書き込まれたであろう文字の個数 (文字列を終端する NULL バイトを除く) を返す。 従って、返り値が \fIsize\fP
+には文字列を終端するヌルバイト (\(aq\e0\(aq) も含まれる)。 この制限によって出力が切り詰められた場合には、
+もし十分なスペースがあれば書き込まれたであろう文字の個数 (文字列を終端するヌルバイトを除く) を返す。 従って、返り値が \fIsize\fP
 以上だった場合、出力が切り詰められたことを意味する (後述の注意も参照のこと)。
 
 エラーが発生した場合は、負の数を返す。
@@ -204,8 +219,8 @@ glibc 2.2 では、さらに一つフラグ文字が追加されている。
 オプションである精度は、ピリオド (\(aq.\(aq) とそれに続く10進数という 形式で指定する (10進数はオプション) 。
 10進数の文字列の代わりに "*" や "*m$" (m は 10 進整数)を書くこともできる。 "*" と "*m$" はそれぞれ、次の引き数と m
 番目の引き数を精度として 使うことを指定する (これらの引き数は \fIint\fP 型でなければならない)。 精度として \(aq.\(aq
-だけが指定されたり、精度が負の数だった場合、 精度はゼロとみなされる。 \fBd\fP, \fBi\fP, \fBo\fP, \fBu\fP, \fBx\fP, \fBX\fP
-変換では、表示される最小の桁数を指定する。 \fBa\fP, \fBA\fP, \fBe\fP, \fBE\fP, \fBf\fP, \fBF\fP
+だけが指定された場合、 精度はゼロとみなされる。 精度が負の数だった場合、 精度は指定されなかったものとみなされる。 \fBd\fP, \fBi\fP, \fBo\fP,
+\fBu\fP, \fBx\fP, \fBX\fP 変換では、表示される最小の桁数を指定する。 \fBa\fP, \fBA\fP, \fBe\fP, \fBE\fP, \fBf\fP, \fBF\fP
 変換では、小数点以下に表示される数字の桁数を指定する。 \fBg\fP と \fBG\fP 変換では、有効数字の最大桁数を指定する。 \fBs\fP と \fBS\fP
 変換では、文字列から出力される最大文字数を指定する。
 .SS 長さ修飾子
@@ -303,27 +318,19 @@ NaN は文字列の先頭に `nan' をつけて表示するように規定され
 関数を初期シフト状態で呼び出してマルチバイト文字列に変換し、 変換されたマルチバイト文字列を出力する。
 .TP 
 \fBs\fP
-If no \fBl\fP modifier is present: The \fIconst char\ *\fP argument is expected to
-be a pointer to an array of character type (pointer to a string).
-Characters from the array are written up to (but not including) a
-terminating null byte (\(aq\e0\(aq); if a precision is specified, no more
-than the number specified are written.  If a precision is given, no null
-byte need be present; if the precision is not specified, or is greater than
-the size of the array, the array must contain a terminating null byte.
-
-If an \fBl\fP modifier is present: The \fIconst wchar_t\ *\fP argument is expected
-to be a pointer to an array of wide characters.  Wide characters from the
-array are converted to multibyte characters (each by a call to the
-\fBwcrtomb\fP(3)  function, with a conversion state starting in the initial
-state before the first wide character), up to and including a terminating
-null wide character.  The resulting multibyte characters are written up to
-(but not including) the terminating null byte.  If a precision is specified,
-no more bytes than the number specified are written, but no partial
-multibyte characters are written.  Note that the precision determines the
-number of \fIbytes\fP written, not the number of \fIwide characters\fP or \fIscreen
-positions\fP.  The array must contain a terminating null wide character,
-unless a precision is given and it is so small that the number of bytes
-written exceeds it before the end of the array is reached.
+\fBl\fP 修飾子がない場合、 引き数は \fIconst char\ *\fP 型で文字型の配列へのポインタ (文字列へのポインタ) であることが
+期待されている。配列中の文字は、終端の ヌルバイト (\(aq\e0\(aq)  が出てくるまで出力される (終端文字は出力されない)。
+精度が指定されていると、指定された字数以上は出力されない。 精度が指定された場合には、終端バイトが存在する必要はない。
+精度が指定されていなかったり、精度の値が配列の大きさより大きい場合には、 配列は終端のヌルバイトを含んでいなければならない。
+
+\fBl\fP 修飾子が指定されている場合、 引き数は \fIconst wchar_t\ *\fP 型でワイド文字の配列へのポインタであることが期待されている。
+配列中のワイド文字は (1文字毎に \fBwcrtomb\fP(3)  を呼び出して) マルチバイト文字に変換される (最初のワイド文字の変換の前に
+\fBwcrtomb\fP()  のシフト状態を初期状態に戻してから変換は行われる)。 マルチバイト文字への変換は、文字列を終端するヌルワイド文字が
+出てくるまで行われ、終端ヌルワイド文字も含めて変換される。 結果のマルチバイト文字列は、終端のヌルバイトが出てくるまで 出力される
+(終端のヌルバイトは出力されない)。 精度が指定された場合、指定されたバイト数以上には出力されない。
+但し、マルチバイト文字の一部分だけが出力されることはない。 精度は「バイト」数を指定するものであり、「ワイド文字」数や
+「画面での位置」を指定するものではないことに注意。 精度が指定されていて、さらに出力が配列の末尾に達する前に出力バイト数が
+精度の値を超える場合だけは、配列はヌルワイド文字で終端されていなくてもよい。 それ以外の場合は、必ず配列はヌルワイド文字で終端されていなければならない。
 .TP 
 \fBC\fP
 (C99 にはないが SUSv2 にはある)  \fBlc\fP と同じ。使ってはならない。
@@ -332,12 +339,10 @@ written exceeds it before the end of the array is reached.
 (C99 にはないが SUSv2 にはある)  \fBls\fP と同じ。使ってはならない。
 .TP 
 \fBp\fP
-The \fIvoid\ *\fP pointer argument is printed in hexadecimal (as if by \fB%#x\fP
-or \fB%#lx\fP).
+\fIvoid\ *\fP ポインタ引き数を (\fB%#x\fP や \fB%#lx\fP のような) 16 進数で出力する。
 .TP 
 \fBn\fP
-The number of characters written so far is stored into the integer indicated
-by the \fIint\ *\fP (or variant) pointer argument.  No argument is converted.
+これまでに出力された文字数を \fIint\ *\fP (または類似の型) のポインタ引き数が指す整数に保存する。 引き数の変換は行われない。
 .TP 
 \fBm\fP
 (glibc での拡張)  \fIstrerror(errno)\fP の出力を表示する。引き数は必要ない。
@@ -473,8 +478,6 @@ fprintf(stdout, format,
 であれば、 "Sonntag, 3. Juli, 10:02" という結果になる。
 .PP
 十分に大きな文字列領域を確保して、そこにメッセージを格納するには (glibc 2.0 と glibc 2.1 の両方で正しく動作するコード):
-.PP
-バージョン 2.0.6 より前の glibc で切り詰めが起こった場合、切り詰めは適切に処理されず、エラーとして扱われる。
 .nf
 
 #include <stdio.h>
@@ -489,7 +492,8 @@ make_message(const char *fmt, ...)
     char *p, *np;
     va_list ap;
 
-    if ((p = malloc(size)) == NULL)
+    p = malloc(size);
+    if (p == NULL)
         return NULL;
 
     while (1) {
@@ -502,8 +506,10 @@ make_message(const char *fmt, ...)
 
         /* Check error code */
 
-        if (n < 0)
+        if (n < 0) {
+            free(p);
             return NULL;
+        }
 
         /* If that worked, return the string */
 
@@ -515,7 +521,8 @@ make_message(const char *fmt, ...)
         size = n + 1;       /* Precisely what is needed */
 
 
-        if ((np = realloc (p, size)) == NULL) {
+        np = realloc(p, size);
+        if (np == NULL) {
             free(p);
             return NULL;
         } else {
@@ -524,10 +531,12 @@ make_message(const char *fmt, ...)
     }
 }
 .fi
+.PP
+バージョン 2.0.6 より前の glibc で切り詰めが起こった場合、切り詰めは適切に処理されず、エラーとして扱われる。
 .SH 関連項目
 \fBprintf\fP(1), \fBasprintf\fP(3), \fBdprintf\fP(3), \fBscanf\fP(3), \fBsetlocale\fP(3),
 \fBwcrtomb\fP(3), \fBwprintf\fP(3), \fBlocale\fP(5)
 .SH この文書について
-この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.67 の一部
 である。プロジェクトの説明とバグ報告に関する情報は
 http://www.kernel.org/doc/man\-pages/ に書かれている。