X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Ftime-util.c;h=12f1b193be550aa7b3962891c99ea7fe75943b7e;hb=d896ac2d2fbce41a0b11a0618a685adeaf18b8fe;hp=33d0822f335ace06ff2583a4869f535c7254297a;hpb=75a5f1d837739fc84a7c5af14797490774a10646;p=elogind.git diff --git a/src/shared/time-util.c b/src/shared/time-util.c index 33d0822f3..12f1b193b 100644 --- a/src/shared/time-util.c +++ b/src/shared/time-util.c @@ -296,8 +296,14 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) { assert(buf); assert(l > 0); - if (t == USEC_INFINITY || t <= 0) { - strncpy(p, t == USEC_INFINITY ? "infinity" : "0", l); + if (t == USEC_INFINITY) { + strncpy(p, "infinity", l-1); + p[l-1] = 0; + return p; + } + + if (t <= 0) { + strncpy(p, "0", l-1); p[l-1] = 0; return p; } @@ -392,18 +398,21 @@ void dual_timestamp_serialize(FILE *f, const char *name, dual_timestamp *t) { t->monotonic); } -void dual_timestamp_deserialize(const char *value, dual_timestamp *t) { +int dual_timestamp_deserialize(const char *value, dual_timestamp *t) { unsigned long long a, b; assert(value); assert(t); - if (sscanf(value, "%llu %llu", &a, &b) != 2) - log_debug("Failed to parse finish timestamp value %s", value); - else { - t->realtime = a; - t->monotonic = b; + if (sscanf(value, "%llu %llu", &a, &b) != 2) { + log_debug("Failed to parse finish timestamp value %s.", value); + return -EINVAL; } + + t->realtime = a; + t->monotonic = b; + + return 0; } int parse_timestamp(const char *t, usec_t *usec) { @@ -780,7 +789,7 @@ int parse_nsec(const char *t, nsec_t *nsec) { s = startswith(p, "infinity"); if (s) { s += strspn(s, WHITESPACE); - if (!*s != 0) + if (*s != 0) return -EINVAL; *nsec = NSEC_INFINITY; @@ -959,7 +968,7 @@ bool timezone_is_valid(const char *name) { if (slash) return false; - t = strappenda("/usr/share/zoneinfo/", name); + t = strjoina("/usr/share/zoneinfo/", name); if (stat(t, &st) < 0) return false;