summaryrefslogtreecommitdiffstats
path: root/src/basic/format-util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/basic/format-util.h')
-rw-r--r--src/basic/format-util.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/basic/format-util.h b/src/basic/format-util.h
index 8719df3..ba7cff6 100644
--- a/src/basic/format-util.h
+++ b/src/basic/format-util.h
@@ -18,6 +18,14 @@ assert_cc(sizeof(uid_t) == sizeof(uint32_t));
assert_cc(sizeof(gid_t) == sizeof(uint32_t));
#define GID_FMT "%" PRIu32
+/* Note: the lifetime of the compound literal is the immediately surrounding block,
+ * see C11 ยง6.5.2.5, and
+ * https://stackoverflow.com/questions/34880638/compound-literal-lifetime-and-if-blocks */
+#define FORMAT_UID(uid) \
+ snprintf_ok((char[DECIMAL_STR_MAX(uid_t)]){}, DECIMAL_STR_MAX(uid_t), UID_FMT, uid)
+#define FORMAT_GID(gid) \
+ snprintf_ok((char[DECIMAL_STR_MAX(gid_t)]){}, DECIMAL_STR_MAX(gid_t), GID_FMT, gid)
+
#if SIZEOF_TIME_T == 8
# define PRI_TIME PRIi64
#elif SIZEOF_TIME_T == 4