summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-12-30 17:22:26 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-01-02 19:45:47 -0500
commitccd06097c79218f7d5ea4c21721bbcbc7c467dca (patch)
tree168bee7d15161c2c1cba3926447162b84c761898 /src/shared
parentab9001a1e3dc6e60d0cdf53363dc5d18dcc382fd (diff)
Use format patterns for usec_t, pid_t, nsec_t, usec_t
It is nicer to predefine patterns using configure time check instead of using casts everywhere. Since we do not need to use any flags, include "%" in the format instead of excluding it like PRI* macros.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/time-util.h3
-rw-r--r--src/shared/util.h18
2 files changed, 20 insertions, 1 deletions
diff --git a/src/shared/time-util.h b/src/shared/time-util.h
index 913821a6bd..96f2ec8fa3 100644
--- a/src/shared/time-util.h
+++ b/src/shared/time-util.h
@@ -27,6 +27,9 @@
typedef uint64_t usec_t;
typedef uint64_t nsec_t;
+#define NSEC_FMT "%" PRIu64
+#define USEC_FMT "%" PRIu64
+
#include "macro.h"
typedef struct dual_timestamp {
diff --git a/src/shared/util.h b/src/shared/util.h
index f6d2cedd88..d9720d0a36 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -42,6 +42,22 @@
#include <mntent.h>
#include <sys/socket.h>
+#if SIZEOF_PID_T == 4
+# define PID_FMT "%" PRIu32
+#elif SIZEOF_PID_T == 2
+# define PID_FMT "%" PRIu16
+#else
+# error Unknown pid_t size
+#endif
+
+#if SIZEOF_UID_T == 4
+# define UID_FMT "%" PRIu32
+#elif SIZEOF_UID_T == 2
+# define UID_FMT "%" PRIu16
+#else
+# error Unknown uid_t size
+#endif
+
#include "macro.h"
#include "time-util.h"
@@ -763,7 +779,7 @@ int unlink_noerrno(const char *path);
pid_t _pid_ = (pid); \
char *_r_; \
_r_ = alloca(sizeof("/proc/") -1 + DECIMAL_STR_MAX(pid_t) + 1 + sizeof(field)); \
- sprintf(_r_, "/proc/%lu/" field, (unsigned long) _pid_); \
+ sprintf(_r_, "/proc/"PID_FMT"/" field, _pid_); \
_r_; \
})