OSDN Git Service

f6b91b6857adc5e68b7a52b18a1be25c6dbcd9e6
[linuxjm/LDP_man-pages.git] / draft / man3 / printf.3
1 .\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" This is free documentation; you can redistribute it and/or
4 .\" modify it under the terms of the GNU General Public License as
5 .\" published by the Free Software Foundation; either version 2 of
6 .\" the License, or (at your option) any later version.
7 .\"
8 .\" The GNU General Public License's references to "object code"
9 .\" and "executables" are to be interpreted as the output of any
10 .\" document formatting or typesetting system, including
11 .\" intermediate and printed output.
12 .\"
13 .\" This manual is distributed in the hope that it will be useful,
14 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
15 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 .\" GNU General Public License for more details.
17 .\"
18 .\" You should have received a copy of the GNU General Public
19 .\" License along with this manual; if not, write to the Free
20 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
21 .\" USA.
22 .\"
23 .\"
24 .\" Earlier versions of this page influenced the present text.
25 .\" It was derived from a Berkeley page with version
26 .\"       @(#)printf.3    6.14 (Berkeley) 7/30/91
27 .\" converted for Linux by faith@cs.unc.edu, updated by
28 .\" Helmut.Geyer@iwr.uni-heidelberg.de, agulbra@troll.no and Bruno Haible.
29 .\"
30 .\" 1999-11-25 aeb - Rewritten, using SUSv2 and C99.
31 .\" 2000-07-26 jsm28@hermes.cam.ac.uk - three small fixes
32 .\" 2000-10-16 jsm28@hermes.cam.ac.uk - more fixes
33 .\"
34 .\" Japanese Version Copyright (c) 1997 YOSHINO Takashi all rights reserved.
35 .\" Translated 1998-02-17, YOSHINO Takashi <yoshino@civil.jcn.nihon-u.ac.jp>
36 .\" Updated 2000-10-02, Kentaro Shirakata <argrath@ub32.org>
37 .\" Updated 2001-01-29, Kentaro Shirakata <argrath@ub32.org>
38 .\" Updated 2002-01-03, Kentaro Shirakata <argrath@ub32.org>
39 .\" Updated 2002-10-17, Kentaro Shirakata <argrath@ub32.org>
40 .\" Updated 2005-03-15, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
41 .\" Updated 2006-07-20, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
42 .\" Updated 2008-02-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.77
43 .\" Updated 2009-03-03, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.19
44 .\"
45 .\" WORD: conversion specifier  変換指定子
46 .\" WORD: length modifier       長さ修飾子
47 .\"
48 .TH PRINTF 3  2011-09-28 "GNU" "Linux Programmer's Manual"
49 .\"O .SH NAME
50 .SH 名前
51 .\"O printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf,
52 .\"O vsnprintf \- formatted output conversion
53 printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf,
54 vsnprintf \- 指定された書式に変換して出力を行う
55 .\"O .SH SYNOPSIS
56 .SH 書式
57 .B #include <stdio.h>
58 .sp
59 .BI "int printf(const char *" format ", ...);"
60 .br
61 .BI "int fprintf(FILE *" stream ", const char *" format ", ...);"
62 .br
63 .BI "int sprintf(char *" str ", const char *" format ", ...);"
64 .br
65 .BI "int snprintf(char *" str ", size_t " size ", const char *" format ", ...);"
66 .sp
67 .B #include <stdarg.h>
68 .sp
69 .BI "int vprintf(const char *" format ", va_list " ap );
70 .br
71 .BI "int vfprintf(FILE *" stream ", const char *" format ", va_list " ap );
72 .br
73 .BI "int vsprintf(char *" str ", const char *" format ", va_list " ap );
74 .br
75 .BI "int vsnprintf(char *" str ", size_t " size ", const char *" format \
76 ", va_list " ap );
77 .sp
78 .in -4n
79 .\"O Feature Test Macro Requirements for glibc (see
80 .\"O .BR feature_test_macros (7)):
81 glibc 向けの機能検査マクロの要件
82 .RB ( feature_test_macros (7)
83 参照):
84 .in
85 .sp
86 .ad l
87 .BR snprintf (),
88 .BR vsnprintf ():
89 .RS 4
90 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _ISOC99_SOURCE ||
91 _POSIX_C_SOURCE\ >=\ 200112L;
92 .br
93 or
94 .I "cc -std=c99"
95 .RE
96 .ad
97 .\"O .SH DESCRIPTION
98 .SH 説明
99 .\"O The functions in the
100 .\"O .BR printf ()
101 .\"O family produce output according to a
102 .\"O .I format
103 .\"O as described below.
104 .BR printf ()
105 関数グループは、以下で述べるように、
106 .I format
107 に従って出力を生成するものである。
108 .\"O The functions
109 .\"O .BR printf ()
110 .\"O and
111 .\"O .BR vprintf ()
112 .\"O write output to
113 .\"O .IR stdout ,
114 .\"O the standard output stream;
115 .\"O .BR fprintf ()
116 .\"O and
117 .\"O .BR vfprintf ()
118 .\"O write output to the given output
119 .\"O .IR stream ;
120 .\"O .BR sprintf (),
121 .\"O .BR snprintf (),
122 .\"O .BR vsprintf ()
123 .\"O and
124 .\"O .BR vsnprintf ()
125 .\"O write to the character string
126 .\"O .IR str .
127 .BR printf ()
128
129 .BR vprintf ()
130 は出力を
131 .I stdout
132 (標準出力ストリーム) に書き出す。
133 .BR fprintf ()
134
135 .BR vfprintf ()
136 は出力を指定された出力
137 .I stream
138 に書き出す。
139 .BR sprintf (),
140 .BR snprintf (),
141 .BR vsprintf (),
142 .BR vsnprintf ()
143 は出力を文字列
144 .IR str
145 に書き込む。
146 .PP
147 .\"O The functions
148 .\"O .BR snprintf ()
149 .\"O and
150 .\"O .BR vsnprintf ()
151 .\"O write at most
152 .\"O .I size
153 .\"O bytes (including the terminating null byte (\(aq\e0\(aq)) to
154 .\"O .IR str .
155 .BR snprintf ()
156
157 .BR vsnprintf ()
158 は最大で
159 .I size
160 バイトを
161 .I str
162 に書き込む
163 .RI ( size
164 には文字列を終端する NULL バイト (\(aq\e0\(aq) もを含まれる)。
165 .PP
166 .\"O The functions
167 .\"O .BR vprintf (),
168 .\"O .BR vfprintf (),
169 .\"O .BR vsprintf (),
170 .\"O .BR vsnprintf ()
171 .\"O are equivalent to the functions
172 .\"O .BR printf (),
173 .\"O .BR fprintf (),
174 .\"O .BR sprintf (),
175 .\"O .BR snprintf (),
176 .\"O respectively, except that they are called with a
177 .\"O .I va_list
178 .\"O instead of a variable number of arguments.
179 .\"O These functions do not call the
180 .\"O .I va_end
181 .\"O macro.
182 .\"O Because they invoke the
183 .\"O .I va_arg
184 .\"O macro, the value of
185 .\"O .I ap
186 .\"O is undefined after the call.
187 .\"O See
188 .\"O .BR stdarg (3).
189 .BR vprintf (),
190 .BR vfprintf (),
191 .BR vsprintf (),
192 .BR vsnprintf ()
193 の各関数はそれぞれ
194 .BR printf (),
195 .BR fprintf (),
196 .BR sprintf (),
197 .BR snprintf (),
198 の各関数と等価であり、可変数引き数の代わりに
199 .I va_list
200 を引き数として呼び出される点だけが異なる。
201 これらの関数では
202 .I va_end
203 マクロは呼び出されない。
204 これらの関数は
205 .I va_arg
206 を呼び出すので、呼び出し後の
207 .I ap
208 の値は未定義である。
209 .BR stdarg (3)
210 を参照のこと。
211 .PP
212 .\"O These eight functions write the output under the control of a
213 .\"O .I format
214 .\"O string that specifies how subsequent arguments (or arguments accessed via
215 .\"O the variable-length argument facilities of
216 .\"O .BR stdarg (3))
217 .\"O are converted for output.
218 これらの 8 つの関数は
219 .I format
220 文字列の制御に従って出力を書き出す。
221 .I format
222 文字列は、これに続く引き数 (または
223 .BR stdarg (3)
224 の可変長引き数機構を使ってアクセスできる引き数)
225 をどのように変換して出力するかを指定する。
226
227 .\"O C99 and POSIX.1-2001 specify that the results are undefined if a call to
228 .\"O .BR sprintf (),
229 .\"O .BR snprintf (),
230 .\"O .BR vsprintf (),
231 .\"O or
232 .\"O .BR vsnprintf ()
233 .\"O would cause copying to take place between objects that overlap
234 .\"O (e.g., if the target string array and one of the supplied input arguments
235 .\"O refer to the same buffer).
236 .\"O See NOTES.
237 C99 と POSIX.1-2001 では、
238 .BR sprintf (),
239 .BR snprintf (),
240 .BR vsprintf (),
241 .BR vsnprintf ()
242 の呼び出しで、範囲が重複するオブジェクト間でコピーが発生する場合の
243 結果は不定であると規定されている (例えば、出力先の文字列と入力された
244 引き数の一つが同じバッファを参照している場合などである)。
245 「注意」の節を参照。
246 .\"O .SS "Return value"
247 .SS 返り値
248 .\"O Upon successful return, these functions return the number of characters
249 .\"O printed (excluding the null byte used to end output to strings).
250 成功時には、上記の関数は書き込まれた文字数を返す
251 (文字列の最後を示すために使用する NULL バイトは数に含まれない)。
252
253 .\"O The functions
254 .\"O .BR snprintf ()
255 .\"O and
256 .\"O .BR vsnprintf ()
257 .\"O do not write more than
258 .\"O .I size
259 .\"O bytes (including the terminating null byte (\(aq\e0\(aq)).
260 .\"O If the output was truncated due to this limit then the return value
261 .\"O is the number of characters (excluding the terminating null byte)
262 .\"O which would have been written to the final string if enough space
263 .\"O had been available.
264 .\"O Thus, a return value of
265 .\"O .I size
266 .\"O or more means that the output was truncated.
267 .\"O (See also below under NOTES.)
268 .BR snprintf ()
269
270 .BR vsnprintf ()
271 は、
272 .I size
273 バイトを越える文字数を書き込まない
274 .RI ( size
275 には文字列を終端する NULL バイト (\(aq\e0\(aq) も含まれる)。
276 この制限によって出力が切り詰められた場合には、
277 もし十分なスペースがあれば書き込まれたであろう文字の個数
278 (文字列を終端する NULL バイトを除く) を返す。
279 従って、返り値が
280 .I size
281 以上だった場合、出力が切り詰められたことを意味する
282 (後述の注意も参照のこと)。
283
284 .\"O If an output error is encountered, a negative value is returned.
285 エラーが発生した場合は、負の数を返す。
286 .\"O .SS "Format of the format string"
287 .SS フォーマット文字列のフォーマット
288 .\"O The format string is a character string, beginning and ending
289 .\"O in its initial shift state, if any.
290 フォーマット文字列は文字の列で、
291 (もしあるなら) 初期シフト状態で始まり、初期シフト状態で終わる。
292 .\"O The format string is composed of zero or more directives: ordinary
293 .\"O characters (not
294 .\"O .BR % ),
295 .\"O which are copied unchanged to the output stream;
296 .\"O and conversion specifications, each of which results in fetching zero or
297 .\"O more subsequent arguments.
298 フォーマット用の文字列は 0 個以上の命令 (directives) によって構成される。
299 命令には、通常文字と変換指定 (conversion specifications) がある。
300 通常文字は
301 .B %
302 以外の文字で、出力ストリームにそのままコピーされる。
303 変換指定は、それぞれが 0 個以上の引き数を取る。
304 .\"O Each conversion specification is introduced by
305 .\"O the character
306 .\"O .BR % ,
307 .\"O and ends with a
308 .\"O .IR "conversion specifier" .
309 各変換指定は文字
310 .B %
311 で始まり、
312 .I "変換指定子 (conversion specifier)"
313 で終わる。
314 .\"O In between there may be (in this order) zero or more
315 .\"O .IR flags ,
316 .\"O an optional minimum
317 .\"O .IR "field width" ,
318 .\"O an optional
319 .\"O .I precision
320 .\"O and an optional
321 .\"O .IR "length modifier" .
322 .B %
323 と変換指定子の間には、0 個以上の
324 .I フラグ 、
325 最小
326 .I フィールド幅 、
327 .I 精度 、
328 .I 長さ修飾子
329 を (この順序で) 置くことができる。
330
331 .\"O The arguments must correspond properly (after type promotion) with the
332 .\"O conversion specifier.
333 .\"O By default, the arguments are used in the order
334 .\"O given, where each \(aq*\(aq and each conversion specifier asks for the next
335 .\"O argument (and it is an error if insufficiently many arguments are given).
336 引き数は (型の格上げの後は) 変換指定子が表す型と正確に対応しなければならない。
337 デフォルトでは、\(aq*\(aq や変換指定子が出てくる毎に次の引き数を要求され、
338 引き数は指定された順序で使用されていく
339 (指定された引き数の個数が不十分ならエラーとなる)。
340 .\"O One can also specify explicitly which argument is taken,
341 .\"O at each place where an argument is required, by writing "%m$" instead
342 .\"O of \(aq%\(aq and "*m$" instead of \(aq*\(aq,
343 .\"O where the decimal integer m denotes
344 .\"O the position in the argument list of the desired argument, indexed starting
345 .\"O from 1.
346 .\"O Thus,
347 .\"O .in +4n
348 .\"O .nf
349 .\"O
350 .\"O printf("%*d", width, num);
351 .\"O
352 .\"O .fi
353 .\"O .in
354 .\"O and
355 .\"O .in +4n
356 .\"O .nf
357 .\"O
358 .\"O printf("%2$*1$d", width, num);
359 .\"O
360 .\"O .fi
361 .\"O .in
362 また、引き数が必要な箇所で \(aq%\(aq の代わりに "%m$"、
363 \(aq*\(aqの代わりに "*m$" と書くことで、
364 明示的にどの引き数を使用するかを指定することもできる。
365 ここで 10進の整数 m は希望の引き数の引き数リストでの位置を示す
366 (最初の引き数の番号が 1 である)。
367 従って、以下の二つは等価である。
368 .in +4n
369 .nf
370
371 printf("%*d", width, num);
372
373 printf("%2$*1$d", width, num);
374
375 .fi
376 .in
377 は等価である。
378 .\"O are equivalent.
379 .\"O The second style allows repeated references to the
380 .\"O same argument.
381 .\"O The C99 standard does not include the style using \(aq$\(aq,
382 .\"O which comes from the Single UNIX Specification.
383 .\"O If the style using
384 .\"O \(aq$\(aq is used, it must be used throughout for all conversions taking an
385 .\"O argument and all width and precision arguments, but it may be mixed
386 .\"O with "%%" formats which do not consume an argument.
387 .\"O There may be no
388 .\"O gaps in the numbers of arguments specified using \(aq$\(aq; for example, if
389 .\"O arguments 1 and 3 are specified, argument 2 must also be specified
390 .\"O somewhere in the format string.
391 二番目の書き方では同じ引き数を繰り返し参照することができる。
392 C99 標準には、 Single UNIX Specification 由来の \(aq$\(aq を使った書き方は含まれていない。
393 \(aq$\(aq を使ったスタイルを使うと、引き数を取る変換及び幅と精度の引き数を
394 全てこのスタイルで指定しなければならないが、
395 引き数を消費しない "%%" フォーマットと混ざっているかもしれない。
396 \(aq$\(aq で指定される引き数の番号に空きがあってはならない。
397 例えば、もし引き数 1 と 3 が指定されると、引き数 2 もフォーマット文字列のどこかで
398 指定されなければならない。
399
400 .\"O For some numeric conversion a radix character ("decimal point") or
401 .\"O thousands' grouping character is used.
402 .\"O The actual character used
403 .\"O depends on the
404 .\"O .B LC_NUMERIC
405 .\"O part of the locale.
406 .\"O The POSIX locale
407 .\"O uses \(aq.\(aq as radix character, and does not have a grouping character.
408 数値変換には小数点や 1000 単位の区切り文字を使うものもある。
409 実際にどの文字を使うかはロケールの
410 .B LC_NUMERIC
411 による。
412 POSIX ロケールでは小数点に \(aq.\(aq を用い、
413 区切り文字は使わない。
414 .\"O Thus,
415 従って、
416 .in +4n
417 .nf
418
419 printf("%\(aq.2f", 1234567.89);
420
421 .fi
422 .in
423 .\"O results in "1234567.89" in the POSIX locale, in "1234567,89" in the
424 .\"O nl_NL locale, and in "1.234.567,89" in the da_DK locale.
425 は、 POSIX ロケールでは "1234567.89" 、 nl_NL ロケールでは "1234567,89"、
426 da_DK ロケールでは "1.234.567,89" となる。
427 .\"O .SS "The flag characters"
428 .SS フラグ文字
429 .\"O The character % is followed by zero or more of the following flags:
430 % 文字の後ろには 0 個以上のフラグ文字が続く。
431 .TP
432 .\"O .B #
433 .\"O The value should be converted to an "alternate form".
434 .B #
435 値は「別の形式」に変換される。
436 .\"O For
437 .\"O .B o
438 .\"O conversions, the first character of the output string is made zero
439 .\"O (by prefixing a 0 if it was not zero already).
440 .B o
441 変換の場合、(先頭文字が 0 になっていない場合に先頭に 0 を追加することで)
442 出力文字列の最初の文字を 0 にする。
443 .\"O For
444 .\"O .B x
445 .\"O and
446 .\"O .B X
447 .\"O conversions, a nonzero result has the string "0x" (or "0X" for
448 .\"O .B X
449 .\"O conversions) prepended to it.
450 .B x
451
452 .B X
453 変換の場合、数値が 0 でないときには文字列 "0x"
454 .RB ( X
455 変換の場合には "0X") が前に付与される。
456 .\"O For
457 .\"O .BR a ,
458 .\"O .BR A ,
459 .\"O .BR e ,
460 .\"O .BR E ,
461 .\"O .BR f ,
462 .\"O .BR F ,
463 .\"O .BR g ,
464 .\"O and
465 .\"O .B G
466 .\"O conversions, the result will always contain a decimal point, even if no
467 .\"O digits follow it (normally, a decimal point appears in the results of those
468 .\"O conversions only if a digit follows).
469 .\"O For
470 .BR a ,
471 .BR A ,
472 .BR e ,
473 .BR E ,
474 .BR f ,
475 .BR F ,
476 .BR g ,
477 .B G
478 変換では、 小数点に続く数字がなくても、
479 出力には常に小数点が含まれる
480 (通常は、小数点の後に数字が続く場合にのみ、
481 小数点が表示される)。
482 .\"O .B g
483 .\"O and
484 .\"O .B G
485 .\"O conversions, trailing zeros are not removed from the result as they would
486 .\"O otherwise be.
487 .B g
488
489 .B G
490 変換の場合、他の変換とは異なり、末尾のゼロが変換結果から削除されない。
491 .\"O For other conversions, the result is undefined.
492 その他の変換では、結果は未定義である。
493 .TP
494 .B \&0
495 .\"O The value should be zero padded.
496 .\"O For
497 .\"O .BR d ,
498 .\"O .BR i ,
499 .\"O .BR o ,
500 .\"O .BR u ,
501 .\"O .BR x ,
502 .\"O .BR X ,
503 .\"O .BR a ,
504 .\"O .BR A ,
505 .\"O .BR e ,
506 .\"O .BR E ,
507 .\"O .BR f ,
508 .\"O .BR F ,
509 .\"O .BR g ,
510 .\"O and
511 .\"O .B G
512 .\"O conversions, the converted value is padded on the left with zeros rather
513 .\"O than blanks.
514 値をゼロで埋める。
515 .BR d ,
516 .BR i ,
517 .BR o ,
518 .BR u ,
519 .BR x ,
520 .BR X ,
521 .BR a ,
522 .BR A ,
523 .BR e ,
524 .BR E ,
525 .BR f ,
526 .BR F ,
527 .BR g ,
528 .B G
529 変換では、変換した値の左側を空白文字の代わりにゼロで埋める。
530 .\"O If the
531 .\"O .B \&0
532 .\"O and
533 .\"O .B \-
534 .\"O flags both appear, the
535 .\"O .B \&0
536 .\"O flag is ignored.
537 .B \&0
538
539 .B \-
540 が両方とも指定された場合は、
541 .B \&0
542 フラグは無視される。
543 .\"O If a precision is given with a numeric conversion
544 .\"O .RB ( d ,
545 .\"O .BR i ,
546 .\"O .BR o ,
547 .\"O .BR u ,
548 .\"O .BR x ,
549 .\"O and
550 .\"O .BR X ),
551 .\"O the
552 .\"O .B \&0
553 .\"O flag is ignored.
554 精度が数値変換
555 .RB ( d ,
556 .BR i ,
557 .BR o ,
558 .BR u ,
559 .BR x ,
560 .BR X )
561 と同時に指定された場合には、
562 .B \&0
563 フラグは無視される。
564 .\"O For other conversions, the behavior is undefined.
565 その他の変換では、動作は未定義である。
566 .TP
567 .B \-
568 .\"O The converted value is to be left adjusted on the field boundary.
569 .\"O (The default is right justification.)
570 .\"O Except for
571 .\"O .B n
572 .\"O conversions, the converted value is padded on the right with blanks, rather
573 .\"O than on the left with blanks or zeros.
574 .\"O A
575 変換値をフィールド境界で左揃えにする
576 (デフォルトは右揃えである)。
577 .B n
578 変換以外では、変換された値は
579 左側ではなく右側を空白文字やゼロで埋められる。
580 .\"O .B \-
581 .\"O overrides a
582 .\"O .B \&0
583 .\"O if both are given.
584 .B \-
585
586 .B \&0
587 の両方が指定された場合には、
588 .B \-
589 が優先される。
590 .TP
591 .\"O .B \(aq \(aq
592 .B ' '
593 .\"O (a space) A blank should be left before a positive number
594 .\"O (or empty string) produced by a signed conversion.
595 (1個の半角スペース)
596 符号付き変換で生成された正の数字の前に空白 (または空文字列) が置かれる。
597 .TP
598 .\"O .B +
599 .\"O A sign (+ or \-) should always be placed before a number produced by a signed
600 .\"O conversion.
601 .\"O By default a sign is used only for negative numbers.
602 .\"O A
603 .\"O .B +
604 .\"O overrides a space if both are used.
605 .B +
606 符号付き変換によって出力される数字の前に、常に符号 (+ か \-) が置かれる。
607 デフォルトでは、符号は負の数字の場合のみ付与される。
608 .B +
609 と半角スペースの
610 両方が使われている場合には、
611 .B +
612 が優先される。
613 .PP
614 .\"O The five flag characters above are defined in the C standard.
615 .\"O The SUSv2 specifies one further flag character.
616 上記の 5 つのフラグは C 標準で定義されている。
617 SUSv2 では、さらにもう一つフラグ文字が規定されている。
618 .TP
619 .B \(aq
620 .\"O For decimal conversion
621 .\"O .RB ( i ,
622 .\"O .BR d ,
623 .\"O .BR u ,
624 .\"O .BR f ,
625 .\"O .BR F ,
626 .\"O .BR g ,
627 .\"O .BR G )
628 .\"O the output is to be grouped with thousands' grouping characters
629 .\"O if the locale information indicates any.
630 .\"O Note that many versions of
631 .\"O .BR gcc (1)
632 .\"O cannot parse this option and will issue a warning.
633 .\"O SUSv2 does not
634 .\"O include %\(aqF.
635 10進数変換
636 .RB ( i ,
637 .BR d ,
638 .BR u ,
639 .BR f ,
640 .BR F ,
641 .BR g ,
642 .BR G )
643 において、ロケール情報に指定があれば 1000 単位の区切り文字を出力する。
644 .BR gcc (1)
645 の多くのバージョンは、このオプションを解釈することができず、
646 警告を出力することに注意せよ。
647 %\(aqF は SUSv2 には含まれていない。
648 .PP
649 .\"O glibc 2.2 adds one further flag character.
650 glibc 2.2 では、さらに一つフラグ文字が追加されている。
651 .TP
652 .B I
653 .\"O For decimal integer conversion
654 .\"O .RB ( i ,
655 .\"O .BR d ,
656 .\"O .BR u )
657 .\"O the output uses the locale's alternative output digits, if any.
658 .\"O For example, since glibc 2.2.3 this will give Arabic-Indic digits
659 .\"O in the Persian ("fa_IR") locale.
660 .\"O .\" outdigits keyword in locale file
661 10進整数変換
662 .RB ( i ,
663 .BR d ,
664 .BR u )
665 において、ロケールの代替出力数字があれば、それを用いて出力する。
666 例えば、 glibc 2.2.3 以降では、ペルシア ("fa_IR") ロケールで
667 アラビア数字 (Arabic-Indic digits) を出力できる。
668 .\" ロケールファイルには outdigits というキーワードがある。
669 .\"O .SS "The field width"
670 .SS フィールド幅
671 .\"O An optional decimal digit string (with nonzero first digit) specifying
672 .\"O a minimum field width.
673 .\"O If the converted value has fewer characters
674 .\"O than the field width, it will be padded with spaces on the left
675 .\"O (or right, if the left-adjustment flag has been given).
676 最小のフィールド幅を指定する 10進数の数値文字列 (文字列の最初の文字は
677 ゼロ以外)。本項目はオプションである。
678 変換された値の文字数がフィールド長よりも少ない場合、
679 フィールドの左側をスペースで埋める
680 (左揃えのフラグがある場合は右側を埋める)。
681 .\"O Instead of a decimal digit string one may write "*" or "*m$"
682 .\"O (for some decimal integer \fIm\fP) to specify that the field width
683 .\"O is given in the next argument, or in the \fIm\fP-th argument, respectively,
684 .\"O which must be of type
685 .\"O .IR int .
686 10進数の文字列の代わりに "*" や "*m$" (\fIm\fP は 10進整数) を書くこともできる。
687 "*" と "*m$" はそれぞれ、次の引き数と \fIm\fP 番目の引き数をフィールド幅として
688 使うことを指定する (これらの引き数は
689 .I int
690 型でなければならない)。
691 .\"O A negative field width is taken as a \(aq\-\(aq flag followed by a
692 .\"O positive field width.
693 フィールド幅に負の数が指定された場合は、
694 \(aq\-\(aq フラグと正の数のフィールド幅として扱われる。
695 .\"O In no case does a nonexistent or small field width cause truncation of a
696 .\"O field; if the result of a conversion is wider than the field width, the
697 .\"O field is expanded to contain the conversion result.
698 フィールド幅が小さかったり指定がなかったりしても、フィールドが切り詰められる
699 ことはない。もし変換結果がフィールド幅よりも広かった場合、
700 フィールドは変換結果が入る幅に広げられる。
701 .\"O .SS "The precision"
702 .SS 精度
703 .\"O An optional precision, in the form of a period (\(aq.\(aq)  followed by an
704 .\"O optional decimal digit string.
705 オプションである精度は、ピリオド (\(aq.\(aq) とそれに続く10進数という
706 形式で指定する (10進数はオプション) 。
707 .\"O Instead of a decimal digit string one may write "*" or "*m$"
708 .\"O (for some decimal integer m) to specify that the precision
709 .\"O is given in the next argument, or in the m-th argument, respectively,
710 .\"O which must be of type
711 .\"O .IR int .
712 10進数の文字列の代わりに "*" や "*m$" (m は 10 進整数)を書くこともできる。
713 "*" と "*m$" はそれぞれ、次の引き数と m 番目の引き数を精度として
714 使うことを指定する (これらの引き数は
715 .I int
716 型でなければならない)。
717 .\"O If the precision is given as just \(aq.\(aq, or the precision is negative,
718 .\"O the precision is taken to be zero.
719 精度として \(aq.\(aq だけが指定されたり、精度が負の数だった場合、
720 精度はゼロとみなされる。
721 .\"O This gives the minimum number of digits to appear for
722 .\"O .BR d ,
723 .\"O .BR i ,
724 .\"O .BR o ,
725 .\"O .BR u ,
726 .\"O .BR x ,
727 .\"O and
728 .\"O .B X
729 .\"O conversions, the number of digits to appear after the radix character for
730 .\"O .BR a ,
731 .\"O .BR A ,
732 .\"O .BR e ,
733 .\"O .BR E ,
734 .\"O .BR f ,
735 .\"O and
736 .\"O .B F
737 .\"O conversions, the maximum number of significant digits for
738 .\"O .B g
739 .\"O and
740 .\"O .B G
741 .\"O conversions, or the maximum number of characters to be printed from a
742 .\"O string for
743 .\"O .B s
744 .\"O and
745 .\"O .B S
746 .\"O conversions.
747 .BR d ,
748 .BR i ,
749 .BR o ,
750 .BR u ,
751 .BR x ,
752 .B X
753 変換では、表示される最小の桁数を指定する。
754 .BR a ,
755 .BR A ,
756 .BR e ,
757 .BR E ,
758 .BR f ,
759 .B F
760 変換では、小数点以下に表示される数字の桁数を指定する。
761 .B g
762
763 .B G
764 変換では、有効数字の最大桁数を指定する。
765 .B s
766
767 .B S
768 変換では、文字列から出力される最大文字数を指定する。
769 .\"O .SS "The length modifier"
770 .SS 長さ修飾子
771 .\"O Here, "integer conversion" stands for
772 .\"O .BR d ,
773 .\"O .BR i ,
774 .\"O .BR o ,
775 .\"O .BR u ,
776 .\"O .BR x ,
777 .\"O or
778 .\"O .B X
779 .\"O conversion.
780 「整数変換」とは、
781 .BR d ,
782 .BR i ,
783 .BR o ,
784 .BR u ,
785 .BR x ,
786 .B X
787 変換のことである。
788 .TP
789 .B hh
790 .\"O A following integer conversion corresponds to a
791 .\"O .I signed char
792 .\"O or
793 .\"O .I unsigned char
794 .\"O argument, or a following
795 .\"O .B n
796 .\"O conversion corresponds to a pointer to a
797 .\"O .I signed char
798 .\"O argument.
799 整数変換に対応する引き数が
800 .I signed char
801
802 .I unsigned char
803 で、
804 .B n
805 変換に対応する引き数が
806 .I signed char
807 へのポインタであることを示す。
808 .TP
809 .B h
810 .\"O A following integer conversion corresponds to a
811 .\"O .I short int
812 .\"O or
813 .\"O .I unsigned short int
814 .\"O argument, or a following
815 .\"O .B n
816 .\"O conversion corresponds to a pointer to a
817 .\"O .I short int
818 .\"O argument.
819 整数変換に対応する引き数が
820 .I short int
821
822 .I unsigned short int
823 で、
824 .B n
825 変換に対応する引き数が
826 .I short int
827 へのポインタであることを示す。
828 .TP
829 .\"O .B l
830 .\"O (ell) A following integer conversion corresponds to a
831 .\"O .I long int
832 .\"O or
833 .\"O .I unsigned long int
834 .\"O argument, or a following
835 .\"O .B n
836 .\"O conversion corresponds to a pointer to a
837 .\"O .I long long int
838 .\"O argument, or a following
839 .\"O .B c
840 .\"O conversion corresponds to a
841 .\"O .I wint_t
842 .\"O argument, or a following
843 .\"O .B s
844 .\"O conversion corresponds to a pointer to
845 .\"O .I wchar_t
846 .\"O argument.
847 .BR l " (エル)"
848 各変換に対応する引き数が、
849 整数変換では
850 .IR "long int" か
851 .IR "unsigned long int" 、
852 .B n
853 変換では
854 .I long long int
855 へのポインタ、
856 .B c
857 変換では
858 .IR wint_t 、
859 .B s
860 変換では
861 .I wchar_t
862 へのポインタであることを示す。
863
864 .TP
865 .\"O .B ll
866 .\"O (ell-ell).
867 .\"O A following integer conversion corresponds to a
868 .\"O .I long long int
869 .\"O or
870 .\"O .I unsigned long long int
871 .\"O argument, or a following
872 .\"O .B n
873 .\"O conversion corresponds to a pointer to a
874 .\"O .I long int
875 .\"O argument.
876 .BR ll " (エルエル)"
877 整数変換に対応する引き数が
878 .I long long int
879
880 .I unsigned long long int
881 で、
882 .B n
883 変換に対応する引き数が
884 .I long int
885 へのポインタであることを示す。
886 .TP
887 .B L
888 .\"O A following
889 .\"O .BR a ,
890 .\"O .BR A ,
891 .\"O .BR e ,
892 .\"O .BR E ,
893 .\"O .BR f ,
894 .\"O .BR F ,
895 .\"O .BR g ,
896 .\"O or
897 .\"O .B G
898 .\"O conversion corresponds to a
899 .\"O .I long double
900 .\"O argument.
901 .BR a ,
902 .BR A ,
903 .BR e ,
904 .BR E ,
905 .BR f ,
906 .BR F ,
907 .BR g ,
908 .B G
909 変換に対応する引き数が
910 .I long double
911 であることを示す。
912 .\"O (C99 allows %LF, but SUSv2 does not.)
913 (C99 では %LF を使うことを認めているが、SUSv2 では認められていない。)
914 .TP
915 .B q
916 .\"O ("quad". 4.4BSD and Linux libc5 only.
917 .\"O Don't use.)
918 .\"O This is a synonym for
919 .\"O .BR ll .
920 ("quad"。 4.4BSD と Linux libc5 のみ有効。使ってはならない。)
921 .B ll
922 と同じ意味である。
923 .TP
924 .B j
925 .\"O A following integer conversion corresponds to an
926 .\"O .I intmax_t
927 .\"O or
928 .\"O .I uintmax_t
929 .\"O argument.
930 整数変換に対応する引き数が
931 .I intmax_t
932
933 .I uintmax_t
934 であることを示す。
935 .TP
936 .B z
937 .\"O A following integer conversion corresponds to a
938 .\"O .I size_t
939 .\"O or
940 .\"O .I ssize_t
941 .\"O argument.
942 .\"O (Linux libc5 has
943 .\"O .B Z
944 .\"O with this meaning.
945 .\"O Don't use it.)
946 整数変換に対応する引き数が
947 .I size_t
948
949 .I ssize_t
950 であることを示す。
951 (Linux libc5 では、これを指定するのに
952 .B Z
953 を用いる。使ってはならない。)
954 .TP
955 .B t
956 .\"O A following integer conversion corresponds to a
957 .\"O .I ptrdiff_t
958 .\"O argument.
959 整数変換に対応する引き数が
960 .I ptrdiff_t
961 であることを示す。
962 .PP
963 .\"O The SUSv2 only knows about the length modifiers
964 .\"O .B h
965 .\"O (in
966 .\"O .BR hd ,
967 .\"O .BR hi ,
968 .\"O .BR ho ,
969 .\"O .BR hx ,
970 .\"O .BR hX ,
971 .\"O .BR hn )
972 .\"O and
973 .\"O .B l
974 .\"O (in
975 .\"O .BR ld ,
976 .\"O .BR li ,
977 .\"O .BR lo ,
978 .\"O .BR lx ,
979 .\"O .BR lX ,
980 .\"O .BR ln ,
981 .\"O .BR lc ,
982 .\"O .BR ls )
983 .\"O and
984 .\"O .B L
985 .\"O (in
986 .\"O .BR Le ,
987 .\"O .BR LE ,
988 .\"O .BR Lf ,
989 .\"O .BR Lg ,
990 .\"O .BR LG ).
991 SUSv2 で長さ修飾子として使用できるのは、
992 .B h
993 .RB ( hd ,
994 .BR hi ,
995 .BR ho ,
996 .BR hx ,
997 .BR hX ,
998 .BR hn ),
999 .B l
1000 .RB ( ld ,
1001 .BR li ,
1002 .BR lo ,
1003 .BR lx ,
1004 .BR lX ,
1005 .BR ln ,
1006 .BR lc ,
1007 .BR ls ),
1008 .B L
1009 .RB ( Le ,
1010 .BR LE ,
1011 .BR Lf ,
1012 .BR Lg ,
1013 .BR LG )
1014 だけである。
1015 .\"O .SS "The conversion specifier"
1016 .SS 変換指定子
1017 .\"O A character that specifies the type of conversion to be applied.
1018 適用される変換の型を指定する文字。
1019 .PP
1020 .\"O The conversion specifiers and their meanings are:
1021 変換指定子とその意味は以下の通りである。
1022 .TP
1023 .BR d ", " i
1024 .\"O The
1025 .\"O .I int
1026 .\"O argument is converted to signed decimal notation.
1027 .I int
1028 引き数を符号付き 10 進表記に変換する。
1029 .\"O The precision, if any, gives the minimum number of digits
1030 .\"O that must appear; if the converted value requires fewer digits, it is
1031 .\"O padded on the left with zeros.
1032 .\"O The default precision is 1.
1033 精度指定があれば、精度で指定した桁数は必ず出力される。変換後の値が
1034 指定された桁数に足りない場合は、左側が 0 で埋められる。
1035 デフォルトの精度は 1 である。
1036 .\"O When 0 is printed with an explicit precision 0, the output is empty.
1037 0 を表示しようとした時に、明示的に精度として 0 が指定されていると、
1038 出力は空文字列となる。
1039 .TP
1040 .BR o ", " u ", " x ", " X
1041 .\"O The
1042 .\"O .I "unsigned int"
1043 .\"O argument is converted to unsigned octal
1044 .\"O .RB ( o ),
1045 .\"O unsigned decimal
1046 .\"O .RB ( u ),
1047 .\"O or unsigned hexadecimal
1048 .\"O .RB ( x
1049 .\"O and
1050 .\"O .BR X )
1051 .\"O notation.
1052 .I "unsigned int"
1053 引き数を、
1054 符号なし8進数
1055 .RB ( o ),
1056 符号なし10進数
1057 .RB ( u ),
1058 符号なし16進数
1059 .RB ( x
1060
1061 .BR X )
1062 に変換する。
1063 .\"O The letters
1064 .\"O .B abcdef
1065 .\"O are used for
1066 .\"O .B x
1067 .\"O conversions; the letters
1068 .\"O .B ABCDEF
1069 .\"O are used for
1070 .\"O .B X
1071 .\"O conversions.
1072 .B x
1073 変換では
1074 .B abcdef
1075 が使用され、
1076 .B X
1077 変換では
1078 .B ABCDEF
1079 が使用される。
1080 .\"O The precision, if any, gives the minimum number of digits
1081 .\"O that must appear; if the converted value requires fewer digits, it is
1082 .\"O padded on the left with zeros.
1083 精度指定があれば、精度で指定した桁数は必ず出力される。変換後の値が
1084 指定された桁数に足りない場合は、左側が 0 で埋められる。
1085 .TP
1086 .BR e ", " E
1087 .\"O The
1088 .\"O .I double
1089 .\"O argument is rounded and converted in the style
1090 .\"O .if \w'\*(Pm'=0 .ds Pm \(+-
1091 .\"O .RB [\-]d \&. ddd e \\*(Pmdd
1092 .\"O where there is one digit before the decimal-point character and the number
1093 .\"O of digits after it is equal to the precision; if the precision is missing,
1094 .\"O it is taken as 6; if the precision is zero, no decimal-point character
1095 .\"O appears.
1096 .\"O An
1097 .I double
1098 引き数を丸めて
1099 .if \w'\*(Pm'=0 .ds Pm \(+-
1100 .RB [\-]d \&. ddd e \\*(Pmdd
1101 の形に変換する。
1102 小数点の前には一桁の数字があり、小数点以下の桁数は精度で指定された
1103 桁数になる。精度は指定されなかった場合 6 とみなされる。
1104 精度が 0 の場合には、小数点以下は表示されない。
1105 .\"O .B E
1106 .\"O conversion uses the letter
1107 .\"O .B E
1108 .\"O (rather than
1109 .\"O .BR e )
1110 .\"O to introduce the exponent.
1111 .B E
1112 変換では、指数を表現するときに
1113 .RB ( e
1114 ではなく)
1115 .B E
1116 が使われる。
1117 .\"O The exponent always contains at least two
1118 .\"O digits; if the value is zero, the exponent is 00.
1119 指数部分は少なくとも 2桁表示される。
1120 つまり、指数の値が 0 の場合には、00 と表示される。
1121 .TP
1122 .BR f ", " F
1123 .\"O The
1124 .\"O .I double
1125 .\"O argument is rounded and converted to decimal notation in the style
1126 .\"O .RB [\-]ddd \&. ddd,
1127 .\"O where the number of digits after the decimal-point character is equal to
1128 .\"O the precision specification.
1129 .I double
1130 引き数を丸めて
1131 .RB [\-]ddd \&. ddd
1132 の形の10進表現に変換する。
1133 小数点の後の桁数は、精度で指定された値となる。
1134 .\"O If the precision is missing, it is taken as
1135 .\"O 6; if the precision is explicitly zero, no decimal-point character appears.
1136 精度が指定されていない場合には 6 として扱われる。
1137 精度として明示的に 0 が指定されたときには、小数点以下は表示されない。
1138 .\"O If a decimal point appears, at least one digit appears before it.
1139 小数点を表示する際には、小数点の前に少なくとも一桁は数字が表示される。
1140
1141 .\"O (The SUSv2 does not know about
1142 .\"O .B F
1143 .\"O and says that character string representations for infinity and NaN
1144 .\"O may be made available.
1145 .\"O The C99 standard specifies "[\-]inf" or "[\-]infinity"
1146 .\"O for infinity, and a string starting with "nan" for NaN, in the case of
1147 .\"O .B f
1148 .\"O conversion, and "[\-]INF" or "[\-]INFINITY" or "NAN*" in the case of
1149 .\"O .B F
1150 .\"O conversion.)
1151 (SUSv2 では、
1152 .B F
1153 は規定されておらず、無限や NaN に関する文字列表現を
1154 行ってもよいことになっている。
1155  C99 標準では、
1156 .B f
1157 変換では、無限は "[\-]inf" か "[\-]infinity" と表示し、
1158 NaN は文字列の先頭に `nan' をつけて表示するように規定されている。
1159 .B F
1160 変換の場合は "[\-]INF", "[\-]INFINITY", "NAN*" と表示される。)
1161 .TP
1162 .BR g ", " G
1163 .\"O The
1164 .\"O .I double
1165 .\"O argument is converted in style
1166 .\"O .B f
1167 .\"O or
1168 .\"O .B e
1169 .\"O (or
1170 .\"O .B F
1171 .\"O or
1172 .\"O .B E
1173 .\"O for
1174 .\"O .B G
1175 .\"O conversions).
1176 .I double
1177 引き数を
1178 .B f
1179
1180 .B e
1181 .RB ( G
1182 変換の場合は
1183 .B F
1184
1185 .BR E )
1186 の形式に変換する。
1187 .\"O The precision specifies the number of significant digits.
1188 精度は表示する桁数を指定する。
1189 .\"O If the precision is missing, 6 digits are given; if the precision is zero,
1190 .\"O it is treated as 1.
1191 精度が指定されない場合は、6桁とみなされる。
1192 精度が 0 の場合は、1桁とみなされる。
1193 .\"O Style
1194 .\"O .B e
1195 .\"O is used if the exponent from its conversion is less than \-4 or greater
1196 .\"O than or equal to the precision.
1197 変換される値の指数が、 \-4 より小さいか、精度以上の場合に、
1198 .B e
1199 形式が使用される。
1200 .\"O Trailing zeros are removed from the
1201 .\"O fractional part of the result; a decimal point appears only if it is
1202 .\"O followed by at least one digit.
1203 変換された結果の小数部分の末尾の 0 は削除される。小数点が表示されるのは、
1204 小数点以下に数字が少なくとも一つある場合にだけである。
1205 .TP
1206 .BR a ", " A
1207 .\"O (C99; not in SUSv2) For
1208 .\"O .B a
1209 .\"O conversion, the
1210 .\"O .I double
1211 .\"O argument is converted to hexadecimal notation (using the letters abcdef)
1212 .\"O in the style
1213 .\"O .RB [\-] 0x h \&. hhhh p \\*(Pmd;
1214 .\"O for
1215 .\"O .B A
1216 .\"O conversion the prefix
1217 .\"O .BR 0X ,
1218 .\"O the letters ABCDEF, and the exponent separator
1219 .\"O .B P
1220 .\"O is used.
1221 (C99 にはあるが SUSv2 にはない)
1222 .B a
1223 変換では、
1224 .I double
1225 引き数を (abcdef の文字を使って)
1226 .RB [\-] 0x h \&. hhhh p \\*(Pmd;
1227 形式の 16 進表記に変換する。
1228 .B A
1229 変換では、前置文字列
1230 .BR 0X ,
1231 文字 ABCDEF, 指数文字
1232 .B P
1233 を用いる。
1234 .\"O There is one hexadecimal digit before the decimal point,
1235 .\"O and the number of digits after it is equal to the precision.
1236 小数点の前には 1桁の16進数が置かれ、小数点の後ろの桁数は
1237 精度で指定された値となる。
1238 .\"O The default precision suffices for an exact representation of the value
1239 .\"O if an exact representation in base 2 exists
1240 .\"O and otherwise is sufficiently large to distinguish values of type
1241 .\"O .IR double .
1242 デフォルトの精度は、その値が 2進数で正確に表現できる場合には、
1243 その値を正確に表現できる桁数となる。それ以外の場合は、
1244 .I double
1245 型の値を区別するのに十分な大きさとなる。
1246 .\"O The digit before the decimal point is unspecified for nonnormalized
1247 .\"O numbers, and nonzero but otherwise unspecified for normalized numbers.
1248 .\" motoki 2005/03/19: 合っているかな?
1249 小数点の前の数字は、正規化されていない数の場合はいくつになるか分からない。
1250 正規化された数の場合は、 0 以外の値になるが、いくつになるかは分からない。
1251 .TP
1252 .B c
1253 .\"O If no
1254 .\"O .B l
1255 .\"O modifier is present, the
1256 .\"O .I int
1257 .\"O argument is converted to an
1258 .\"O .IR "unsigned char" ,
1259 .\"O and the resulting character is written.
1260 .B l
1261 修飾子がなければ、
1262 .I int
1263 引き数を
1264 .IR "unsigned char"
1265 に変換して、その結果に対応する文字を出力する。
1266 .\"O If an
1267 .\"O .B l
1268 .\"O modifier is present, the
1269 .\"O .I wint_t
1270 .\"O (wide character) argument is converted to a multibyte sequence by a call
1271 .\"O to the
1272 .\"O .BR wcrtomb (3)
1273 .\"O function, with a conversion state starting in the initial state, and the
1274 .\"O resulting multibyte string is written.
1275 .B l
1276 修飾子があれば、
1277 .I wint_t
1278 (ワイド文字) 引き数を、
1279 .BR wcrtomb (3)
1280 関数を初期シフト状態で呼び出してマルチバイト文字列に変換し、
1281 変換されたマルチバイト文字列を出力する。
1282 .TP
1283 .B s
1284 .\"O If no
1285 .\"O .B l
1286 .\"O modifier is present: The
1287 .\"O .I "const char *"
1288 .\"O argument is expected to be a pointer to an array of character type (pointer
1289 .\"O to a string).
1290 .\"O Characters from the array are written up to (but not
1291 .\"O including) a terminating null byte (\(aq\\0\(aq);
1292 .\"O if a precision is specified, no more than the number specified
1293 .\"O are written.
1294 .\"O If a precision is given, no null byte need be present;
1295 .\"O if the precision is not specified, or is greater than the size of the
1296 .\"O array, the array must contain a terminating null byte.
1297 .B l
1298 修飾子がない場合、
1299 引き数は
1300 .I "const char *"
1301 型で文字型の配列へのポインタ (文字列へのポインタ) であることが
1302 期待されている。配列中の文字は、終端の NULL バイト (\(aq\\0\(aq)
1303 が出てくるまで出力される (終端文字は出力されない)。
1304 精度が指定されていると、指定された字数以上は出力されない。
1305 精度が指定された場合には、終端バイトが存在する必要はない。
1306 精度が指定されていなかったり、精度の値が配列の大きさより大きい場合には、
1307 配列は終端の NULL バイトを含んでいなければならない。
1308
1309 .\"O If an
1310 .\"O .B l
1311 .\"O modifier is present: The
1312 .\"O .I "const wchar_t *"
1313 .\"O argument is expected to be a pointer to an array of wide characters.
1314 .B l
1315 修飾子が指定されている場合、
1316 引き数は
1317 .I "const wchar_t *"
1318 型でワイド文字の配列へのポインタであることが期待されている。
1319 .\"O Wide characters from the array are converted to multibyte characters
1320 .\"O (each by a call to the
1321 .\"O .BR wcrtomb (3)
1322 .\"O function, with a conversion state starting in the initial state before
1323 .\"O the first wide character), up to and including a terminating null
1324 .\"O wide character.
1325 .\"O The resulting multibyte characters are written up to
1326 .\"O (but not including) the terminating null byte.
1327 .\"O If a precision is
1328 .\"O specified, no more bytes than the number specified are written, but
1329 .\"O no partial multibyte characters are written.
1330 .\"O Note that the precision
1331 .\"O determines the number of
1332 .\"O .I bytes
1333 .\"O written, not the number of
1334 .\"O .I wide characters
1335 .\"O or
1336 .\"O .IR "screen positions" .
1337 配列中のワイド文字は (1文字毎に
1338 .BR wcrtomb (3)
1339 を呼び出して) マルチバイト文字に変換される
1340 (最初のワイド文字の変換の前に
1341 .BR wcrtomb ()
1342 のシフト状態を初期状態に戻してから変換は行われる)。
1343 マルチバイト文字への変換は、文字列を終端する NULL ワイド文字が
1344 出てくるまで行われ、終端 NULL ワイド文字も含めて変換される。
1345 結果のマルチバイト文字列は、終端の NULL バイトが出てくるまで
1346 出力される (終端の NULL バイトは出力されない)。
1347 精度が指定された場合、指定されたバイト数以上には出力されない。
1348 但し、マルチバイト文字の一部分だけが出力されることはない。
1349 精度は「バイト」数を指定するものであり、「ワイド文字」数や
1350 「画面での位置」を指定するものではないことに注意。
1351 .\"O The array must contain a terminating null wide character, unless a
1352 .\"O precision is given and it is so small that the number of bytes written
1353 .\"O exceeds it before the end of the array is reached.
1354 精度が指定されていて、さらに出力が配列の末尾に達する前に出力バイト数が
1355 精度の値を超える場合だけは、配列は NULL ワイド文字で終端されていなくてもよい。
1356 それ以外の場合は、必ず配列は NULL ワイド文字で終端されていなければならない。
1357 .TP
1358 .B C
1359 .\"O (Not in C99, but in SUSv2.)
1360 .\"O Synonym for
1361 .\"O .BR lc .
1362 .\"O Don't use.
1363 (C99 にはないが SUSv2 にはある)
1364 .B lc
1365 と同じ。使ってはならない。
1366 .TP
1367 .B S
1368 .\"O (Not in C99, but in SUSv2.)
1369 .\"O Synonym for
1370 .\"O .BR ls .
1371 .\"O Don't use.
1372 (C99 にはないが SUSv2 にはある)
1373 .B ls
1374 と同じ。使ってはならない。
1375 .TP
1376 .B p
1377 .\"O The
1378 .\"O .I "void *"
1379 .\"O pointer argument is printed in hexadecimal (as if by
1380 .\"O .B %#x
1381 .\"O or
1382 .\"O .BR  %#lx ).
1383 .I "void *"
1384 ポインタ引き数を
1385 .RB ( %#x
1386
1387 .BR  %#lx
1388 のような) 16 進数で出力する。
1389 .TP
1390 .B n
1391 .\"O The number of characters written so far is stored into the integer
1392 .\"O indicated by the
1393 .\"O .I "int *"
1394 .\"O (or variant) pointer argument.
1395 .\"O No argument is converted.
1396 これまでに出力された文字数を
1397 .I "int *"
1398 (または類似の型) のポインタ引き数が指す整数に保存する。
1399 引き数の変換は行われない。
1400 .TP
1401 .B m
1402 .\"O (Glibc extension.)
1403 .\"O Print output of
1404 .\"O .IR strerror(errno) .
1405 .\"O No argument is required.
1406 (glibc での拡張)
1407 .I strerror(errno)
1408 の出力を表示する。引き数は必要ない。
1409 .TP
1410 .B %
1411 .\"O A \(aq%\(aq is written.
1412 .\"O No argument is converted.
1413 .\"O The complete conversion
1414 .\"O specification is \(aq%%\(aq.
1415 \(aq%\(aq 文字を出力する。変換される引き数は無い。
1416 変換指定全体を書くと "%%" となる。
1417 .\"O .SH "CONFORMING TO"
1418 .SH 準拠
1419 .\"O The
1420 .\"O .BR fprintf (),
1421 .\"O .BR printf (),
1422 .\"O .BR sprintf (),
1423 .\"O .BR vprintf (),
1424 .\"O .BR vfprintf (),
1425 .\"O and
1426 .\"O .BR vsprintf ()
1427 .\"O functions conform to C89 and C99.
1428 .BR fprintf (),
1429 .BR printf (),
1430 .BR sprintf (),
1431 .BR vprintf (),
1432 .BR vfprintf (),
1433 .BR vsprintf ()
1434 関数は、C89 と C99 に準拠している。
1435 .\"O The
1436 .\"O .BR snprintf ()
1437 .\"O and
1438 .\"O .BR vsnprintf ()
1439 .\"O functions conform to C99.
1440 .BR snprintf ()
1441
1442 .BR vsnprintf ()
1443 は C99 に準拠している。
1444 .PP
1445 .\"O Concerning the return value of
1446 .\"O .BR snprintf (),
1447 .\"O SUSv2 and C99 standard contradict each other: when
1448 .\"O .BR snprintf ()
1449 .\"O is called with
1450 .\"O .IR size =0
1451 .\"O then SUSv2 stipulates an unspecified return value less than 1,
1452 .\"O while C99 allows
1453 .\"O .I str
1454 .\"O to be NULL in this case, and gives the return value (as always)
1455 .\"O as the number of characters that would have been written in case
1456 .\"O the output string has been large enough.
1457 .BR snprintf ()
1458 の返り値を見ると、
1459 SUSv2 と C99 標準は互いに矛盾している。
1460 SUSv2 では、
1461 .BR snprintf ()
1462
1463 .IR size =0
1464 で呼び出された場合、 1 未満の値を何か返り値とするように規定している。
1465 一方 C99 では、このような場合
1466 .I str
1467 を NULL とし、返り値として (通常通り) 出力バッファが十分な大きさが
1468 あった場合に出力されるであろう文字数を返す。
1469 .PP
1470 .\"O Linux libc4 knows about the five C standard flags.
1471 .\"O It knows about the length modifiers \fBh\fP, \fBl\fP, \fBL\fP,
1472 .\"O and the conversions
1473 .\"O \fBc\fP, \fBd\fP, \fBe\fP, \fBE\fP, \fBf\fP, \fBF\fP,
1474 .\"O \fBg\fP, \fBG\fP, \fBi\fP, \fBn\fP, \fBo\fP, \fBp\fP,
1475 .\"O \fBs\fP, \fBu\fP, \fBx\fP, and \fBX\fP,
1476 .\"O where \fBF\fP is a synonym for \fBf\fP.
1477 Linux libc4 では、 5 つの C 標準のフラグ、
1478 長さ修飾子 \fBh\fP, \fBl\fP, \fBL\fP、変換
1479 \fBc\fP, \fBd\fP, \fBe\fP, \fBE\fP, \fBf\fP, \fBF\fP,
1480 \fBg\fP, \fBG\fP, \fBi\fP, \fBn\fP, \fBo\fP, \fBp\fP,
1481 \fBs\fP, \fBu\fP, \fBx\fP, \fBX\fP
1482 が使える。
1483 但し \fBF\fP は \fBf\fP と同義である。
1484 .\"O Additionally, it accepts \fBD\fP, \fBO\fP, and \fBU\fP as synonyms
1485 .\"O for \fBld\fP, \fBlo\fP, and \fBlu\fP.
1486 .\"O (This is bad, and caused serious bugs later, when
1487 .\"O support for \fB%D\fP disappeared.)
1488 .\"O No locale-dependent radix character,
1489 .\"O no thousands' separator, no NaN or infinity, no "%m$" and "*m$".
1490 また、 \fBD\fP, \fBO\fP, and \fBU\fP を \fBld\fP, \fBlo\fP, and \fBlu\fP
1491 と同じものとして使える
1492 (これはまずい仕様で、 後に \fB%D\fP の対応が打ち切られた時に深刻なバグを
1493 引き起こした)。ロケール依存の小数点、1000 区切り、 NaN と無限、
1494 "%m$" と "*m$" は使えない。
1495 .PP
1496 .\"O Linux libc5 knows about the five C standard flags and the \(aq flag,
1497 .\"O locale, "%m$" and "*m$".
1498 .\"O It knows about the length modifiers \fBh\fP, \fBl\fP, \fBL\fP,
1499 .\"O \fBZ\fP, and \fBq\fP, but accepts \fBL\fP and \fBq\fP
1500 .\"O both for \fIlong double\fP and for \fIlong long int\fP (this is a bug).
1501 Linux libc5 では、 5 つの C 標準のフラグと \(aq フラグ、ロケール、
1502 "%m$" と "*m$" が使える。
1503 また、長さ修飾子 \fBh\fP, \fBl\fP, \fBL\fP, \fBZ\fP, iand \fBq\fP が使えるが、
1504 \fBL\fP と \fBq\fP は両方とも
1505 \fIlong double\fP と \fIlong long int\fP に対応している (これはバグである)。
1506 .\"O It no longer recognizes \fBF\fP, \fBD\fP, \fBO\fP, and \fBU\fP,
1507 .\"O but adds the conversion character
1508 .\"O .BR m ,
1509 .\"O which outputs
1510 .\"O .IR strerror(errno) .
1511 現在では変換 \fBF\fP, \fBD\fP, \fBO\fP, \fBU\fP は認識されないが、変換文字
1512 .B m
1513 が追加された。これは
1514 .I strerror(errno)
1515 を出力するものである。
1516 .PP
1517 .\"O glibc 2.0 adds conversion characters \fBC\fP and \fBS\fP.
1518 glibc 2.0 では、変換文字 \fBC\fP と \fBS\fP が追加された。
1519 .PP
1520 .\"O glibc 2.1 adds length modifiers \fBhh\fP, \fBj\fP, \fBt\fP, and \fBz\fP
1521 .\"O and conversion characters \fBa\fP and \fBA\fP.
1522 glibc 2.1 では、長さ修飾子 \fBhh\fP, \fBj\fP, \fBt\fP, \fBz\fP
1523 と変換文字 \fBa\fP, \fBA\fP が追加された。
1524 .PP
1525 .\"O glibc 2.2 adds the conversion character \fBF\fP with C99 semantics,
1526 .\"O and the flag character \fBI\fP.
1527 glibc 2.2 では、 C99 で規定された意味での変換文字 \fBF\fP と
1528 フラグ文字 \fBI\fP が追加された。
1529 .\"O .SH NOTES
1530 .SH 注意
1531 .\"O Some programs imprudently rely on code such as the following
1532 .\"O 
1533 .\"O     sprintf(buf, "%s some further text", buf);
1534 .\"O 
1535 .\"O to append text to
1536 .\"O .IR buf .
1537 テキストを
1538 .I buf
1539 に追加するのに、軽率にも次のようなコードを使っているプログラムがある。
1540
1541     sprintf(buf, "%s some further text", buf);
1542
1543 .\"O However, the standards explicitly note that the results are undefined
1544 .\"O if source and destination buffers overlap when calling
1545 .\"O .BR sprintf (),
1546 .\"O .BR snprintf (),
1547 .\"O .BR vsprintf (),
1548 .\"O and
1549 .\"O .BR vsnprintf ().
1550 しかしながら、標準規格では、
1551 .BR sprintf (),
1552 .BR snprintf (),
1553 .BR vsprintf (),
1554 .BR vsnprintf ()
1555 の呼び出しにおいて、コピー元とコピー先のバッファが重なっていた場合の
1556 結果は不定である、と明記されている。
1557 .\" http://sourceware.org/bugzilla/show_bug.cgi?id=7075
1558 .\"O Depending on the version of
1559 .\"O .BR gcc (1)
1560 .\"O used, and the compiler options employed, calls such as the above will
1561 .\"O .B not
1562 .\"O produce the expected results.
1563 使用する
1564 .BR gcc (1)
1565 のバージョンや指定したコンパイラのオプション次第では、
1566 上記のような呼び出しで、期待した結果が得られ「ない」ことがある。
1567
1568 .\"O The glibc implementation of the functions
1569 .\"O .BR snprintf ()
1570 .\"O and
1571 .\"O .BR vsnprintf ()
1572 .\"O conforms to the C99 standard, that is, behaves as described above,
1573 .\"O since glibc version 2.1.
1574 .\"O Until glibc 2.0.6 they would return \-1
1575 .\"O when the output was truncated.
1576 glibc の
1577 .BR snprintf ()
1578
1579 .BR vsnprintf ()
1580 の実装は、バージョン 2.1 以降は C99 標準に準拠しており、
1581 上記の通りの動作をする。
1582 glibc 2.0.6 までは、出力が切り詰められた場合は \-1 を返す。
1583 .\"O .\" .SH HISTORY
1584 .\" .SH 歴史
1585 .\"O .\" UNIX V7 defines the three routines
1586 .\"O .\" .BR printf (),
1587 .\"O .\" .BR fprintf (),
1588 .\"O .\" .BR sprintf (),
1589 .\"O .\" and has the flag \-, the width or precision *, the length modifier l,
1590 .\"O .\" and the conversions doxfegcsu, and also D,O,U,X as synonyms for ld,lo,lu,lx.
1591 .\" UNIX V7 では
1592 .\" .BR printf (),
1593 .\" .BR fprintf (),
1594 .\" .BR sprintf ()
1595 .\" の 3 つの関数と、フラグ \-、幅と精度での *、長さ修飾子 l、
1596 .\" 変換 doxfegcsu、そして ld,ld,lu,lx の同義語として D,O,U,X が定義されている。
1597 .\"O .\" This is still true for 2.9.1BSD, but 2.10BSD has the flags
1598 .\"O .\" #, + and <space> and no longer mentions D,O,U,X.
1599 .\" 2.9.1BSD でもこれは同じだったが、 2.10BSD では
1600 .\" フラグ #, +, 空白が追加され、 D,O,U,X については記載されなくなった。
1601 .\"O .\" 2.11BSD has
1602 .\"O .\" .BR vprintf (),
1603 .\"O .\" .BR vfprintf (),
1604 .\"O .\" .BR vsprintf (),
1605 .\"O .\" and warns not to use D,O,U,X.
1606 .\" 2.11BSD では
1607 .\" .BR vprintf (),
1608 .\" .BR vfprintf (),
1609 .\" .BR vsprintf ()
1610 .\" が追加され、 D,O,U,X を使わないように警告された。
1611 .\"O .\" 4.3BSD Reno has the flag 0, the length modifiers h and L,
1612 .\"O .\" and the conversions n, p, E, G, X (with current meaning)
1613 .\"O .\" and deprecates D,O,U.
1614 .\" 4.3BSD Reno ではフラグ 0、長さ修飾子 h と L、
1615 .\" 変換 n, p, E, G, (現在の意味での) X が追加され、
1616 .\" D,O,U は非推奨扱いとなった。
1617 .\"O .\" 4.4BSD introduces the functions
1618 .\"O .\" .BR snprintf ()
1619 .\"O .\" and
1620 .\"O .\" .BR vsnprintf (),
1621 .\"O .\" and the length modifier q.
1622 .\" 4.4BSD では、関数
1623 .\" .BR snprintf ()と
1624 .\" .BR vsnprintf ()、
1625 .\" 長さ修飾子 q が導入された。
1626 .\"O .\" FreeBSD also has functions
1627 .\"O .\" .BR asprintf ()
1628 .\"O .\" and
1629 .\"O .\" .BR vasprintf (),
1630 .\"O .\" that allocate a buffer large enough for
1631 .\"O .\" .BR sprintf ().
1632 .\" FreeBSD では、
1633 .\" .BR sprintf ()
1634 .\" のために十分なバッファを確保する
1635 .\" .BR asprintf ()
1636 .\" と
1637 .\" .BR vasprintf ()
1638 .\" が追加されている。
1639 .\"O .\" In glibc there are functions
1640 .\"O .\" .BR dprintf ()
1641 .\"O .\" and
1642 .\"O .\" .BR vdprintf ()
1643 .\"O .\" that print to a file descriptor instead of a stream.
1644 .\" glibc には、関数
1645 .\" .BR dprintf (),
1646 .\" .BR vdprintf ()
1647 .\" があり、これらはストリームではなくファイルディスクリプタに出力する。
1648 .\"O .SH BUGS
1649 .SH バグ
1650 .\"O Because
1651 .\"O .BR sprintf ()
1652 .\"O and
1653 .\"O .BR vsprintf ()
1654 .\"O assume an arbitrarily long string, callers must be careful not to overflow
1655 .\"O the actual space; this is often impossible to assure.
1656 .\"O Note that the length
1657 .\"O of the strings produced is locale-dependent and difficult to predict.
1658 .BR sprintf ()
1659
1660 .BR vsprintf ()
1661 は勝手に十分に長い文字列領域があると仮定するので、呼び出し側は
1662 実際の領域からあふれないように注意しなければならない。
1663 しかし、これを保証することが不可能な場合が多い。
1664 生成される文字列の長さはロケール依存であり、予測が難しいことに注意。
1665 .\"O Use
1666 .\"O .BR snprintf ()
1667 .\"O and
1668 .\"O .BR vsnprintf ()
1669 .\"O instead (or
1670 .\"O .BR asprintf (3)
1671 .\"O and
1672 .\"O .BR vasprintf (3)).
1673 代わりに
1674 .BR snprintf ()
1675
1676 .BR vsnprintf ()
1677 (または
1678 .BR asprintf (3)
1679
1680 .BR vasprintf (3))
1681 を使うこと。
1682 .PP
1683 .\"O Linux libc4.[45] does not have a
1684 .\"O .BR snprintf (),
1685 .\"O but provides a libbsd that contains an
1686 .\"O .BR snprintf ()
1687 .\"O equivalent to
1688 .\"O .BR sprintf (),
1689 .\"O that is, one that ignores the
1690 .\"O .I size
1691 .\"O argument.
1692 Linux libc4.[45] には
1693 .BR snprintf ()
1694 はないが、 libbsd が提供されており、
1695 その中には
1696 .BR sprintf ()
1697 と等価な (つまり
1698 .I size
1699 引き数を無視する)
1700 .BR snprintf ()
1701 がある。
1702 .\"O Thus, the use of
1703 .\"O .BR snprintf ()
1704 .\"O with early libc4 leads to serious security problems.
1705 したがって、初期の libc4 で
1706 .BR snprintf ()
1707 を使うと、深刻なセキュリティ問題を引き起こすことがある。
1708 .PP
1709 .\"O Code such as
1710 .\"O .BI printf( foo );
1711 .\"O often indicates a bug, since
1712 .\"O .I foo
1713 .\"O may contain a % character.
1714 .\"O If
1715 .\"O .I foo
1716 .\"O comes from untrusted user input, it may contain \fB%n\fP, causing the
1717 .\"O .BR printf ()
1718 .\"O call to write to memory and creating a security hole.
1719 .BI printf( foo );
1720 のようなコードはしばしばバグを引き起こす。
1721 なぜなら
1722 .I foo
1723 に % 文字が含まれてるかもしれないからである。
1724 .I foo
1725 が信頼できないユーザー入力から作られている場合には、
1726 その中に \fB%n\fP が含まれていることがあり、
1727 .BR printf ()
1728 呼び出し時にメモリへの書き込みが起こり、
1729 セキュリティーホールを作ることになるかもしれない。
1730 .\".PP
1731 .\".\"O Some floating-point conversions under early libc4
1732 .\".\"O caused memory leaks.
1733 .\"初期の libc4 での実数変換にはメモリリークを引き起こすことがある。
1734 .\"O .SH EXAMPLE
1735 .SH 例
1736 .if \w'\*(Pi'=0 .ds Pi pi
1737 .\"O To print \*(Pi to five decimal places:
1738 \*(Pi を 5 桁で出力する。
1739 .in +4n
1740 .nf
1741
1742 #include <math.h>
1743 #include <stdio.h>
1744 fprintf(stdout, "pi = %.5f\en", 4 * atan(1.0));
1745 .fi
1746 .in
1747 .PP
1748 .\"O To print a date and time in the form "Sunday, July 3, 10:02",
1749 .\"O where
1750 .\"O .I weekday
1751 .\"O and
1752 .\"O .I month
1753 .\"O are pointers to strings:
1754 日付と時間を "Sunday, July 3, 10:02" の形式で出力する。
1755 .RI ( weekday
1756
1757 .I month
1758 は文字列へのポインタである)
1759 .in +4n
1760 .nf
1761
1762 #include <stdio.h>
1763 fprintf(stdout, "%s, %s %d, %.2d:%.2d\en",
1764         weekday, month, day, hour, min);
1765 .fi
1766 .in
1767 .PP
1768 .\"O Many countries use the day-month-year order.
1769 .\"O Hence, an internationalized version must be able to print
1770 .\"O the arguments in an order specified by the format:
1771 日 - 月 - 年 の順序で表示を行う国も多い。
1772 従って、国際版では書式で指定された順番で
1773 引き数を表示できなければならない。
1774 .in +4n
1775 .nf
1776
1777 #include <stdio.h>
1778 fprintf(stdout, format,
1779         weekday, month, day, hour, min);
1780
1781 .fi
1782 .in
1783 .\"O where
1784 .\"O .I format
1785 .\"O depends on locale, and may permute the arguments.
1786 .\"O With the value:
1787 .I format
1788 はロケールに依存しており、引き数の順番を変えることもできる。
1789 .I format
1790
1791 .in +4n
1792 .nf
1793
1794 "%1$s, %3$d. %2$s, %4$d:%5$.2d\en"
1795
1796 .fi
1797 .in
1798 .\"O one might obtain "Sonntag, 3. Juli, 10:02".
1799 であれば、 "Sonntag, 3. Juli, 10:02" という結果になる。
1800 .PP
1801 .\"O To allocate a sufficiently large string and print into it
1802 .\"O (code correct for both glibc 2.0 and glibc 2.1):
1803 十分に大きな文字列領域を確保して、そこにメッセージを格納するには
1804 (glibc 2.0 と glibc 2.1 の両方で正しく動作するコード):
1805 .nf
1806
1807 #include <stdio.h>
1808 #include <stdlib.h>
1809 #include <stdarg.h>
1810 char *
1811 make_message(const char *fmt, ...)
1812 {
1813     int n;
1814     int size = 100;     /* Guess we need no more than 100 bytes. */
1815     char *p, *np;
1816     va_list ap;
1817
1818     if ((p = malloc(size)) == NULL)
1819         return NULL;
1820
1821     while (1) {
1822
1823         /* Try to print in the allocated space. */
1824
1825         va_start(ap, fmt);
1826         n = vsnprintf(p, size, fmt, ap);
1827         va_end(ap);
1828
1829         /* If that worked, return the string. */
1830
1831         if (n > \-1 && n < size)
1832             return p;
1833
1834         /* Else try again with more space. */
1835
1836         if (n > \-1)    /* glibc 2.1 */
1837             size = n+1; /* precisely what is needed */
1838         else           /* glibc 2.0 */
1839             size *= 2;  /* twice the old size */
1840
1841         if ((np = realloc (p, size)) == NULL) {
1842             free(p);
1843             return NULL;
1844         } else {
1845             p = np;
1846         }
1847     }
1848 }
1849 .fi
1850 .\"O .SH "SEE ALSO"
1851 .SH 関連項目
1852 .BR printf (1),
1853 .BR asprintf (3),
1854 .BR dprintf (3),
1855 .BR scanf (3),
1856 .BR setlocale (3),
1857 .BR wcrtomb (3),
1858 .BR wprintf (3),
1859 .BR locale (5)