OSDN Git Service

(split) Import translated manuals from JM CVS Repository.
[linuxjm/LDP_man-pages.git] / obsolete / man3 / snprintf.3
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\" (c) 1995 by Jim Van Zandt <jrv@vanzandt.mv.com>
3 .\"
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\" 
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\" 
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" 
24 .\" Added _GNU_SOURCE, aeb, Sat Jul  5 23:10:04 MET 1997
25 .\"
26 .\" Japanese Version Copyright (c) 1998 Akihiro Motoki all rights reserved.
27 .\" Translated Mon May 25 1998 by Akihiro Motoki <motoki@hal.t.u-tokyo.ac.jp>
28 .\" Modified Thu Nov 11 1999 by Akihiro Motoki <motoki@ptl.abk.nec.co.jp>
29 .\"
30 .TH SNPRINTF 3  "16 September 1995" "GNU" "Linux Programmer's Manual"
31 .\"O .SH NAME
32 .\"O .snprintf, vsnprintf \- formatted output conversion
33 .SH Ì¾Á°
34 snprintf, vsnprintf \- »ØÄꤷ¤¿½ñ¼°¤Ç½ÐÎϤò¹Ô¤¦
35 .\"O .SH SYNOPSIS
36 .SH ½ñ¼°
37 .B #define _GNU_SOURCE
38 .br
39 .B #include <stdio.h>
40 .sp
41 .BI "int snprintf ( char *" str ", size_t " n ", "
42 .br
43 .BI "                         const char *" format ", ... );"
44 .sp
45 .B #include <stdarg.h>
46 .sp
47 .BI "int vsnprintf ( char *" str ", size_t " n ", "
48 .br
49 .BI "                         const char *" format ", va_list " ap " );"
50 .\"O .SH DESCRIPTION
51 .\"O \fBsnprintf\fP writes output to the string \fIstr\fP, under control of
52 .\"O the \fIformat\fP string that specifies how subsequent arguments are
53 .\"O converted for output.  It is similar to \fBsprintf\fP(3), except that
54 .\"O \fIn\fP specifies the maximum number of characters to produce.  The
55 .\"O trailing null character is counted towards this limit, so you should
56 .\"O allocate at least \fIn\fP characters for the string \fIstr\fP.
57 .SH ÀâÌÀ
58 \fBsnprintf\fP ´Ø¿ô¤Ï¡¢\fIformat\fP ¤Ç»ØÄꤵ¤ì¤¿½ñ¼°¤Ë½¾¤¤¡¢¤½¤ì°Ê¹ß¤Ë
59 Í¿¤¨¤é¤ì¤¿°ú¿ô¤òÀ°·Á¤·¤Æ½ÐÎϤ·¡¢½ÐÎϤÏʸ»úÎó \fIstr\fP ¤Ë½ñ¤­¹þ¤Þ¤ì¤ë¡£
60 ¤³¤Î´Ø¿ô¤Ï \fBsprintf\fP(3) ¤Ë»÷¤Æ¤¤¤ë¤¬¡¢ ½ÐÎϤµ¤ì¤ë
61 ºÇÂçʸ»ú¿ô \fIn\fP ¤ò»ØÄê¤Ç¤­¤ëÅÀ¤¬°Û¤Ê¤ë¡£
62 ʸ»úÎó¤Î½ªÃ¼¤ò¼¨¤¹¥Ì¥ëʸ»ú¤âºÇÂçʸ»ú¿ô¤Ë´Þ¤Þ¤ì¤ë¤¿¤á¡¢
63 ½ÐÎÏʸ»úÎó \fIstr\fP ¤Ë¤Ï¾¯¤Ê¤¯¤È¤â \fIn\fP Ê¸»ú³ä¤êÅö¤Æ¤ëɬÍפ¬¤¢¤ë¡£
64 .PP
65 .\"O \fBvsnprintf\fP is the equivalent of \fBsnprintf\fP with the variable
66 .\"O argument list specified directly as for \fBvprintf\fP.
67 \fBvsnprintf\fP ´Ø¿ô¤Ï²ÄÊѤΰú¿ô¥ê¥¹¥È¤ò¤â¤Ã¤¿ \fBsnprintf\fP ¤ÈÅù²Á¤Ç¤¢¤ë¡£
68 °ú¿ô¥ê¥¹¥È¤Ë¤Ä¤¤¤Æ¤Ï \fBvprintf\fP ¤Î¹à¤ÇÀâÌÀ¤µ¤ì¤Æ¤¤¤ë¡£
69 .\"O .SH "RETURN VALUE"
70 .\"O If the output was truncated, the return value is -1, otherwise it is
71 .\"O the number of characters stored, not including the terminating null.
72 .\"O (Thus until glibc 2.0.6.  Since glibc 2.1 these functions
73 .\"O return the  number of characters (excluding the trailing null)
74 .\"O which would have been written to the final string if enough space
75 .\"O had been available.)
76 .SH ÊÖ¤êÃÍ
77 ½ÐÎϤ¬Ä¹¤¯ÅÓÃæ¤Ç¥«¥Ã¥È¤µ¤ì¤¿¾ì¹ç¤Ë¤Ï -1 ¤òÊÖ¤·¡¢¤½¤ì°Ê³°¤Ï \fIstr\fP ¤ËÊݸ
78 ¤µ¤ì¤¿Ê¸»ú¿ô(ʸ»úÎó¤Î½ªÃ¼¤ò¼¨¤¹'\e0'¤ò½ü¤¯)¤òÊÖ¤¹¡£
79 (⤷ glibc 2.0.6 ¤Þ¤Ç¤Î»ÅÍͤǤ¢¤ë¡£
80 glibc 2.1 °Ê¹ß¤Ç¤Ï¡¢¤³¤ì¤é¤Î´Ø¿ô¤Ï¡¢¤â¤·ÍøÍѲÄǽ¤Ê½½Ê¬¤Ê¥¹¥Ú¡¼¥¹¤¬¤¢¤ì¤Ð
81 ½ñ¤­¹þ¤Þ¤ì¤¿¤Ç¤¢¤í¤¦Ê¸»ú¿ô(ʸ»úÎó¤Î½ªÃ¼¤ò¼¨¤¹'\e0'¤ò½ü¤¯)¤òÊÖ¤¹¡£)
82 .\"O .SH EXAMPLE
83 .SH Îã
84 .br
85 .\"O Here is an example program which dynamically enlarges its output buffer,
86 .\"O and works correctly under both glibc 2.0 and glibc 2.1.
87 ½ÐÎϥХåե¡¤òưŪ¤Ë³ÈÄ¥¤¹¤ë¥×¥í¥°¥é¥àÎã¤ò°Ê²¼¤Ë¼¨¤¹¡£
88 ¤³¤Î¥×¥í¥°¥é¥à¤Ï¡¢glibc 2.0 ¤È glibc 2.1 ¤Î¤É¤Á¤é¤Ç¤âÀµ¤·¤¯Æ°ºî¤¹¤ë¡£
89 .br
90 .sp
91 .nf
92 .\"O      /* Construct a message describing the value of a 
93 .\"O         variable whose name is NAME and whose value is 
94 .\"O         VALUE. */
95     /* ÊÑ¿ô̾¤È¤½¤ÎÃͤòµ­½Ò¤¹¤ë "value of ÊÑ¿ô̾ is ÃÍ"
96        ¤È¤¤¤¦¥á¥Ã¥»¡¼¥¸¤òºîÀ®¤¹¤ë´Ø¿ô */
97     char *
98     make_message (char *name, char *value)
99     {
100 .\"O       /* Guess we need no more than 100 chars of space. */
101       /* ½ÐÎϥХåե¡¤Ï100ʸ»úʬ¤Ç½½Ê¬¤Ç¤¢¤ë¤È²¾Äê */
102       int size = 100;
103       char *buffer = (char *) xmalloc (size);
104       while (1)
105         {
106 .\"O           /* Try to print in the allocated space. */
107           /* ³ÎÊݺѤߤΥХåե¡¤Ë½ÐÎϤ·¤è¤¦¤È¤¹¤ë */
108           int nchars = snprintf (buffer, size,
109                         "value of %s is %s", name, value);
110 .\"O           /* If that worked, return the string. */
111           /* À®¸ù¤¹¤ì¤Ð¡¢¥Ð¥Ã¥Õ¥¡Æâ¤Îʸ»úÎó¤òÊÖ¤¹ */
112           if (nchars > -1 && nchars < size)
113             return buffer;
114 .\"O           /* Else try again with more space. */
115 .\"O           if (nchars > -1)
116 .\"O             size = nchars+1;  /* precisely what is needed */
117 .\"O           else
118 .\"O             size *= 2;        /* twice the old size */
119           /* ¼ºÇÔ¤¹¤ì¤Ð¡¢¤µ¤é¤Ë¥Ð¥Ã¥Õ¥¡¤ò³ÎÊݤ·¤ÆºÆ»î¹Ô */
120           if (nchars > -1)
121             size = nchars+1;  /* É¬ÍפʥХåե¡Ä¹¤òÀµ³Î¤Ë³ÎÊÝ */
122           else
123             size *= 2;        /* ¥Ð¥Ã¥Õ¥¡Ä¹¤ò£²Çܤˤ¹¤ë */
124           buffer = (char *) xrealloc (buffer, size);
125         }
126     }
127 .fi
128 .RE
129 .\"O .SH "CONFORMING TO"
130 .\"O These are GNU extensions, expected to become part of ISO C9x.
131 .SH ½àµò
132 ¤³¤ì¤é¤Î´Ø¿ô¤Ï GNU ¤Ë¤è¤ë³ÈÄ¥¤Ç¤¢¤ë¡£ISO C9x ¤Î°ìÉô¤È¤Ê¤ëͽÄê¤Ç¤¢¤ë¡£
133 .\"O .SH "SEE ALSO"
134 .SH ´ØÏ¢¹àÌÜ
135 .BR printf "(3), " sprintf "(3), " vsprintf "(3), " stdarg (3)