From 215e49253d3a35e1aae340b7ae8465018254ae87 Mon Sep 17 00:00:00 2001 From: billow Date: Mon, 8 Aug 2022 23:57:30 +0800 Subject: [PATCH] Fix windows and cpp compatibility (#2887) --- librz/include/meson.build | 1 + librz/include/rz_util/rz_time.h | 14 ++++++++++++-- librz/util/time.c | 8 ++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/librz/include/meson.build b/librz/include/meson.build index 0a60144999..069afceae1 100644 --- a/librz/include/meson.build +++ b/librz/include/meson.build @@ -51,6 +51,7 @@ include_files = [ 'rz_types_overflow.h', 'rz_util.h', 'rz_vector.h', + 'rz_windows.h', 'rz_windows_heap.h', ] install_headers(include_files, install_dir: rizin_incdir) diff --git a/librz/include/rz_util/rz_time.h b/librz/include/rz_util/rz_time.h index 685b02db41..43303f4bc5 100644 --- a/librz/include/rz_util/rz_time.h +++ b/librz/include/rz_util/rz_time.h @@ -12,16 +12,22 @@ #define ASCTIME_BUF_MINLEN 26 +#ifdef __cplusplus +extern "C" { +#endif + #ifdef _MSC_VER struct timeval; -struct timezone { +struct rz_timezone { int tz_minuteswest; /* minutes W of Greenwich */ int tz_dsttime; /* type of dst correction */ }; +#else +#define rz_timezone timezone #endif -RZ_API int rz_time_gettimeofday(struct timeval *p, struct timezone *tz); +RZ_API int rz_time_gettimeofday(struct timeval *p, struct rz_timezone *tz); // wall clock time in microseconds RZ_API ut64 rz_time_now(void); @@ -58,4 +64,8 @@ RZ_API struct tm *rz_gmtime_r(RZ_NONNULL const time_t *time, RZ_NONNULL struct t } while (0) #endif +#ifdef __cplusplus +} +#endif + #endif diff --git a/librz/util/time.c b/librz/util/time.c index d4d494c8d7..a7f3c478b6 100644 --- a/librz/util/time.c +++ b/librz/util/time.c @@ -23,10 +23,10 @@ * information. * * \param p Pointer to a \p timeval structure that will be filled by this function - * \param tz Pointer to a \p timezone structure that will be filled by this function + * \param tz Pointer to a \p rz_timezone structure that will be filled by this function * \return 0 if the function succeeds, -1 on error */ -RZ_API int rz_time_gettimeofday(struct timeval *p, struct timezone *tz) { +RZ_API int rz_time_gettimeofday(struct timeval *p, struct rz_timezone *tz) { // ULARGE_INTEGER ul; // As specified on MSDN. ut64 ul = 0; static int tzflag = 0; @@ -72,10 +72,10 @@ RZ_API int rz_time_gettimeofday(struct timeval *p, struct timezone *tz) { * information. * * \param p Pointer to a \p timeval structure that will be filled by this function - * \param tz Pointer to a \p timezone structure that will be filled by this function + * \param tz Pointer to a \p rz_timezone structure that will be filled by this function * \return 0 if the function succeeds, -1 on error */ -RZ_API int rz_time_gettimeofday(struct timeval *p, struct timezone *tz) { +RZ_API int rz_time_gettimeofday(struct timeval *p, struct rz_timezone *tz) { return gettimeofday(p, tz); } #endif