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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2014-01-02 19:45:47 -05:00
parent ab9001a1e3
commit ccd06097c7
14 changed files with 95 additions and 73 deletions
+3
View File
@@ -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 {
+17 -1
View File
@@ -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_; \
})