From e8aa5100a75924ac7e01adb991e21dcb4e00e2ff Mon Sep 17 00:00:00 2001 From: Giovanni <561184+wargio@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:13:17 +0800 Subject: [PATCH] struct timezone is obsolete/deprecated (#4672) https://man7.org/linux/man-pages/man2/gettimeofday.2.html --- librz/include/rz_util/rz_time.h | 10 +--------- librz/util/time.c | 20 +++++--------------- test/unit/test_analysis_block.c | 2 +- test/unit/test_intervaltree.c | 2 +- 4 files changed, 8 insertions(+), 26 deletions(-) diff --git a/librz/include/rz_util/rz_time.h b/librz/include/rz_util/rz_time.h index b531e7ce8a..6cf57fae67 100644 --- a/librz/include/rz_util/rz_time.h +++ b/librz/include/rz_util/rz_time.h @@ -18,17 +18,9 @@ extern "C" { #ifdef _MSC_VER struct timeval; - -struct rz_timezone { - int tz_minuteswest; /* minutes W of Greenwich */ - int tz_dsttime; /* type of dst correction */ -}; -#else -#include -#define rz_timezone timezone #endif -RZ_API int rz_time_gettimeofday(struct timeval *p, struct rz_timezone *tz); +RZ_API int rz_time_gettimeofday(struct timeval *p); // wall clock time in microseconds RZ_API ut64 rz_time_now(void); diff --git a/librz/util/time.c b/librz/util/time.c index 6ed4c7d58f..9433fb85c0 100644 --- a/librz/util/time.c +++ b/librz/util/time.c @@ -23,13 +23,11 @@ * information. * * \param p Pointer to a \p timeval 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 rz_timezone *tz) { +RZ_API int rz_time_gettimeofday(struct timeval *p) { // ULARGE_INTEGER ul; // As specified on MSDN. ut64 ul = 0; - static int tzflag = 0; FILETIME ft = { 0 }; if (p) { // Returns a 64-bit value representing the number of @@ -54,14 +52,6 @@ RZ_API int rz_time_gettimeofday(struct timeval *p, struct rz_timezone *tz) { p->tv_sec = (long)(ul / 1000000LL); p->tv_usec = (long)(ul % 1000000LL); } - if (tz) { - if (!tzflag) { - _tzset(); - tzflag++; - } - tz->tz_minuteswest = _timezone / 60; - tz->tz_dsttime = _daylight; - } return 0; } #else @@ -72,11 +62,11 @@ RZ_API int rz_time_gettimeofday(struct timeval *p, struct rz_timezone *tz) { * information. * * \param p Pointer to a \p timeval 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 rz_timezone *tz) { - return gettimeofday(p, tz); +RZ_API int rz_time_gettimeofday(struct timeval *p) { + // struct timezone is obsolete and shall not be used. + return gettimeofday(p, NULL); } #endif @@ -93,7 +83,7 @@ RZ_API int rz_time_gettimeofday(struct timeval *p, struct rz_timezone *tz) { RZ_API ut64 rz_time_now(void) { ut64 ret; struct timeval now; - rz_time_gettimeofday(&now, NULL); + rz_time_gettimeofday(&now); ret = now.tv_sec * RZ_USEC_PER_SEC; ret += now.tv_usec; return ret; diff --git a/test/unit/test_analysis_block.c b/test/unit/test_analysis_block.c index a08609d157..b8b28171c9 100644 --- a/test/unit/test_analysis_block.c +++ b/test/unit/test_analysis_block.c @@ -998,7 +998,7 @@ int all_tests() { int main(int argc, char **argv) { struct timeval tv; - rz_time_gettimeofday(&tv, NULL); + rz_time_gettimeofday(&tv); unsigned int seed = argc > 1 ? strtoul(argv[1], NULL, 0) : tv.tv_sec + tv.tv_usec; printf("seed for test_analysis_block: %u\n", seed); return all_tests(); diff --git a/test/unit/test_intervaltree.c b/test/unit/test_intervaltree.c index f4d5763765..6ac0bc8b84 100644 --- a/test/unit/test_intervaltree.c +++ b/test/unit/test_intervaltree.c @@ -341,7 +341,7 @@ int all_tests() { int main(int argc, char **argv) { struct timeval tv; - rz_time_gettimeofday(&tv, NULL); + rz_time_gettimeofday(&tv); unsigned int seed = argc > 1 ? strtoul(argv[1], NULL, 0) : tv.tv_sec + tv.tv_usec; printf("seed for test_intervaltree: %u\n", seed); srand(seed);