OSDN Git Service

(split) LDP: Update drafts based on LDP 3.52 release
[linuxjm/LDP_man-pages.git] / draft / man3 / printf.3
index 05cf69c..6cd5346 100644 (file)
@@ -1,5 +1,12 @@
 .\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl)
 .\"
+.\" Earlier versions of this page influenced the present text.
+.\" It was derived from a Berkeley page with version
+.\"       @(#)printf.3    6.14 (Berkeley) 7/30/91
+.\" converted for Linux by faith@cs.unc.edu, updated by
+.\" Helmut.Geyer@iwr.uni-heidelberg.de, agulbra@troll.no and Bruno Haible.
+.\"
+.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
 .\" 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
 .\" GNU General Public License for more details.
 .\"
 .\" You should have received a copy of the GNU General Public
-.\" License along with this manual; if not, write to the Free
-.\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
-.\" USA.
-.\"
-.\"
-.\" Earlier versions of this page influenced the present text.
-.\" It was derived from a Berkeley page with version
-.\"       @(#)printf.3    6.14 (Berkeley) 7/30/91
-.\" converted for Linux by faith@cs.unc.edu, updated by
-.\" Helmut.Geyer@iwr.uni-heidelberg.de, agulbra@troll.no and Bruno Haible.
+.\" License along with this manual; if not, see
+.\" <http://www.gnu.org/licenses/>.
+.\" %%%LICENSE_END
 .\"
 .\" 1999-11-25 aeb - Rewritten, using SUSv2 and C99.
 .\" 2000-07-26 jsm28@hermes.cam.ac.uk - three small fixes
@@ -36,7 +36,7 @@
 .\" This file was generated with po4a. Translate the source file.
 .\"
 .\"*******************************************************************
-.TH PRINTF 3 2011\-09\-28 GNU "Linux Programmer's Manual"
+.TH PRINTF 3 2013\-03\-05 GNU "Linux Programmer's Manual"
 .SH 名前
 printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf \-
 指定された書式に変換して出力を行う
