Skip to content

win32.c: use _mkgmtime() instead of mktime() in stat() #20064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pod/perldelta.pod
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,18 @@ L</Modules and Pragmata> section.

=over 4

=item XXX-some-platform
=item Windows

XXX
=over 4

=item *

In some cases, timestamps returned by L<stat()|perlfunc/stat> and
L<lstat()|perlfunc/lstat> failed to take daylight saving time into account.
[L<GH #20018|https://github.com/Perl/perl5/issues/20018>]
[L<GH #20061|https://github.com/Perl/perl5/issues/20061>]

=back

=back

Expand Down
23 changes: 10 additions & 13 deletions win32/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1469,24 +1469,21 @@ win32_kill(int pid, int sig)
PERL_STATIC_INLINE
time_t
translate_ft_to_time_t(FILETIME ft) {
SYSTEMTIME st, local_st;
SYSTEMTIME st;
struct tm pt;

if (!FileTimeToSystemTime(&ft, &st) ||
!SystemTimeToTzSpecificLocalTime(NULL, &st, &local_st)) {
if (!FileTimeToSystemTime(&ft, &st))
return -1;
}

Zero(&pt, 1, struct tm);
pt.tm_year = local_st.wYear - 1900;
pt.tm_mon = local_st.wMonth - 1;
pt.tm_mday = local_st.wDay;
pt.tm_hour = local_st.wHour;
pt.tm_min = local_st.wMinute;
pt.tm_sec = local_st.wSecond;
pt.tm_isdst = -1;

return mktime(&pt);
pt.tm_year = st.wYear - 1900;
pt.tm_mon = st.wMonth - 1;
pt.tm_mday = st.wDay;
pt.tm_hour = st.wHour;
pt.tm_min = st.wMinute;
pt.tm_sec = st.wSecond;

return _mkgmtime(&pt);
}

typedef DWORD (__stdcall *pGetFinalPathNameByHandleA_t)(HANDLE, LPSTR, DWORD, DWORD);
Expand Down