From f97b34a629dc4e811b9cf3d5f8cf9032f595ee2b Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Mon, 7 Nov 2016 10:14:59 -0500 Subject: Rename formats-util.h to format-util.h We don't have plural in the name of any other -util files and this inconsistency trips me up every time I try to type this file name from memory. "formats-util" is even hard to pronounce. --- src/shared/logs-show.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/shared/logs-show.c') diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 5ad5ade31e..99b76714e0 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -33,7 +33,7 @@ #include "alloc-util.h" #include "fd-util.h" -#include "formats-util.h" +#include "format-util.h" #include "hashmap.h" #include "hostname-util.h" #include "io-util.h" -- cgit v1.2.3-54-g00ecf From 70887c5f2956f2e8c4f58563535049149db98fc2 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Mon, 7 Nov 2016 11:49:25 -0500 Subject: tree-wide: add PRI_[NU]SEC, and use time format strings more --- src/basic/time-util.c | 8 ++++---- src/basic/time-util.h | 6 ++++-- src/gpt-auto-generator/gpt-auto-generator.c | 4 ++-- src/shared/logs-show.c | 9 +++------ src/timesync/timesyncd-manager.c | 4 ++-- 5 files changed, 15 insertions(+), 16 deletions(-) (limited to 'src/shared/logs-show.c') diff --git a/src/basic/time-util.c b/src/basic/time-util.c index fedff1362c..cbdfd55ada 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -309,7 +309,7 @@ static char *format_timestamp_internal( if (n + 8 > l) return NULL; /* Microseconds part doesn't fit. */ - sprintf(buf + n, ".%06llu", (unsigned long long) (t % USEC_PER_SEC)); + sprintf(buf + n, ".%06"PRI_USEC, t % USEC_PER_SEC); } /* Append the timezone */ @@ -499,11 +499,11 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) { if (j > 0) { k = snprintf(p, l, - "%s"USEC_FMT".%0*llu%s", + "%s"USEC_FMT".%0*"PRI_USEC"%s", p > buf ? " " : "", a, j, - (unsigned long long) b, + b, table[i].suffix); t = 0; @@ -1320,7 +1320,7 @@ unsigned long usec_to_jiffies(usec_t u) { r = sysconf(_SC_CLK_TCK); assert(r > 0); - hz = (unsigned long) r; + hz = r; } return DIV_ROUND_UP(u , USEC_PER_SEC / hz); diff --git a/src/basic/time-util.h b/src/basic/time-util.h index 558b0b5b7f..f67a4474ed 100644 --- a/src/basic/time-util.h +++ b/src/basic/time-util.h @@ -29,8 +29,10 @@ typedef uint64_t usec_t; typedef uint64_t nsec_t; -#define NSEC_FMT "%" PRIu64 -#define USEC_FMT "%" PRIu64 +#define PRI_NSEC PRIu64 +#define PRI_USEC PRIu64 +#define NSEC_FMT "%" PRI_NSEC +#define USEC_FMT "%" PRI_USEC #include "macro.h" diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index e64d5bb231..52cde493e5 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -429,10 +429,10 @@ static int add_automount( "Documentation=man:systemd-gpt-auto-generator(8)\n" "[Automount]\n" "Where=%s\n" - "TimeoutIdleSec=%lld\n", + "TimeoutIdleSec="USEC_FMT"\n", description, where, - (unsigned long long)timeout / USEC_PER_SEC); + timeout / USEC_PER_SEC); r = fflush_and_check(f); if (r < 0) diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 99b76714e0..75ea25c8ac 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -223,10 +223,7 @@ static int output_timestamp_monotonic(FILE *f, sd_journal *j, const char *monoto if (r < 0) return log_error_errno(r, "Failed to get monotonic timestamp: %m"); - fprintf(f, "[%5llu.%06llu]", - (unsigned long long) (t / USEC_PER_SEC), - (unsigned long long) (t % USEC_PER_SEC)); - + fprintf(f, "[%5"PRI_USEC".%06"PRI_USEC"]", t / USEC_PER_SEC, t % USEC_PER_SEC); return 1 + 5 + 1 + 6 + 1; } @@ -268,7 +265,7 @@ static int output_timestamp_realtime(FILE *f, sd_journal *j, OutputMode mode, Ou switch (mode) { case OUTPUT_SHORT_UNIX: - xsprintf(buf, "%10llu.%06llu", (unsigned long long) t, (unsigned long long) (x % USEC_PER_SEC)); + xsprintf(buf, "%10"PRI_TIME".%06"PRIu64, t, x % USEC_PER_SEC); break; case OUTPUT_SHORT_ISO: @@ -292,7 +289,7 @@ static int output_timestamp_realtime(FILE *f, sd_journal *j, OutputMode mode, Ou assert(sizeof(buf) > strlen(buf)); k = sizeof(buf) - strlen(buf); - r = snprintf(buf + strlen(buf), k, ".%06llu", (unsigned long long) (x % USEC_PER_SEC)); + r = snprintf(buf + strlen(buf), k, ".%06"PRIu64, x % USEC_PER_SEC); if (r <= 0 || (size_t) r >= k) { /* too long? */ log_error("Failed to format precise time"); return -EINVAL; diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c index d5e16db3a0..a455652a27 100644 --- a/src/timesync/timesyncd-manager.c +++ b/src/timesync/timesyncd-manager.c @@ -376,12 +376,12 @@ static int manager_adjust_clock(Manager *m, double offset, int leap_sec) { m->drift_ppm = tmx.freq / 65536; log_debug(" status : %04i %s\n" - " time now : %li.%03llu\n" + " time now : %li.%03"PRI_USEC"\n" " constant : %li\n" " offset : %+.3f sec\n" " freq offset : %+li (%i ppm)\n", tmx.status, tmx.status & STA_UNSYNC ? "unsync" : "sync", - tmx.time.tv_sec, (unsigned long long) (tmx.time.tv_usec / NSEC_PER_MSEC), + tmx.time.tv_sec, tmx.time.tv_usec / NSEC_PER_MSEC, tmx.constant, (double)tmx.offset / NSEC_PER_SEC, tmx.freq, m->drift_ppm); -- cgit v1.2.3-54-g00ecf