Rizin
unix-like reverse engineering framework and cli tools
rz_time.h
Go to the documentation of this file.
1 #ifndef RZ_TIME_H
2 #define RZ_TIME_H
3 
4 #include <rz_types.h>
5 #include <time.h>
6 
7 #define RZ_NSEC_PER_SEC 1000000000ULL
8 #define RZ_NSEC_PER_MSEC 1000000ULL
9 #define RZ_USEC_PER_SEC 1000000ULL
10 #define RZ_NSEC_PER_USEC 1000ULL
11 #define RZ_USEC_PER_MSEC 1000ULL
12 
13 #define ASCTIME_BUF_MINLEN 26
14 
15 #ifdef _MSC_VER
16 struct timeval;
17 
18 struct timezone {
19  int tz_minuteswest; /* minutes W of Greenwich */
20  int tz_dsttime; /* type of dst correction */
21 };
22 #endif
23 
24 RZ_API int rz_time_gettimeofday(struct timeval *p, struct timezone *tz);
25 
26 // wall clock time in microseconds
27 RZ_API ut64 rz_time_now(void);
28 
29 // monotonic time in microseconds
31 
32 RZ_API RZ_OWN char *rz_time_stamp_to_str(ut32 timestamp);
34 RZ_API bool rz_time_stamp_is_dos_format(const ut32 certainPosixTimeStamp, const ut32 possiblePosixOrDosTimeStamp);
38 #define rz_time_date_unix_to_string rz_time_stamp_to_str
40 
41 // Thread-safe cross platform wrappers
42 RZ_API char *rz_asctime_r(RZ_NONNULL const struct tm *tm, RZ_NONNULL char *buf);
43 RZ_API char *rz_ctime_r(RZ_NONNULL const time_t *timer, RZ_NONNULL char *buf);
44 RZ_API struct tm *rz_localtime_r(RZ_NONNULL const time_t *time, RZ_NONNULL struct tm *res);
45 RZ_API struct tm *rz_gmtime_r(RZ_NONNULL const time_t *time, RZ_NONNULL struct tm *res);
46 
47 #define RZ_TIME_PROFILE_ENABLED 0
48 
49 #if RZ_TIME_PROFILE_ENABLED
50 #define RZ_TIME_PROFILE_BEGIN ut64 __now__ = rz_time_now_mono()
51 #define RZ_TIME_PROFILE_END eprintf("%s %" PFMT64d "\n", __FUNCTION__, rz_time_now_mono() - __now__)
52 #else
53 #define RZ_TIME_PROFILE_BEGIN \
54  do { \
55  } while (0)
56 #define RZ_TIME_PROFILE_END \
57  do { \
58  } while (0)
59 #endif
60 
61 #endif
#define RZ_API
uint32_t ut32
voidpf void * buf
Definition: ioapi.h:138
void * p
Definition: libc.cpp:67
static static fork const void static count static fd const char const char static newpath char char char static envp time
Definition: sflib.h:42
RZ_API RZ_OWN char * rz_time_date_dos_to_string(ut32 timestamp)
Converts a dos date (ut32) and returns the timestamp in string format.
Definition: time.c:239
RZ_API RZ_OWN char * rz_time_date_now_to_string(void)
Returns the timestamp in string format of the current time (now)
Definition: time.c:278
RZ_API struct tm * rz_localtime_r(RZ_NONNULL const time_t *time, RZ_NONNULL struct tm *res)
Definition: time.c:284
RZ_API struct tm * rz_gmtime_r(RZ_NONNULL const time_t *time, RZ_NONNULL struct tm *res)
Definition: time.c:294
RZ_API bool rz_time_stamp_is_dos_format(const ut32 certainPosixTimeStamp, const ut32 possiblePosixOrDosTimeStamp)
Verifies that the timestamp is in dos format.
Definition: time.c:225
RZ_API char * rz_asctime_r(RZ_NONNULL const struct tm *tm, RZ_NONNULL char *buf)
Definition: time.c:304
RZ_API RZ_OWN char * rz_time_date_w32_to_string(ut64 timestamp)
Converts a Win32 date (ut64) and returns the timestamp in string format.
Definition: time.c:261
RZ_API ut64 rz_time_now(void)
Returns the current time in microseconds.
Definition: time.c:88
RZ_API int rz_time_gettimeofday(struct timeval *p, struct timezone *tz)
Get the system current time and the current time zone.
Definition: time.c:78
RZ_API RZ_OWN char * rz_time_date_hfs_to_string(ut32 timestamp)
Converts a Mac HFS+ date (ut32) and returns the timestamp in string format.
Definition: time.c:250
RZ_API RZ_OWN char * rz_time_stamp_to_str(ut32 timestamp)
Converts an unix epoch timestamp to string.
Definition: time.c:143
RZ_API char * rz_ctime_r(RZ_NONNULL const time_t *timer, RZ_NONNULL char *buf)
Definition: time.c:314
RZ_API ut64 rz_time_now_mono(void)
Returns the current time in microseconds, using the monotonic clock.
Definition: time.c:102
RZ_API ut32 rz_time_dos_time_stamp_to_posix(ut32 timestamp)
Converts dos timestamp to posix timestamp.
Definition: time.c:190
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_NONNULL
Definition: rz_types.h:64
int time_t
Definition: sftypes.h:66
ut64(WINAPI *w32_GetEnabledXStateFeatures)()