]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
timeutils: add an inline funciton, is_timespecset()
authorMasatake YAMATO <yamato@redhat.com>
Sat, 10 Jun 2023 15:31:46 +0000 (00:31 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Sat, 10 Jun 2023 20:11:08 +0000 (05:11 +0900)
Close #2300.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
include/timeutils.h
misc-utils/lsfd-unkn.c

index eb0e534510ba5b8f1e73594da1d6d420cd48b4e8..9c99ef5a75269188964780cdb5026760b9c8e361 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <inttypes.h>
 #include <sys/time.h>
+#include <stdbool.h>
 
 typedef uint64_t usec_t;
 typedef uint64_t nsec_t;
@@ -111,4 +112,9 @@ static inline struct timeval usec_to_timeval(usec_t t)
        return r;
 }
 
+static inline bool is_timespecset(const struct timespec *t)
+{
+       return t->tv_sec || t->tv_nsec;
+}
+
 #endif /* UTIL_LINUX_TIME_UTIL_H */
index 9af0816f11697634c134e1d9be65424be128a992..c42beb71c105fc970a2ea944f5968a88b5f9e3a7 100644 (file)
@@ -22,6 +22,7 @@
 #include "xalloc.h"
 #include "nls.h"
 #include "libsmartcols.h"
+#include "timeutils.h"
 
 #include "lsfd.h"
 
@@ -616,11 +617,6 @@ static int anon_timerfd_handle_fdinfo(struct unkn *unkn, const char *key, const
        }
 }
 
-static bool is_zero_timespec(const struct timespec *t)
-{
-       return !t->tv_sec && !t->tv_nsec;
-}
-
 static const char *anon_timerfd_decode_clockid(int clockid)
 {
        switch (clockid) {
@@ -663,12 +659,12 @@ static char *anon_timerfd_get_name(struct unkn *unkn)
        clockid_name = anon_timerfd_decode_clockid(data->clockid);
 
        exp = &data->itimerspec.it_value;
-       if (!is_zero_timespec(exp))
+       if (is_timespecset(exp))
                anon_timerfd_render_timespec_string(exp_buf, sizeof(exp_buf),
                                                    " remaining=", exp);
 
        ival = &data->itimerspec.it_interval;
-       if (!is_zero_timespec(ival))
+       if (is_timespecset(ival))
                anon_timerfd_render_timespec_string(ival_buf, sizeof(ival_buf),
                                                    " interval=", ival);