mirror of
https://gitee.com/openharmony/third_party_libnl
synced 2024-11-27 20:20:30 +00:00
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 b3fb89f445
.
Signed-off-by: Thomas Haller <thaller@redhat.com>
Acked-by: Thomas Graf <tgraf@suug.ch>
This commit is contained in:
parent
b3b8d72416
commit
3fb0aae0bc
10
lib/utils.c
10
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)
|
||||
|
Loading…
Reference in New Issue
Block a user