@@ -261,11 +261,12 @@ SUSv2 で長さ修飾子として使用できるのは、 \fBh\fP (\fBhd\fP, \fB
 精度指定があれば、精度で指定した桁数は必ず出力される。変換後の値が 指定された桁数に足りない場合は、左側が 0 で埋められる。
 .TP 
 \fBe\fP, \fBE\fP
-\fIdouble\fP 引き数を丸めて
-.if  \w'\*(Pm'=0 .ds Pm \(+-
-[\-]d\fB\&.\fPddd\fBe\fP\*(Pmdd の形に変換する。 小数点の前には一桁の数字があり、小数点以下の桁数は精度で指定された
-桁数になる。精度は指定されなかった場合 6 とみなされる。 精度が 0 の場合には、小数点以下は表示されない。 \fBE\fP 変換では、指数を表現するときに
-(\fBe\fP ではなく)  \fBE\fP が使われる。 指数部分は少なくとも 2桁表示される。 つまり、指数の値が 0 の場合には、00 と表示される。
+\fIdouble\fP 引き数を丸めて [\-]d\fB\&.\fPddd\fBe\fP\(+-dd の形に変換する。
+小数点の前には一桁の数字があり、小数点以下の桁数は精度で指定された桁数
+になる。精度は指定されなかった場合 6 とみなされる。 精度が 0 の場合には、
+小数点以下は表示されない。\fBE\fP 変換では、指数を表現するときに (\fBe\fP で
+はなく) \fBE\fP が使われる。指数部分は少なくとも 2桁表示される。つまり、
+指数の値が 0 の場合には、00 と表示される。
 .TP 
 \fBf\fP, \fBF\fP
 \fIdouble\fP 引き数を丸めて [\-]ddd\fB\&.\fPddd の形の10進表現に変換する。 小数点の後の桁数は、精度で指定された値となる。
@@ -285,12 +286,16 @@ NaN は文字列の先頭に `nan' をつけて表示するように規定され
 小数点以下に数字が少なくとも一つある場合にだけである。
 .TP 
 \fBa\fP, \fBA\fP
-(C99 にはあるが SUSv2 にはない)  \fBa\fP 変換では、 \fIdouble\fP 引き数を (abcdef の文字を使って)
-[\-]\fB0x\fPh\fB\&.\fPhhhh\fBp\fP\*(Pmd; 形式の 16 進表記に変換する。 \fBA\fP 変換では、前置文字列 \fB0X\fP, 文字
-ABCDEF, 指数文字 \fBP\fP を用いる。 小数点の前には 1桁の16進数が置かれ、小数点の後ろの桁数は 精度で指定された値となる。
-デフォルトの精度は、その値が 2進数で正確に表現できる場合には、 その値を正確に表現できる桁数となる。それ以外の場合は、 \fIdouble\fP
-型の値を区別するのに十分な大きさとなる。 小数点の前の数字は、正規化されていない数の場合はいくつになるか分からない。 正規化された数の場合は、 0
-以外の値になるが、いくつになるかは分からない。
+(C99 にはあるが SUSv2 にはない) \fBa\fP 変換では、 \fIdouble\fP 引き数を
+(abcdef の文字を使って) [\-]\fB0x\fPh\fB\&.\fPhhhh\fBp\fP\(+- 形式の
+16 進表記に変換する。
+\fBA\fP 変換では、前置文字列 \fB0X\fP, 文字 ABCDEF, 指数文字 \fBP\fP を用いる。
+小数点の前には 1 桁の 16 進数が置かれ、小数点の後ろの桁数は 精度で指定
+された値となる。デフォルトの精度は、その値が 2 進数で正確に表現できる
+場合には、その値を正確に表現できる桁数となる。それ以外の場合は、
+\fIdouble\fP 型の値を区別するのに十分な大きさとなる。 小数点の前の数字は、
+正規化されていない数の場合はいくつになるか分からない。 正規化された数の
+場合は、 0 以外の値になるが、いくつになるかは分からない。
 .TP 
 \fBc\fP
 \fBl\fP 修飾子がなければ、 \fIint\fP 引き数を \fIunsigned char\fP に変換して、その結果に対応する文字を出力する。 \fBl\fP
@@ -298,20 +303,27 @@ ABCDEF, 指数文字 \fBP\fP を用いる。 小数点の前には 1桁の16進
 関数を初期シフト状態で呼び出してマルチバイト文字列に変換し、 変換されたマルチバイト文字列を出力する。
 .TP 
 \fBs\fP
-\fBl\fP 修飾子がない場合、 引き数は \fIconst char *\fP 型で文字型の配列へのポインタ (文字列へのポインタ) であることが
-期待されている。配列中の文字は、終端の NULL バイト (\(aq\e0\(aq)  が出てくるまで出力される (終端文字は出力されない)。
-精度が指定されていると、指定された字数以上は出力されない。 精度が指定された場合には、終端バイトが存在する必要はない。
-精度が指定されていなかったり、精度の値が配列の大きさより大きい場合には、 配列は終端の NULL バイトを含んでいなければならない。
-
-\fBl\fP 修飾子が指定されている場合、 引き数は \fIconst wchar_t *\fP 型でワイド文字の配列へのポインタであることが期待されている。
-配列中のワイド文字は (1文字毎に \fBwcrtomb\fP(3)  を呼び出して) マルチバイト文字に変換される (最初のワイド文字の変換の前に
-\fBwcrtomb\fP()  のシフト状態を初期状態に戻してから変換は行われる)。 マルチバイト文字への変換は、文字列を終端する NULL ワイド文字が
-出てくるまで行われ、終端 NULL ワイド文字も含めて変換される。 結果のマルチバイト文字列は、終端の NULL バイトが出てくるまで 出力される
-(終端の NULL バイトは出力されない)。 精度が指定された場合、指定されたバイト数以上には出力されない。
-但し、マルチバイト文字の一部分だけが出力されることはない。 精度は「バイト」数を指定するものであり、「ワイド文字」数や
-「画面での位置」を指定するものではないことに注意。 精度が指定されていて、さらに出力が配列の末尾に達する前に出力バイト数が
-精度の値を超える場合だけは、配列は NULL ワイド文字で終端されていなくてもよい。 それ以外の場合は、必ず配列は NULL
-ワイド文字で終端されていなければならない。
+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.
 .TP 
 \fBC\fP
 (C99 にはないが SUSv2 にはある)  \fBlc\fP と同じ。使ってはならない。
@@ -320,10 +332,12 @@ ABCDEF, 指数文字 \fBP\fP を用いる。 小数点の前には 1桁の16進
 (C99 にはないが SUSv2 にはある)  \fBls\fP と同じ。使ってはならない。
 .TP 
 \fBp\fP
-\fIvoid *\fP ポインタ引き数を (\fB%#x\fP や \fB%#lx\fP のような) 16 進数で出力する。
+The \fIvoid\ *\fP pointer argument is printed in hexadecimal (as if by \fB%#x\fP
+or \fB%#lx\fP).
 .TP 
 \fBn\fP
-これまでに出力された文字数を \fIint *\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.
 .TP 
 \fBm\fP
 (glibc での拡張)  \fIstrerror(errno)\fP の出力を表示する。引き数は必要ない。
@@ -417,8 +431,7 @@ Linux libc4.[45] には \fBsnprintf\fP()  はないが、 libbsd が提供され
 文字が含まれてるかもしれないからである。 \fIfoo\fP が信頼できないユーザー入力から作られている場合には、 その中に \fB%n\fP
 が含まれていることがあり、 \fBprintf\fP()  呼び出し時にメモリへの書き込みが起こり、 セキュリティーホールを作ることになるかもしれない。
 .SH 例
-.if  \w'\*(Pi'=0 .ds Pi pi
-\*(Pi を 5 桁で出力する。
+\fIPi\fP を 5 桁で出力する。
 .in +4n
 .nf
 
@@ -460,6 +473,8 @@ fprintf(stdout, format,
 であれば、 "Sonntag, 3. Juli, 10:02" という結果になる。
 .PP
 十分に大きな文字列領域を確保して、そこにメッセージを格納するには (glibc 2.0 と glibc 2.1 の両方で正しく動作するコード):
+.PP
+バージョン 2.0.6 より前の glibc で切り詰めが起こった場合、切り詰めは適切に処理されず、エラーとして扱われる。
 .nf
 
 #include <stdio.h>
@@ -470,7 +485,7 @@ char *
 make_message(const char *fmt, ...)
 {
     int n;
-    int size = 100;     /* Guess we need no more than 100 bytes. */
+    int size = 100;     /* Guess we need no more than 100 bytes */
     char *p, *np;
     va_list ap;
 
@@ -479,23 +494,26 @@ make_message(const char *fmt, ...)
 
     while (1) {
 
-        /* Try to print in the allocated space. */
+        /* Try to print in the allocated space */
 
         va_start(ap, fmt);
         n = vsnprintf(p, size, fmt, ap);
         va_end(ap);
 
-        /* If that worked, return the string. */
+        /* Check error code */
 
-        if (n > \-1 && n < size)
+        if (n < 0)
+            return NULL;
+
+        /* If that worked, return the string */
+
+        if (n < size)
             return p;
 
-        /* Else try again with more space. */
+        /* Else try again with more space */
+
+        size = n + 1;       /* Precisely what is needed */
 
-        if (n > \-1)    /* glibc 2.1 */
-            size = n+1; /* precisely what is needed */
-        else           /* glibc 2.0 */
-            size *= 2;  /* twice the old size */
 
         if ((np = realloc (p, size)) == NULL) {
             free(p);
@@ -509,3 +527,7 @@ make_message(const char *fmt, ...)
 .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 の一部
+である。プロジェクトの説明とバグ報告に関する情報は
+http://www.kernel.org/doc/man\-pages/ に書かれている。