summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-04-25 07:45:15 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-05-15 15:29:58 +0200
commitde0671ee7fe465e108f62dcbbbe9366f81dd9e9a (patch)
tree3ee30af44852655c365104703359b47a6e6219b5 /src/shared
parent12ed81d9c88406234c20e9261ae8c8b992d8bc4d (diff)
Remove unnecessary casts in printfs
No functional change expected :)
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/ask-password-api.c8
-rw-r--r--src/shared/cgroup-util.c2
-rw-r--r--src/shared/def.h2
-rw-r--r--src/shared/log.c4
-rw-r--r--src/shared/logs-show.c30
-rw-r--r--src/shared/socket-util.c2
-rw-r--r--src/shared/time-util.c50
-rw-r--r--src/shared/util.c8
-rw-r--r--src/shared/util.h16
9 files changed, 69 insertions, 53 deletions
diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c
index c3c78b69f..5997a03fb 100644
--- a/src/shared/ask-password-api.c
+++ b/src/shared/ask-password-api.c
@@ -359,14 +359,14 @@ int ask_password_agent(
fprintf(f,
"[Ask]\n"
- "PID=%lu\n"
+ "PID="PID_FMT"\n"
"Socket=%s\n"
"AcceptCached=%i\n"
- "NotAfter=%llu\n",
- (unsigned long) getpid(),
+ "NotAfter="USEC_FMT"\n",
+ getpid(),
socket_name,
accept_cached ? 1 : 0,
- (unsigned long long) until);
+ until);
if (message)
fprintf(f, "Message=%s\n", message);
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index 139888c4a..c1c4d409a 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -641,7 +641,7 @@ int cg_attach(const char *controller, const char *path, pid_t pid) {
if (pid == 0)
pid = getpid();
- snprintf(c, sizeof(c), "%lu\n", (unsigned long) pid);
+ snprintf(c, sizeof(c), PID_FMT"\n", pid);
return write_string_file(fs, c);
}
diff --git a/src/shared/def.h b/src/shared/def.h
index aa489d80d..a52853cfd 100644
--- a/src/shared/def.h
+++ b/src/shared/def.h
@@ -71,7 +71,7 @@
#endif
#define UNIX_USER_BUS_FMT "unix:path=%s/bus"
-#define KERNEL_USER_BUS_FMT "kernel:path=/dev/kdbus/%lu-user/bus"
+#define KERNEL_USER_BUS_FMT "kernel:path=/dev/kdbus/"UID_FMT"-user/bus"
#ifndef TTY_GID
#define TTY_GID 5
diff --git a/src/shared/log.c b/src/shared/log.c
index a4b3b68ef..9039db349 100644
--- a/src/shared/log.c
+++ b/src/shared/log.c
@@ -378,7 +378,7 @@ static int write_to_syslog(
if (strftime(header_time, sizeof(header_time), "%h %e %T ", tm) <= 0)
return -EINVAL;
- snprintf(header_pid, sizeof(header_pid), "[%lu]: ", (unsigned long) getpid());
+ snprintf(header_pid, sizeof(header_pid), "["PID_FMT"]: ", getpid());
char_array_0(header_pid);
IOVEC_SET_STRING(iovec[0], header_priority);
@@ -426,7 +426,7 @@ static int write_to_kmsg(
snprintf(header_priority, sizeof(header_priority), "<%i>", level);
char_array_0(header_priority);
- snprintf(header_pid, sizeof(header_pid), "[%lu]: ", (unsigned long) getpid());
+ snprintf(header_pid, sizeof(header_pid), "["PID_FMT"]: ", getpid());
char_array_0(header_pid);
IOVEC_SET_STRING(iovec[0], header_priority);
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index b0b66f64f..72c9ad2eb 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -301,8 +301,8 @@ static int output_short(
}
fprintf(f, "[%5llu.%06llu]",
- (unsigned long long) (t / USEC_PER_SEC),
- (unsigned long long) (t % USEC_PER_SEC));
+ t / USEC_PER_SEC,
+ t % USEC_PER_SEC);
n += 1 + 5 + 1 + 6 + 1;
@@ -531,12 +531,12 @@ static int output_export(
fprintf(f,
"__CURSOR=%s\n"
- "__REALTIME_TIMESTAMP=%llu\n"
- "__MONOTONIC_TIMESTAMP=%llu\n"
+ "__REALTIME_TIMESTAMP="USEC_FMT"\n"
+ "__MONOTONIC_TIMESTAMP="USEC_FMT"\n"
"_BOOT_ID=%s\n",
cursor,
- (unsigned long long) realtime,
- (unsigned long long) monotonic,
+ realtime,
+ monotonic,
sd_id128_to_string(boot_id, sid));
JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
@@ -673,12 +673,12 @@ static int output_json(
fprintf(f,
"{\n"
"\t\"__CURSOR\" : \"%s\",\n"
- "\t\"__REALTIME_TIMESTAMP\" : \"%llu\",\n"
- "\t\"__MONOTONIC_TIMESTAMP\" : \"%llu\",\n"
+ "\t\"__REALTIME_TIMESTAMP\" : \""USEC_FMT"\",\n"
+ "\t\"__MONOTONIC_TIMESTAMP\" : \""USEC_FMT"\",\n"
"\t\"_BOOT_ID\" : \"%s\"",
cursor,
- (unsigned long long) realtime,
- (unsigned long long) monotonic,
+ realtime,
+ monotonic,
sd_id128_to_string(boot_id, sid));
else {
if (mode == OUTPUT_JSON_SSE)
@@ -686,12 +686,12 @@ static int output_json(
fprintf(f,
"{ \"__CURSOR\" : \"%s\", "
- "\"__REALTIME_TIMESTAMP\" : \"%llu\", "
- "\"__MONOTONIC_TIMESTAMP\" : \"%llu\", "
+ "\"__REALTIME_TIMESTAMP\" : \""USEC_FMT"\", "
+ "\"__MONOTONIC_TIMESTAMP\" : \""USEC_FMT"\", "
"\"_BOOT_ID\" : \"%s\"",
cursor,
- (unsigned long long) realtime,
- (unsigned long long) monotonic,
+ realtime,
+ monotonic,
sd_id128_to_string(boot_id, sid));
}
@@ -1100,7 +1100,7 @@ int add_matches_for_user_unit(sd_journal *j, const char *unit, uid_t uid) {
m2 = strappenda("USER_UNIT=", unit);
m3 = strappenda("COREDUMP_USER_UNIT=", unit);
m4 = strappenda("OBJECT_SYSTEMD_USER_UNIT=", unit);
- sprintf(muid, "_UID=%lu", (unsigned long) uid);
+ sprintf(muid, "_UID="UID_FMT, uid);
(void) (
/* Look for messages from the user service itself */
diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c
index 5ef2e2244..997a1ceba 100644
--- a/src/shared/socket-util.c
+++ b/src/shared/socket-util.c
@@ -594,7 +594,7 @@ int getpeername_pretty(int fd, char **ret) {
if (r < 0)
return r;
- if (asprintf(ret, "PID %lu/UID %lu", (unsigned long) ucred.pid, (unsigned long) ucred.uid) < 0)
+ if (asprintf(ret, "PID "PID_FMT"/UID "UID_FMT, ucred.pid, ucred.uid) < 0)
return -ENOMEM;
return 0;
diff --git a/src/shared/time-util.c b/src/shared/time-util.c
index eb5c1ae79..c66763872 100644
--- a/src/shared/time-util.c
+++ b/src/shared/time-util.c
@@ -209,44 +209,44 @@ char *format_timestamp_relative(char *buf, size_t l, usec_t t) {
if (d >= USEC_PER_YEAR)
snprintf(buf, l, "%llu years %llu months %s",
- (unsigned long long) (d / USEC_PER_YEAR),
- (unsigned long long) ((d % USEC_PER_YEAR) / USEC_PER_MONTH), s);
+ d / USEC_PER_YEAR,
+ (d % USEC_PER_YEAR) / USEC_PER_MONTH, s);
else if (d >= USEC_PER_MONTH)
snprintf(buf, l, "%llu months %llu days %s",
- (unsigned long long) (d / USEC_PER_MONTH),
- (unsigned long long) ((d % USEC_PER_MONTH) / USEC_PER_DAY), s);
+ d / USEC_PER_MONTH,
+ (d % USEC_PER_MONTH) / USEC_PER_DAY, s);
else if (d >= USEC_PER_WEEK)
snprintf(buf, l, "%llu weeks %llu days %s",
- (unsigned long long) (d / USEC_PER_WEEK),
- (unsigned long long) ((d % USEC_PER_WEEK) / USEC_PER_DAY), s);
+ d / USEC_PER_WEEK,
+ (d % USEC_PER_WEEK) / USEC_PER_DAY, s);
else if (d >= 2*USEC_PER_DAY)
- snprintf(buf, l, "%llu days %s", (unsigned long long) (d / USEC_PER_DAY), s);
+ snprintf(buf, l, "%llu days %s", d / USEC_PER_DAY, s);
else if (d >= 25*USEC_PER_HOUR)
snprintf(buf, l, "1 day %lluh %s",
- (unsigned long long) ((d - USEC_PER_DAY) / USEC_PER_HOUR), s);
+ (d - USEC_PER_DAY) / USEC_PER_HOUR, s);
else if (d >= 6*USEC_PER_HOUR)
snprintf(buf, l, "%lluh %s",
- (unsigned long long) (d / USEC_PER_HOUR), s);
+ d / USEC_PER_HOUR, s);
else if (d >= USEC_PER_HOUR)
snprintf(buf, l, "%lluh %llumin %s",
- (unsigned long long) (d / USEC_PER_HOUR),
- (unsigned long long) ((d % USEC_PER_HOUR) / USEC_PER_MINUTE), s);
+ d / USEC_PER_HOUR,
+ (d % USEC_PER_HOUR) / USEC_PER_MINUTE, s);
else if (d >= 5*USEC_PER_MINUTE)
snprintf(buf, l, "%llumin %s",
- (unsigned long long) (d / USEC_PER_MINUTE), s);
+ d / USEC_PER_MINUTE, s);
else if (d >= USEC_PER_MINUTE)
snprintf(buf, l, "%llumin %llus %s",
- (unsigned long long) (d / USEC_PER_MINUTE),
- (unsigned long long) ((d % USEC_PER_MINUTE) / USEC_PER_SEC), s);
+ d / USEC_PER_MINUTE,
+ (d % USEC_PER_MINUTE) / USEC_PER_SEC, s);
else if (d >= USEC_PER_SEC)
snprintf(buf, l, "%llus %s",
- (unsigned long long) (d / USEC_PER_SEC), s);
+ d / USEC_PER_SEC, s);
else if (d >= USEC_PER_MSEC)
snprintf(buf, l, "%llums %s",
- (unsigned long long) (d / USEC_PER_MSEC), s);
+ d / USEC_PER_MSEC, s);
else if (d > 0)
- snprintf(buf, l, "%lluus %s",
- (unsigned long long) d, s);
+ snprintf(buf, l, USEC_FMT"us %s",
+ d, s);
else
snprintf(buf, l, "now");
@@ -325,9 +325,9 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
if (j > 0) {
k = snprintf(p, l,
- "%s%llu.%0*llu%s",
+ "%s"USEC_FMT".%0*llu%s",
p > buf ? " " : "",
- (unsigned long long) a,
+ a,
j,
(unsigned long long) b,
table[i].suffix);
@@ -340,9 +340,9 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
/* No? Then let's show it normally */
if (!done) {
k = snprintf(p, l,
- "%s%llu%s",
+ "%s"USEC_FMT"%s",
p > buf ? " " : "",
- (unsigned long long) a,
+ a,
table[i].suffix);
t = b;
@@ -370,10 +370,10 @@ void dual_timestamp_serialize(FILE *f, const char *name, dual_timestamp *t) {
if (!dual_timestamp_is_set(t))
return;
- fprintf(f, "%s=%llu %llu\n",
+ fprintf(f, "%s="USEC_FMT" "USEC_FMT"\n",
name,
- (unsigned long long) t->realtime,
- (unsigned long long) t->monotonic);
+ t->realtime,
+ t->monotonic);
}
void dual_timestamp_deserialize(const char *value, dual_timestamp *t) {
diff --git a/src/shared/util.c b/src/shared/util.c
index d1dc476ab..020c1da7a 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -2499,7 +2499,7 @@ static char *lookup_uid(uid_t uid) {
if (getpwuid_r(uid, &pwbuf, buf, bufsize, &pw) == 0 && pw)
return strdup(pw->pw_name);
- if (asprintf(&name, "%lu", (unsigned long) uid) < 0)
+ if (asprintf(&name, UID_FMT, uid) < 0)
return NULL;
return name;
@@ -2624,7 +2624,7 @@ int get_ctty(pid_t pid, dev_t *_devnr, char **r) {
/* This is an ugly hack */
if (major(devnr) == 136) {
- asprintf(&b, "pts/%lu", (unsigned long) minor(devnr));
+ asprintf(&b, "pts/%u", minor(devnr));
goto finish;
}
@@ -4299,7 +4299,7 @@ char* uid_to_name(uid_t uid) {
if (p)
return strdup(p->pw_name);
- if (asprintf(&r, "%lu", (unsigned long) uid) < 0)
+ if (asprintf(&r, UID_FMT, uid) < 0)
return NULL;
return r;
@@ -4316,7 +4316,7 @@ char* gid_to_name(gid_t gid) {
if (p)
return strdup(p->gr_name);
- if (asprintf(&r, "%lu", (unsigned long) gid) < 0)
+ if (asprintf(&r, GID_FMT, gid) < 0)
return NULL;
return r;
diff --git a/src/shared/util.h b/src/shared/util.h
index 891fcee23..f2ce4f0d6 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -67,6 +67,22 @@
# error Unknown gid_t size
#endif
+#if SIZEOF_TIME_T == 8
+# define PRI_TIME PRIu64
+#elif SIZEOF_GID_T == 4
+# define PRI_TIME PRIu32
+#else
+# error Unknown time_t size
+#endif
+
+#if SIZEOF_RLIM_T == 8
+# define RLIM_FMT "%" PRIu64
+#elif SIZEOF_RLIM_T == 4
+# define RLIM_FMT "%" PRIu32
+#else
+# error Unknown rlim_t size
+#endif
+
#include "macro.h"
#include "time-util.h"