summaryrefslogtreecommitdiffstats
path: root/lib/printf
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2019-05-12 21:11:19 +0200
committerDavid Lamparter <equinox@diac24.net>2019-06-03 16:44:24 +0200
commit32b67a0aeb001d3974f432becd8c8783c7ed6d53 (patch)
tree9a9b0c0d53762648804dfc03cbf2a81abacea55d /lib/printf
parentlib/printf: use system printf for floats (diff)
downloadfrr-32b67a0aeb001d3974f432becd8c8783c7ed6d53.tar.xz
frr-32b67a0aeb001d3974f432becd8c8783c7ed6d53.zip
lib/printf: add %Ld/%Lu for int64_t/uint64_t
[u]int64_t is the only type in the intX_t family that needs special-casing for printf since the calling convention may differ between 32-bit and 64-bit systems. Adding the L specifier allows us to eschew the gnarly-looking PRIu64. Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib/printf')
-rw-r--r--lib/printf/printf-pos.c22
-rw-r--r--lib/printf/vfprintf.c10
2 files changed, 19 insertions, 13 deletions
diff --git a/lib/printf/printf-pos.c b/lib/printf/printf-pos.c
index f4104c52b..7f83dea1a 100644
--- a/lib/printf/printf-pos.c
+++ b/lib/printf/printf-pos.c
@@ -65,8 +65,8 @@ enum typeid {
T_UNUSED, TP_SHORT, T_INT, T_U_INT, TP_INT,
T_LONG, T_U_LONG, TP_LONG, T_LLONG, T_U_LLONG, TP_LLONG,
T_PTRDIFFT, TP_PTRDIFFT, T_SSIZET, T_SIZET, TP_SSIZET,
- T_INTMAXT, T_UINTMAXT, TP_INTMAXT, TP_VOID, TP_CHAR, TP_SCHAR,
- T_DOUBLE, T_LONG_DOUBLE, T_WINT, TP_WCHAR
+ T_INT64T, T_UINT64T, T_INTMAXT, T_UINTMAXT, TP_INTMAXT, TP_VOID,
+ TP_CHAR, TP_SCHAR, T_DOUBLE, T_LONG_DOUBLE, T_WINT, TP_WCHAR
};
/* An expandable array of types. */
@@ -145,7 +145,9 @@ addsarg(struct typetable *types, int flags)
if (_ensurespace(types))
return (-1);
- if (flags & INTMAXT)
+ if (flags & LONGDBL)
+ types->table[types->nextarg++] = T_INT64T;
+ else if (flags & INTMAXT)
types->table[types->nextarg++] = T_INTMAXT;
else if (flags & SIZET)
types->table[types->nextarg++] = T_SSIZET;
@@ -166,7 +168,9 @@ adduarg(struct typetable *types, int flags)
if (_ensurespace(types))
return (-1);
- if (flags & INTMAXT)
+ if (flags & LONGDBL)
+ types->table[types->nextarg++] = T_UINT64T;
+ else if (flags & INTMAXT)
types->table[types->nextarg++] = T_UINTMAXT;
else if (flags & SIZET)
types->table[types->nextarg++] = T_SIZET;
@@ -311,11 +315,9 @@ reswitch: switch (ch) {
goto rflag;
}
goto reswitch;
-#ifndef NO_FLOATING_POINT
case 'L':
flags |= LONGDBL;
goto rflag;
-#endif
case 'h':
if (flags & SHORTINT) {
flags &= ~SHORTINT;
@@ -504,11 +506,9 @@ reswitch: switch (ch) {
goto rflag;
}
goto reswitch;
-#ifndef NO_FLOATING_POINT
case 'L':
flags |= LONGDBL;
goto rflag;
-#endif
case 'h':
if (flags & SHORTINT) {
flags &= ~SHORTINT;
@@ -743,6 +743,12 @@ build_arg_table(struct typetable *types, va_list ap, union arg **argtable)
case TP_INTMAXT:
(*argtable) [n].pintmaxarg = va_arg (ap, intmax_t *);
break;
+ case T_INT64T:
+ (*argtable) [n].intmaxarg = va_arg (ap, int64_t);
+ break;
+ case T_UINT64T:
+ (*argtable) [n].uintmaxarg = va_arg (ap, uint64_t);
+ break;
case T_DOUBLE:
#ifndef NO_FLOATING_POINT
(*argtable) [n].doublearg = va_arg (ap, double);
diff --git a/lib/printf/vfprintf.c b/lib/printf/vfprintf.c
index 58412a48c..8c26c2f7c 100644
--- a/lib/printf/vfprintf.c
+++ b/lib/printf/vfprintf.c
@@ -224,14 +224,16 @@ __vfprintf(FILE *fp, const char *fmt0, va_list ap)
flags&SHORTINT ? (u_long)(u_short)GETARG(int) : \
flags&CHARINT ? (u_long)(u_char)GETARG(int) : \
(u_long)GETARG(u_int))
-#define INTMAX_SIZE (INTMAXT|SIZET|PTRDIFFT|LLONGINT)
+#define INTMAX_SIZE (INTMAXT|SIZET|PTRDIFFT|LLONGINT|LONGDBL)
#define SJARG() \
- (flags&INTMAXT ? GETARG(intmax_t) : \
+ (flags&LONGDBL ? GETARG(int64_t) : \
+ flags&INTMAXT ? GETARG(intmax_t) : \
flags&SIZET ? (intmax_t)GETARG(ssize_t) : \
flags&PTRDIFFT ? (intmax_t)GETARG(ptrdiff_t) : \
(intmax_t)GETARG(long long))
#define UJARG() \
- (flags&INTMAXT ? GETARG(uintmax_t) : \
+ (flags&LONGDBL ? GETARG(uint64_t) : \
+ flags&INTMAXT ? GETARG(uintmax_t) : \
flags&SIZET ? (uintmax_t)GETARG(size_t) : \
flags&PTRDIFFT ? (uintmax_t)GETARG(ptrdiff_t) : \
(uintmax_t)GETARG(unsigned long long))
@@ -377,11 +379,9 @@ reswitch: switch (ch) {
}
width = n;
goto reswitch;
-#ifndef NO_FLOATING_POINT
case 'L':
flags |= LONGDBL;
goto rflag;
-#endif
case 'h':
if (flags & SHORTINT) {
flags &= ~SHORTINT;