From 16caa44298f13e119e0f282de070d0dbbd2c80ac Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 5 Sep 2023 21:37:01 +0000 Subject: [PATCH] Use localtime_r() on Windows too. I don't know why I didn't clean these up when I learned about this trick. Test: treehugger Change-Id: I16e7d92fd79c2dfc006612442bbb924b35a5f213 --- tools/zipalign/ZipEntry.cpp | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/tools/zipalign/ZipEntry.cpp b/tools/zipalign/ZipEntry.cpp index 689999ee18..dd2eac60a8 100644 --- a/tools/zipalign/ZipEntry.cpp +++ b/tools/zipalign/ZipEntry.cpp @@ -18,6 +18,8 @@ // Access to entries in a Zip archive. // +#define _POSIX_THREAD_SAFE_FUNCTIONS // For mingw localtime_r(). + #define LOG_TAG "zip" #include "ZipEntry.h" @@ -354,31 +356,20 @@ time_t ZipEntry::getModWhen(void) const */ void ZipEntry::setModWhen(time_t when) { -#if !defined(_WIN32) - struct tm tmResult; -#endif - time_t even; - uint16_t zdate, ztime; - - struct tm* ptm; - /* round up to an even number of seconds */ - even = (when & 1) ? (when + 1) : when; + time_t even = (when & 1) ? (when + 1) : when; /* expand */ -#if !defined(_WIN32) - ptm = localtime_r(&even, &tmResult); -#else - ptm = localtime(&even); -#endif + struct tm tmResult; + struct tm* ptm = localtime_r(&even, &tmResult); int year; year = ptm->tm_year; if (year < 80) year = 80; - zdate = (year - 80) << 9 | (ptm->tm_mon+1) << 5 | ptm->tm_mday; - ztime = ptm->tm_hour << 11 | ptm->tm_min << 5 | ptm->tm_sec >> 1; + uint16_t zdate = (year - 80) << 9 | (ptm->tm_mon+1) << 5 | ptm->tm_mday; + uint16_t ztime = ptm->tm_hour << 11 | ptm->tm_min << 5 | ptm->tm_sec >> 1; mCDE.mLastModFileTime = mLFH.mLastModFileTime = ztime; mCDE.mLastModFileDate = mLFH.mLastModFileDate = zdate;