Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4420a988 authored by Elliott Hughes's avatar Elliott Hughes Committed by Gerrit Code Review
Browse files

Merge "Use localtime_r() on Windows too." into main

parents cebab4d1 7930f2f2
Loading
Loading
Loading
Loading
+8 −19
Original line number Diff line number Diff line
@@ -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"
@@ -337,39 +339,26 @@ time_t ZipEntry::getModWhen(void) const
/*
 * Set the CDE/LFH timestamp from UNIX time.
 */
void ZipEntry::setModWhen(time_t when)
{
#if !defined(_WIN32)
    struct tm tmResult;
#endif
    time_t even;
    unsigned short zdate, ztime;

    struct tm* ptm;

void ZipEntry::setModWhen(time_t when) {
    /* round up to an even number of seconds */
    even = (time_t)(((unsigned long)(when) + 1) & (~1));
    time_t even = (time_t)(((unsigned long)(when) + 1) & (~1));

    /* 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;
    unsigned short zdate = (year - 80) << 9 | (ptm->tm_mon + 1) << 5 | ptm->tm_mday;
    unsigned short ztime = ptm->tm_hour << 11 | ptm->tm_min << 5 | ptm->tm_sec >> 1;

    mCDE.mLastModFileTime = mLFH.mLastModFileTime = ztime;
    mCDE.mLastModFileDate = mLFH.mLastModFileDate = zdate;
}


/*
 * ===========================================================================
 *      ZipEntry::LocalFileHeader