1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-03-10 00:58:20 +03:00

tree-wide: add PRI_[NU]SEC, and use time format strings more

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2016-11-07 11:49:25 -05:00
parent 5206a724a0
commit 70887c5f29
5 changed files with 15 additions and 16 deletions

View File

@ -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);

View File

@ -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"

View File

@ -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)

View File

@ -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;

View File

@ -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);