summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Elliott Hughes <enh@google.com> 2023-09-05 21:37:01 +0000
committer Elliott Hughes <enh@google.com> 2023-09-05 21:37:01 +0000
commit16caa44298f13e119e0f282de070d0dbbd2c80ac (patch)
tree2d0ba0cf7e192900cd965d4d93b1ef18609ffef6
parentaea0819fc7e528b0bf419f8b2159a11d1bcd5c66 (diff)
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
-rw-r--r--tools/zipalign/ZipEntry.cpp23
1 files 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;