]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/monotime.h
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / monotime.h
index 0fd49404311b8e51f35f92f8cd53bab926095423..00b9400462e2f6c8b6e49c29ae6e1099fd80854c 100644 (file)
 
 #ifndef TIMESPEC_TO_TIMEVAL
 /* should be in sys/time.h on BSD & Linux libcs */
-#define TIMESPEC_TO_TIMEVAL(tv, ts) do {       \
-       (tv)->tv_sec = (ts)->tv_sec;            \
-       (tv)->tv_usec = (ts)->tv_nsec / 1000;   \
+#define TIMESPEC_TO_TIMEVAL(tv, ts)                                            \
+       do {                                                                   \
+               (tv)->tv_sec = (ts)->tv_sec;                                   \
+               (tv)->tv_usec = (ts)->tv_nsec / 1000;                          \
        } while (0)
 #endif
 #ifndef TIMEVAL_TO_TIMESPEC
 /* should be in sys/time.h on BSD & Linux libcs */
-#define TIMEVAL_TO_TIMESPEC(tv, ts) do {       \
-       (ts)->tv_sec = (tv)->tv_sec;            \
-       (ts)->tv_nsec = (tv)->tv_usec * 1000;   \
+#define TIMEVAL_TO_TIMESPEC(tv, ts)                                            \
+       do {                                                                   \
+               (ts)->tv_sec = (tv)->tv_sec;                                   \
+               (ts)->tv_nsec = (tv)->tv_usec * 1000;                          \
        } while (0)
 #endif
 
@@ -47,6 +49,10 @@ static inline time_t monotime(struct timeval *tvo)
        return ts.tv_sec;
 }
 
+#define ONE_DAY_SECOND 60*60*24
+#define ONE_WEEK_SECOND ONE_DAY_SECOND*7
+#define ONE_YEAR_SECOND ONE_DAY_SECOND*365
+
 /* the following two return microseconds, not time_t!
  *
  * also, they're negative forms of each other, but having both makes the
@@ -74,4 +80,15 @@ static inline int64_t monotime_until(const struct timeval *ref,
        return (int64_t)tv.tv_sec * 1000000LL + tv.tv_usec;
 }
 
+static inline char *time_to_string(time_t ts)
+{
+       struct timeval tv;
+       time_t tbuf;
+
+       monotime(&tv);
+       tbuf = time(NULL) - (tv.tv_sec - ts);
+
+       return ctime(&tbuf);
+}
+
 #endif /* _FRR_MONOTIME_H */