dcerpc-nt: add UNION_ALIGN_TO... helpers
[wireshark-sm.git] / wsutil / time_util.h
blob6c2f52bffe3f85f39ca4b7804118245ee6569336
1 /** @file
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
10 #ifndef __TIME_UTIL_H__
11 #define __TIME_UTIL_H__
13 #include <wireshark.h>
14 #include <time.h>
16 #ifdef __cplusplus
17 extern "C" {
18 #endif /* __cplusplus */
20 /** Converts a broken down date representation, relative to UTC,
21 * to a timestamp
23 WS_DLL_PUBLIC
24 time_t mktime_utc(struct tm *tm);
26 /** Validate the values in a time_t.
27 * Currently checks tm_year, tm_mon, tm_mday, tm_hour, tm_min, and tm_sec;
28 * disregards tm_wday, tm_yday, and tm_isdst.
30 * @param tm The struct tm to validate.
32 WS_DLL_PUBLIC
33 bool tm_is_valid(struct tm *tm);
35 /** Fetch the process CPU time.
37 * Fetch the current process user and system CPU times, convert them to
38 * seconds, and store them in the provided parameters.
40 * @param user_time Seconds spent in user mode.
41 * @param sys_time Seconds spent in system (kernel) mode.
43 WS_DLL_PUBLIC
44 void get_resource_usage(double *user_time, double *sys_time);
46 /** Print the process CPU time followed by a log message.
48 * Print the current process user and system CPU times along with the times
49 * elapsed since the times were last reset.
51 * @param reset_delta Reset the delta times. This will typically be true when
52 * logging the first measurement and false thereafter.
53 * @param format Printf-style format string. Passed to g_string_vprintf.
54 * @param ... Parameters for the format string.
56 WS_DLL_PUBLIC
57 void log_resource_usage(bool reset_delta, const char *format, ...);
59 /**
60 * Fetch the number of microseconds since midnight (0 hour), January 1, 1970.
62 WS_DLL_PUBLIC
63 uint64_t create_timestamp(void);
65 WS_DLL_PUBLIC
66 void ws_tzset(void);
68 WS_DLL_PUBLIC
69 struct timespec *ws_clock_get_realtime(struct timespec *ts);
71 WS_DLL_PUBLIC
72 struct tm *ws_localtime_r(const time_t *timep, struct tm *result);
74 WS_DLL_PUBLIC
75 struct tm *ws_gmtime_r(const time_t *timep, struct tm *result);
77 #ifdef __cplusplus
79 #endif /* __cplusplus */
81 #endif /* __TIME_UTIL_H__ */