Archive-Unzip-Burst
view release on metacpan or search on metacpan
unzip-6.0/wince/wince.cpp view on Meta::CPAN
TCHAR szPath[_MAX_PATH];
MBSTOTSTR(szPath, path, countof(szPath));
HANDLE hFind = FindFirstFile(szPath, &w32fd);
// Bail out now if we could not find the file/directory.
if (hFind == INVALID_HANDLE_VALUE) {
return -1;
}
// Close the find.
FindClose(hFind);
// Mode flags that are currently used: S_IWRITE, S_IFMT, S_IFDIR, S_IEXEC
if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
buffer->st_mode = _S_IFDIR | _S_IREAD | _S_IEXEC;
} else {
buffer->st_mode = _S_IFREG | _S_IREAD;
}
if (!(w32fd.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
buffer->st_mode |= _S_IWRITE;
}
// Store the file size.
buffer->st_size = (_off_t)w32fd.nFileSizeLow;
// Convert the modified FILETIME to a time_t and store it.
DWORDLONG dwl = *(DWORDLONG*)&w32fd.ftLastWriteTime;
buffer->st_mtime = (time_t)((dwl - (DWORDLONG)116444736000000000) / (DWORDLONG)10000000);
return 0;
}
//******************************************************************************
//***** TIME.H functions
//******************************************************************************
// Evaluates to TRUE if 'y' is a leap year, otherwise FALSE
// #define IS_LEAP_YEAR(y) ((((y) % 4 == 0) && ((y) % 100 != 0)) || ((y) % 400 == 0))
// The macro below is a reduced version of the above macro. It is valid for
// years between 1901 and 2099 which easily includes all years representable
// by the current implementation of time_t.
#define IS_LEAP_YEAR(y) (((y) & 3) == 0)
#define BASE_DOW 4 // 1/1/1970 was a Thursday.
#define SECONDS_IN_A_DAY (24L * 60L * 60L) // Number of seconds in one day.
// Month to Year Day conversion array.
int M2YD[] = {
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
};
// Month to Leap Year Day conversion array.
int M2LYD[] = {
0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366
};
//******************************************************************************
//-- Called from list.c
struct tm * __cdecl localtime(const time_t *timer) {
// Return value for localtime(). Source currently never references
// more than one "tm" at a time, so the single return structure is ok.
static struct tm g_tm;
ZeroMemory(&g_tm, sizeof(g_tm));
// Get our time zone information.
TIME_ZONE_INFORMATION tzi;
SafeGetTimeZoneInformation(&tzi);
// Create a time_t that has been corrected for our time zone.
time_t localTime = *timer - (tzi.Bias * 60L);
// Decide if value is in Daylight Savings Time.
if (g_tm.tm_isdst = (int)IsDST(&tzi, localTime)) {
localTime -= tzi.DaylightBias * 60L; // usually 60 minutes
} else {
localTime -= tzi.StandardBias * 60L; // usually 0 minutes
}
// time_t is a 32-bit value for the seconds since January 1, 1970
// FILETIME is a 64-bit value for the number of 100-nanosecond intervals
// since January 1, 1601
// Compute the FILETIME for the given local time.
DWORDLONG dwl = ((DWORDLONG)116444736000000000 +
((DWORDLONG)localTime * (DWORDLONG)10000000));
FILETIME ft = *(FILETIME*)&dwl;
// Convert the FILETIME to a SYSTEMTIME.
SYSTEMTIME st;
ZeroMemory(&st, sizeof(st));
FileTimeToSystemTime(&ft, &st);
// Finish filling in our "tm" structure.
g_tm.tm_sec = (int)st.wSecond;
g_tm.tm_min = (int)st.wMinute;
g_tm.tm_hour = (int)st.wHour;
g_tm.tm_mday = (int)st.wDay;
g_tm.tm_mon = (int)st.wMonth - 1;
g_tm.tm_year = (int)st.wYear - 1900;
return &g_tm;
}
//******************************************************************************
static void SafeGetTimeZoneInformation(TIME_ZONE_INFORMATION *ptzi)
{
ZeroMemory(ptzi, sizeof(TIME_ZONE_INFORMATION));
// Ask the OS for the standard/daylight rules for the current time zone.
if ((GetTimeZoneInformation(ptzi) == 0xFFFFFFFF) ||
(ptzi->StandardDate.wMonth > 12) || (ptzi->DaylightDate.wMonth > 12))
{
// If the OS fails us, we default to the United States' rules.
ZeroMemory(ptzi, sizeof(TIME_ZONE_INFORMATION));
ptzi->StandardDate.wMonth = 10; // October
ptzi->StandardDate.wDay = 5; // Last Sunday (DOW == 0)
ptzi->StandardDate.wHour = 2; // At 2:00 AM
ptzi->DaylightBias = -60; // One hour difference
ptzi->DaylightDate.wMonth = 4; // April
ptzi->DaylightDate.wDay = 1; // First Sunday (DOW == 0)
ptzi->DaylightDate.wHour = 2; // At 2:00 AM
}
}
//******************************************************************************
static time_t GetTransitionTimeT(TIME_ZONE_INFORMATION *ptzi,
int year, BOOL fStartDST)
{
// We only handle years within the range that time_t supports. We need to
( run in 0.783 second using v1.01-cache-2.11-cpan-bbcb1afb8fc )