]> granicus.if.org Git - strace/commitdiff
Add two generic integer printing functions
authorDmitry V. Levin <ldv@altlinux.org>
Sun, 5 Jul 2015 22:09:29 +0000 (22:09 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 9 Jul 2015 01:35:41 +0000 (01:35 +0000)
Add printnum_short and printnum_int64 in addition to already existing
printnum_int and printnum_long.

* defs.h (printnum_short, printnum_int64): New prototypes.
* util.c (DEF_PRINTNUM): New macro.
(printnum_int, printnum_long): Use DEF_PRINTNUM.
(printnum_short, printnum_int64): New functions.

defs.h
util.c

diff --git a/defs.h b/defs.h
index 9afba0d4d586b9bce60a9f5c0e3538e12518ac90..35a86e00d56a2b6a704b0047d6b4eec6ca23f68c 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -529,10 +529,18 @@ extern void dumpiov_in_mmsghdr(struct tcb *, long);
 extern void dumpiov(struct tcb *, int, long);
 extern void dumpstr(struct tcb *, long, int);
 extern void printstr(struct tcb *, long, long);
+extern void printnum_short(struct tcb *, long, const char *)
+       ATTRIBUTE_FORMAT((printf, 3, 0));
 extern void printnum_int(struct tcb *, long, const char *)
        ATTRIBUTE_FORMAT((printf, 3, 0));
 extern void printnum_long(struct tcb *, long, const char *)
        ATTRIBUTE_FORMAT((printf, 3, 0));
+#if SIZEOF_LONG == 8
+# define printnum_int64 printnum_long
+#else
+extern void printnum_int64(struct tcb *, long, const char *)
+       ATTRIBUTE_FORMAT((printf, 3, 0));
+#endif
 extern void printpath(struct tcb *, long);
 extern void printpathn(struct tcb *, long, unsigned int);
 #define TIMESPEC_TEXT_BUFSIZE (sizeof(long)*3 * 2 + sizeof("{%u, %u}"))
diff --git a/util.c b/util.c
index 04d13cb0a1a86da58578e259ba8d7c79c1a1e48f..98c624b0bf40e0935adfb93f78ca76feeaace2fa 100644 (file)
--- a/util.c
+++ b/util.c
@@ -384,41 +384,28 @@ printaddr(const long addr)
                tprintf("%#lx", addr);
 }
 
-void
-printnum_long(struct tcb *tcp, long addr, const char *fmt)
-{
-       long num;
-
-       if (!addr) {
-               tprints("NULL");
-               return;
-       }
-       if (umove(tcp, addr, &num) < 0) {
-               tprintf("%#lx", addr);
-               return;
-       }
-       tprints("[");
-       tprintf(fmt, num);
-       tprints("]");
+#define DEF_PRINTNUM(name, type) \
+void                                                                   \
+printnum_ ## name(struct tcb *tcp, const long addr, const char *fmt)   \
+{                                                                      \
+       type num;                                                       \
+       if (!addr)                                                      \
+               tprints("NULL");                                        \
+       else if (umove(tcp, addr, &num) < 0)                            \
+               tprintf("%#lx", addr);                                  \
+       else {                                                          \
+               tprints("[");                                           \
+               tprintf(fmt, num);                                      \
+               tprints("]");                                           \
+       }                                                               \
 }
 
-void
-printnum_int(struct tcb *tcp, long addr, const char *fmt)
-{
-       int num;
-
-       if (!addr) {
-               tprints("NULL");
-               return;
-       }
-       if (umove(tcp, addr, &num) < 0) {
-               tprintf("%#lx", addr);
-               return;
-       }
-       tprints("[");
-       tprintf(fmt, num);
-       tprints("]");
-}
+DEF_PRINTNUM(long, long)
+DEF_PRINTNUM(int, int)
+DEF_PRINTNUM(short, short)
+#if SIZEOF_LONG != 8
+DEF_PRINTNUM(int64, uint64_t)
+#endif
 
 const char *
 sprinttime(time_t t)