summaryrefslogtreecommitdiffstats
path: root/man3/printf.3
diff options
context:
space:
mode:
Diffstat (limited to 'man3/printf.3')
-rw-r--r--man3/printf.3166
1 files changed, 97 insertions, 69 deletions
diff --git a/man3/printf.3 b/man3/printf.3
index 33fe60067..edd6ba85a 100644
--- a/man3/printf.3
+++ b/man3/printf.3
@@ -13,7 +13,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 2023-02-05 "Linux man-pages 6.03"
+.TH printf 3 2023-07-20 "Linux man-pages 6.05.01"
.SH NAME
printf, fprintf, dprintf, sprintf, snprintf, vprintf, vfprintf, vdprintf,
vsprintf, vsnprintf \- formatted output conversion
@@ -324,7 +324,7 @@ and
flags both appear, the
.B \&0
flag is ignored.
-If a precision is given with a numeric conversion
+If a precision is given with an integer conversion
.RB ( d ,
.BR i ,
.BR o ,
@@ -895,7 +895,92 @@ or more means that the output was truncated.
(See also below under NOTES.)
.PP
If an output error is encountered, a negative value is returned.
-.SH VERSIONS
+.SH ATTRIBUTES
+For an explanation of the terms used in this section, see
+.BR attributes (7).
+.TS
+allbox;
+lbx lb lb
+l l l.
+Interface Attribute Value
+T{
+.na
+.nh
+.BR printf (),
+.BR fprintf (),
+.BR sprintf (),
+.BR snprintf (),
+.BR vprintf (),
+.BR vfprintf (),
+.BR vsprintf (),
+.BR vsnprintf ()
+T} Thread safety MT-Safe locale
+.TE
+.sp 1
+.SH STANDARDS
+.TP
+.BR fprintf ()
+.TQ
+.BR printf ()
+.TQ
+.BR sprintf ()
+.TQ
+.BR vprintf ()
+.TQ
+.BR vfprintf ()
+.TQ
+.BR vsprintf ()
+.TQ
+.BR snprintf ()
+.TQ
+.BR vsnprintf ()
+C11, POSIX.1-2008.
+.TP
+.BR dprintf ()
+.TQ
+.BR vdprintf ()
+GNU, POSIX.1-2008.
+.SH HISTORY
+.TP
+.BR fprintf ()
+.TQ
+.BR printf ()
+.TQ
+.BR sprintf ()
+.TQ
+.BR vprintf ()
+.TQ
+.BR vfprintf ()
+.TQ
+.BR vsprintf ()
+C89, POSIX.1-2001.
+.TP
+.BR snprintf ()
+.TQ
+.BR vsnprintf ()
+SUSv2, C99, POSIX.1-2001.
+.IP
+Concerning the return value of
+.BR snprintf (),
+SUSv2 and C99 contradict each other: when
+.BR snprintf ()
+is called with
+.IR size =0
+then SUSv2 stipulates an unspecified return value less than 1,
+while C99 allows
+.I str
+to be NULL in this case, and gives the return value (as always)
+as the number of characters that would have been written in case
+the output string has been large enough.
+POSIX.1-2001 and later align their specification of
+.BR snprintf ()
+with C99.
+.TP
+.BR dprintf ()
+.TQ
+.BR vdprintf ()
+GNU, POSIX.1-2008.
+.PP
.\" Linux libc4 knows about the five C standard flags.
.\" It knows about the length modifiers \fBh\fP, \fBl\fP, \fBL\fP,
.\" and the conversions
@@ -935,64 +1020,7 @@ of the
.B m
conversion specifier, that is
.IR %#m .
-.SH ATTRIBUTES
-For an explanation of the terms used in this section, see
-.BR attributes (7).
-.ad l
-.nh
-.TS
-allbox;
-lbx lb lb
-l l l.
-Interface Attribute Value
-T{
-.BR printf (),
-.BR fprintf (),
-.BR sprintf (),
-.BR snprintf (),
-.BR vprintf (),
-.BR vfprintf (),
-.BR vsprintf (),
-.BR vsnprintf ()
-T} Thread safety MT-Safe locale
-.TE
-.hy
-.ad
-.sp 1
-.SH STANDARDS
-.BR fprintf (),
-.BR printf (),
-.BR sprintf (),
-.BR snprintf (),
-.BR vprintf (),
-.BR vfprintf (),
-.BR vsprintf (),
-.BR vsnprintf ():
-POSIX.1-2001, POSIX.1-2008, C99.
-.PP
-The
-.BR dprintf ()
-and
-.BR vdprintf ()
-functions were originally GNU extensions that were later standardized
-in POSIX.1-2008.
-.PP
-Concerning the return value of
-.BR snprintf (),
-SUSv2 and C99 contradict each other: when
-.BR snprintf ()
-is called with
-.IR size =0
-then SUSv2 stipulates an unspecified return value less than 1,
-while C99 allows
-.I str
-to be NULL in this case, and gives the return value (as always)
-as the number of characters that would have been written in case
-the output string has been large enough.
-POSIX.1-2001 and later align their specification of
-.BR snprintf ()
-with C99.
-.SH NOTES
+.SH CAVEATS
Some programs imprudently rely on code such as the following
.PP
.in +4n
@@ -1162,7 +1190,7 @@ To allocate a sufficiently large string and print into it
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
-
+\&
char *
make_message(const char *fmt, ...)
{
@@ -1170,30 +1198,30 @@ make_message(const char *fmt, ...)
size_t size = 0;
char *p = NULL;
va_list ap;
-
+\&
/* Determine required size. */
-
+\&
va_start(ap, fmt);
n = vsnprintf(p, size, fmt, ap);
va_end(ap);
-
+\&
if (n < 0)
return NULL;
-
+\&
size = (size_t) n + 1; /* One extra byte for \[aq]\e0\[aq] */
p = malloc(size);
if (p == NULL)
return NULL;
-
+\&
va_start(ap, fmt);
n = vsnprintf(p, size, fmt, ap);
va_end(ap);
-
+\&
if (n < 0) {
free(p);
return NULL;
}
-
+\&
return p;
}
.EE