Go to the documentation of this file.
24 #ifndef SURICATA_UTIL_TIME_H
25 #define SURICATA_UTIL_TIME_H
45 #define SCTIME_INIT(t) \
51 #define SCTIME_INITIALIZER \
54 .secs = 0, .usecs = 0 \
56 #define SCTIME_USECS(t) ((t).usecs)
57 #define SCTIME_SECS(t) ((t).secs)
58 #define SCTIME_MSECS(t) (SCTIME_SECS(t) * 1000 + SCTIME_USECS(t) / 1000)
59 #define SCTIME_ADD_USECS(ts, us) \
62 .secs = (ts).secs + ((ts).usecs + (us)) / 1000000, .usecs = ((ts).usecs + (us)) % 1000000 \
64 #define SCTIME_ADD_SECS(ts, s) \
67 .secs = (ts).secs + (s), .usecs = (ts).usecs \
69 #define SCTIME_FROM_SECS(s) \
72 .secs = (s), .usecs = 0 \
74 #define SCTIME_FROM_USECS(us) \
77 .secs = 0, .usecs = (us) \
79 #define SCTIME_FROM_TIMEVAL(tv) \
82 .secs = (tv)->tv_sec, .usecs = (tv)->tv_usec \
85 #define SCTIME_FROM_TIMEVAL_UNTRUSTED(tv) \
88 .secs = ((tv)->tv_sec > 0) ? (tv)->tv_sec : 0, \
89 .usecs = ((tv)->tv_usec > 0) ? (tv)->tv_usec : 0 \
91 #define SCTIME_FROM_TIMESPEC(ts) \
94 .secs = (ts)->tv_sec, .usecs = (ts)->tv_nsec / 1000 \
97 #define SCTIME_TO_TIMEVAL(tv, t) \
98 (tv)->tv_sec = SCTIME_SECS((t)); \
99 (tv)->tv_usec = SCTIME_USECS((t));
100 #define SCTIME_CMP(a, b, CMP) \
101 ((SCTIME_SECS(a) == SCTIME_SECS(b)) ? (SCTIME_USECS(a) CMP SCTIME_USECS(b)) \
102 : (SCTIME_SECS(a) CMP SCTIME_SECS(b)))
103 #define SCTIME_CMP_GTE(a, b) SCTIME_CMP((a), (b), >=)
104 #define SCTIME_CMP_GT(a, b) SCTIME_CMP((a), (b), >)
105 #define SCTIME_CMP_LT(a, b) SCTIME_CMP((a), (b), <)
106 #define SCTIME_CMP_LTE(a, b) SCTIME_CMP((a), (b), <=)
107 #define SCTIME_CMP_NEQ(a, b) SCTIME_CMP((a), (b), !=)
108 #define SCTIME_CMP_EQ(a, b) SCTIME_CMP((a), (b), ==)
110 static inline SCTime_t SCTimeGetTime(
void)
113 gettimeofday(&
tv, NULL);
124 #define FROM_TIMEVAL(timev) { .tv_sec = (timev).tv_sec, .tv_nsec = (timev).tv_usec * 1000 }
127 #define timeradd(a, b, r) \
129 (r)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
130 (r)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
131 if ((r)->tv_usec >= 1000000) { \
133 (r)->tv_usec -= 1000000; \
149 struct tm *
SCLocalTime(time_t timep,
struct tm *result);
156 int num_patterns,
struct tm *time);
void TimeSetToCurrentTime(void)
set the time to "gettimeofday" meant for testing
void CreateFormattedTimeString(const struct tm *t, const char *fmt, char *str, size_t size)
void TimeModeSetLive(void)
time_t SCMkTimeUtc(struct tm *tp)
Convert broken-down time to seconds since Unix epoch.
void CreateUtcIsoTimeString(const SCTime_t ts, char *str, size_t size)
int SCTimeToStringPattern(time_t epoch, const char *pattern, char *str, size_t size)
Convert epoch time to string pattern.
#define SCTIME_FROM_TIMEVAL(tv)
bool TimeModeIsLive(void)
uint64_t SCTimespecAsEpochMillis(const struct timespec *ts)
bool TimeModeIsReady(void)
void TimeModeSetOffline(void)
void CreateIsoTimeString(const SCTime_t ts, char *str, size_t size)
uint64_t TimeDifferenceMicros(struct timeval t0, struct timeval t1)
uint64_t SCParseTimeSizeString(const char *str)
Parse string containing time size (1m, 1h, etc).
void TimeSetByThread(const int thread_id, SCTime_t tv)
uint64_t SCGetSecondsUntil(const char *str, time_t epoch)
Get seconds until a time unit changes.
void CreateTimeString(const SCTime_t ts, char *str, size_t size)
struct tm * SCLocalTime(time_t timep, struct tm *result)
void TimeSetIncrementTime(uint32_t)
increment the time in the engine
int SCStringPatternToTime(char *string, const char **patterns, int num_patterns, struct tm *time)
Parse a date string based on specified patterns.