1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-12 09:17:44 +03:00

time-util: make sure USEC_PER_SEC and friends are actually of type usec_t

This commit is contained in:
Lennart Poettering 2014-05-22 11:44:03 +09:00
parent 558c6490b1
commit 609e002e78
4 changed files with 37 additions and 37 deletions

View File

@ -301,8 +301,8 @@ static int output_short(
}
fprintf(f, "[%5llu.%06llu]",
t / USEC_PER_SEC,
t % USEC_PER_SEC);
(unsigned long long) (t / USEC_PER_SEC),
(unsigned long long) (t % USEC_PER_SEC));
n += 1 + 5 + 1 + 6 + 1;
@ -335,7 +335,7 @@ static int output_short(
r = strftime(buf, sizeof(buf), "%b %d %H:%M:%S", localtime_r(&t, &tm));
if (r > 0) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
".%06llu", x % USEC_PER_SEC);
".%06llu", (unsigned long long) (x % USEC_PER_SEC));
}
break;
default:

View File

@ -183,7 +183,7 @@ char *format_timestamp_us(char *buf, size_t l, usec_t t) {
if (strftime(buf, l, "%a %Y-%m-%d %H:%M:%S", &tm) <= 0)
return NULL;
snprintf(buf + strlen(buf), l - strlen(buf), ".%06llu", t % USEC_PER_SEC);
snprintf(buf + strlen(buf), l - strlen(buf), ".%06llu", (unsigned long long) (t % USEC_PER_SEC));
if (strftime(buf + strlen(buf), l - strlen(buf), " %Z", &tm) <= 0)
return NULL;
@ -208,41 +208,41 @@ 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",
snprintf(buf, l, USEC_FMT " years " USEC_FMT " months %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",
snprintf(buf, l, USEC_FMT " months " USEC_FMT " days %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",
snprintf(buf, l, USEC_FMT " weeks " USEC_FMT " days %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", d / USEC_PER_DAY, s);
snprintf(buf, l, USEC_FMT " days %s", d / USEC_PER_DAY, s);
else if (d >= 25*USEC_PER_HOUR)
snprintf(buf, l, "1 day %lluh %s",
snprintf(buf, l, "1 day " USEC_FMT "h %s",
(d - USEC_PER_DAY) / USEC_PER_HOUR, s);
else if (d >= 6*USEC_PER_HOUR)
snprintf(buf, l, "%lluh %s",
snprintf(buf, l, USEC_FMT "h %s",
d / USEC_PER_HOUR, s);
else if (d >= USEC_PER_HOUR)
snprintf(buf, l, "%lluh %llumin %s",
snprintf(buf, l, USEC_FMT "h " USEC_FMT "min %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",
snprintf(buf, l, USEC_FMT "min %s",
d / USEC_PER_MINUTE, s);
else if (d >= USEC_PER_MINUTE)
snprintf(buf, l, "%llumin %llus %s",
snprintf(buf, l, USEC_FMT "min " USEC_FMT "s %s",
d / USEC_PER_MINUTE,
(d % USEC_PER_MINUTE) / USEC_PER_SEC, s);
else if (d >= USEC_PER_SEC)
snprintf(buf, l, "%llus %s",
snprintf(buf, l, USEC_FMT "s %s",
d / USEC_PER_SEC, s);
else if (d >= USEC_PER_MSEC)
snprintf(buf, l, "%llums %s",
snprintf(buf, l, USEC_FMT "ms %s",
d / USEC_PER_MSEC, s);
else if (d > 0)
snprintf(buf, l, USEC_FMT"us %s",

View File

@ -37,25 +37,25 @@ typedef struct dual_timestamp {
usec_t monotonic;
} dual_timestamp;
#define MSEC_PER_SEC 1000ULL
#define USEC_PER_SEC 1000000ULL
#define USEC_PER_MSEC 1000ULL
#define NSEC_PER_SEC 1000000000ULL
#define NSEC_PER_MSEC 1000000ULL
#define NSEC_PER_USEC 1000ULL
#define MSEC_PER_SEC ((usec_t) 1000ULL)
#define USEC_PER_SEC ((usec_t) 1000000ULL)
#define USEC_PER_MSEC ((usec_t) 1000ULL)
#define NSEC_PER_SEC ((usec_t) 1000000000ULL)
#define NSEC_PER_MSEC ((usec_t) 1000000ULL)
#define NSEC_PER_USEC ((usec_t) 1000ULL)
#define USEC_PER_MINUTE (60ULL*USEC_PER_SEC)
#define NSEC_PER_MINUTE (60ULL*NSEC_PER_SEC)
#define USEC_PER_HOUR (60ULL*USEC_PER_MINUTE)
#define NSEC_PER_HOUR (60ULL*NSEC_PER_MINUTE)
#define USEC_PER_DAY (24ULL*USEC_PER_HOUR)
#define NSEC_PER_DAY (24ULL*NSEC_PER_HOUR)
#define USEC_PER_WEEK (7ULL*USEC_PER_DAY)
#define NSEC_PER_WEEK (7ULL*NSEC_PER_DAY)
#define USEC_PER_MONTH (2629800ULL*USEC_PER_SEC)
#define NSEC_PER_MONTH (2629800ULL*NSEC_PER_SEC)
#define USEC_PER_YEAR (31557600ULL*USEC_PER_SEC)
#define NSEC_PER_YEAR (31557600ULL*NSEC_PER_SEC)
#define USEC_PER_MINUTE ((usec_t) (60ULL*USEC_PER_SEC))
#define NSEC_PER_MINUTE ((usec_t) (60ULL*NSEC_PER_SEC))
#define USEC_PER_HOUR ((usec_t) (60ULL*USEC_PER_MINUTE))
#define NSEC_PER_HOUR ((usec_t) (60ULL*NSEC_PER_MINUTE))
#define USEC_PER_DAY ((usec_t) (24ULL*USEC_PER_HOUR))
#define NSEC_PER_DAY ((usec_t) (24ULL*NSEC_PER_HOUR))
#define USEC_PER_WEEK ((usec_t) (7ULL*USEC_PER_DAY))
#define NSEC_PER_WEEK ((usec_t) (7ULL*NSEC_PER_DAY))
#define USEC_PER_MONTH ((usec_t) (2629800ULL*USEC_PER_SEC))
#define NSEC_PER_MONTH ((usec_t) (2629800ULL*NSEC_PER_SEC))
#define USEC_PER_YEAR ((usec_t) (31557600ULL*USEC_PER_SEC))
#define NSEC_PER_YEAR ((usec_t) (31557600ULL*NSEC_PER_SEC))
#define FORMAT_TIMESTAMP_MAX ((4*4+1)+11+9+4+1) /* weekdays can be unicode */
#define FORMAT_TIMESTAMP_RELATIVE_MAX 256

View File

@ -455,12 +455,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.%03lli\n"
" time now : %li.%03llu\n"
" constant : %li\n"
" offset : %+.3f sec\n"
" freq offset : %+li (%i ppm)\n",
tmx.status, tmx.status & STA_UNSYNC ? "" : "sync",
tmx.time.tv_sec, tmx.time.tv_usec / NSEC_PER_MSEC,
tmx.time.tv_sec, (unsigned long long) (tmx.time.tv_usec / NSEC_PER_MSEC),
tmx.constant,
(double)tmx.offset / NSEC_PER_SEC,
tmx.freq, m->drift_ppm);
@ -727,7 +727,7 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re
" delay : %+.3f sec\n"
" packet count : %"PRIu64"\n"
" jitter : %.3f%s\n"
" poll interval: %llu\n",
" poll interval: " USEC_FMT "\n",
NTP_FIELD_LEAP(ntpmsg.field),
NTP_FIELD_VERSION(ntpmsg.field),
NTP_FIELD_MODE(ntpmsg.field),
@ -749,7 +749,7 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re
log_error("Failed to call clock_adjtime(): %m");
}
log_info("interval/delta/delay/jitter/drift %llus/%+.3fs/%.3fs/%.3fs/%+ippm%s",
log_info("interval/delta/delay/jitter/drift " USEC_FMT "s/%+.3fs/%.3fs/%.3fs/%+ippm%s",
m->poll_interval_usec / USEC_PER_SEC, offset, delay, m->samples_jitter, m->drift_ppm,
spike ? " (ignored)" : "");