OSDN Git Service

LDP: Update original to LDP v3.68
[linuxjm/LDP_man-pages.git] / original / man3 / printf.3
index 306c01f..f2ba527 100644 (file)
@@ -31,7 +31,7 @@
 .\" 2000-07-26 jsm28@hermes.cam.ac.uk - three small fixes
 .\" 2000-10-16 jsm28@hermes.cam.ac.uk - more fixes
 .\"
-.TH PRINTF 3  2013-03-05 "GNU" "Linux Programmer's Manual"
+.TH PRINTF 3  2013-12-30 "GNU" "Linux Programmer's Manual"
 .SH NAME
 printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf,
 vsnprintf \- formatted output conversion
@@ -160,7 +160,7 @@ and
 do not write more than
 .I size
 bytes (including the terminating null byte (\(aq\e0\(aq)).
-If the output was truncated due to this limit then the return value
+If the output was truncated due to this limit, then the return value
 is the number of characters (excluding the terminating null byte)
 which would have been written to the final string if enough space
 had been available.
@@ -409,8 +409,9 @@ Instead of a decimal digit string one may write "*" or "*m$"
 is given in the next argument, or in the m-th argument, respectively,
 which must be of type
 .IR int .
-If the precision is given as just \(aq.\(aq, or the precision is negative,
-the precision is taken to be zero.
+If the precision is given as just \(aq.\(aq, the precision is taken to
+be zero.
+A negative precision is taken as if the precision were omitted.
 This gives the minimum number of digits to appear for
 .BR d ,
 .BR i ,
@@ -546,7 +547,7 @@ A following integer conversion corresponds to a
 .I ptrdiff_t
 argument.
 .PP
-The SUSv2 only knows about the length modifiers
+The SUSv2 knows about only the length modifiers
 .B h
 (in
 .BR hd ,
@@ -727,7 +728,7 @@ resulting multibyte string is written.
 If no
 .B l
 modifier is present: The
-.I "const char *"
+.I "const char\ *"
 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
@@ -741,7 +742,7 @@ array, the array must contain a terminating null byte.
 If an
 .B l
 modifier is present: The
-.I "const wchar_t *"
+.I "const wchar_t\ *"
 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
@@ -779,16 +780,16 @@ Don't use.
 .TP
 .B p
 The
-.I "void *"
+.I "void\ *"
 pointer argument is printed in hexadecimal (as if by
 .B %#x
 or
-.BR  %#lx ).
+.BR %#lx ).
 .TP
 .B n
 The number of characters written so far is stored into the integer
 indicated by the
-.I "int *"
+.I "int\ *"
 (or variant) pointer argument.
 No argument is converted.
 .TP
@@ -1025,9 +1026,6 @@ one might obtain "Sonntag, 3. Juli, 10:02".
 .PP
 To allocate a sufficiently large string and print into it
 (code correct for both glibc 2.0 and glibc 2.1):
-.PP
-If truncation occurs in glibc versions prior to 2.0.6, this is treated as an
-error instead of being handled gracefully.
 .nf
 
 #include <stdio.h>
@@ -1042,7 +1040,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) {
@@ -1055,8 +1054,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 */
 
@@ -1068,7 +1069,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 {
@@ -1077,6 +1079,9 @@ make_message(const char *fmt, ...)
     }
 }
 .fi
+.PP
+If truncation occurs in glibc versions prior to 2.0.6, this is treated as an
+error instead of being handled gracefully.
 .SH SEE ALSO
 .BR printf (1),
 .BR asprintf (3),
@@ -1086,3 +1091,12 @@ make_message(const char *fmt, ...)
 .BR wcrtomb (3),
 .BR wprintf (3),
 .BR locale (5)
+.SH COLOPHON
+This page is part of release 3.68 of the Linux
+.I man-pages
+project.
+A description of the project,
+information about reporting bugs,
+and the latest version of this page,
+can be found at
+\%http://www.kernel.org/doc/man\-pages/.