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
path, st.st_mode & 0777, mode);
if ((uid != UID_INVALID && st.st_uid != uid) ||
- (gid != GID_INVALID && st.st_gid != gid)) {
- char u[DECIMAL_STR_MAX(uid_t)] = "-", g[DECIMAL_STR_MAX(gid_t)] = "-";
-
- if (uid != UID_INVALID)
- xsprintf(u, UID_FMT, uid);
- if (gid != UID_INVALID)
- xsprintf(g, GID_FMT, gid);
+ (gid != GID_INVALID && st.st_gid != gid))
return log_full_errno(flags & MKDIR_WARN_MODE ? LOG_WARNING : LOG_DEBUG, SYNTHETIC_ERRNO(EEXIST),
"Directory \"%s\" already exists, but is owned by "UID_FMT":"GID_FMT" (%s:%s was requested), refusing.",
- path, st.st_uid, st.st_gid, u, g);
- }
+ path, st.st_uid, st.st_gid, uid != UID_INVALID ? FORMAT_UID(uid) : "-",
+ gid != UID_INVALID ? FORMAT_GID(gid) : "-");
return 0;
}
#include "constants.h"
#include "errno-util.h"
#include "fd-util.h"
+#include "format-util.h"
#include "glyph-util.h"
#include "hexdecoct.h"
#include "hostname-util.h"
return true;
/* Otherwise, we have to figure out our user id and name, and compare things with that. */
- char buf[DECIMAL_STR_MAX(uid_t)];
- xsprintf(buf, UID_FMT, uid);
-
- f = startswith(user_and_machine, buf);
+ f = startswith(user_and_machine, FORMAT_UID(uid));
if (!f) {
un = getusername_malloc();
if (!un)
if (isempty(content))
return 0;
- char t[DECIMAL_STR_MAX(uid_t)];
- xsprintf(t, UID_FMT, uid);
-
- return string_contains_word(content, NULL, t);
+ return string_contains_word(content, NULL, FORMAT_UID(uid));
}
static int uid_get_array(uid_t uid, const char *variable, char ***array) {
uid_range_free(c->uid_range);
}
-/* 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(is_set, uid) \
- ((is_set) ? snprintf_ok((char[DECIMAL_STR_MAX(uid_t)]){}, DECIMAL_STR_MAX(uid_t), UID_FMT, uid) : "(unset)")
-#define FORMAT_GID(is_set, gid) \
- ((is_set) ? snprintf_ok((char[DECIMAL_STR_MAX(gid_t)]){}, DECIMAL_STR_MAX(gid_t), GID_FMT, gid) : "(unset)")
-
static void maybe_emit_login_defs_warning(Context *c) {
assert(c);
(a->uid_set && a->uid != b->uid)) {
log_syntax(NULL, LOG_DEBUG, a->filename, a->line, 0,
"Item not equivalent because UIDs differ (%s vs. %s)",
- FORMAT_UID(a->uid_set, a->uid), FORMAT_UID(b->uid_set, b->uid));
+ a->uid_set ? FORMAT_UID(a->uid) : "(unset)",
+ b->uid_set ? FORMAT_UID(b->uid) : "(unset)");
return false;
}
(a->gid_set && a->gid != b->gid)) {
log_syntax(NULL, LOG_DEBUG, a->filename, a->line, 0,
"Item not equivalent because GIDs differ (%s vs. %s)",
- FORMAT_GID(a->gid_set, a->gid), FORMAT_GID(b->gid_set, b->gid));
+ a->gid_set ? FORMAT_GID(a->gid) : "(unset)",
+ b->gid_set ? FORMAT_GID(b->gid) : "(unset)");
return false;
}