diff options
author | Thomas Haller <thaller@redhat.com> | 2014-02-19 18:22:13 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-02-20 15:28:47 (GMT) |
commit | 3fb0aae0bc37eafe868d28f0f12ee8803d7ad266 (patch) | |
tree | b73a943fc58b17aa0237757d6a5e5c6bb3e6f396 /lib/utils.c | |
parent | b3b8d724164961b7ef4da81eddb5581491f2d025 (diff) | |
download | libnl-3fb0aae0bc37eafe868d28f0f12ee8803d7ad266.zip libnl-3fb0aae0bc37eafe868d28f0f12ee8803d7ad266.tar.gz libnl-3fb0aae0bc37eafe868d28f0f12ee8803d7ad266.tar.bz2 |
utils: fix nl_msec2str() which always returned '0msec' for whole second durations
If the duration was without subsecond part, the function always returned
'0msec', instead of giving the time in days, hours, minutes or seconds.
Regression introduced by commit b3fb89f445108677d405c62865b25aeea209d10a.
Signed-off-by: Thomas Haller <thaller@redhat.com>
Acked-by: Thomas Graf <tgraf@suug.ch>
Diffstat (limited to 'lib/utils.c')
-rw-r--r-- | lib/utils.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/utils.c b/lib/utils.c index c04d83f..1267e87 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -551,6 +551,11 @@ char * nl_msec2str(uint64_t msec, char *buf, size_t len) static const char *units[5] = {"d", "h", "m", "s", "msec"}; char * const buf_orig = buf; + if (msec == 0) { + snprintf(buf, len, "0msec"); + return buf_orig; + } + #define _SPLIT(idx, unit) if ((split[idx] = msec / unit)) msec %= unit _SPLIT(0, 86400000); /* days */ _SPLIT(1, 3600000); /* hours */ @@ -559,11 +564,6 @@ char * nl_msec2str(uint64_t msec, char *buf, size_t len) #undef _SPLIT split[4] = msec; - if (msec == 0) { - snprintf(buf, len, "0msec"); - return buf_orig; - } - for (i = 0; i < ARRAY_SIZE(split) && len; i++) { int l; if (split[i] == 0) |