Skip to content

Commit 9bc534e

Browse files
nobunagachika
authored andcommitted
Win32: Initialize the systemtime function before converting FILETIME
1 parent ff1d615 commit 9bc534e

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

win32/win32.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4832,10 +4832,11 @@ waitpid(rb_pid_t pid, int *stat_loc, int options)
48324832

48334833
static int have_precisetime = -1;
48344834

4835-
static void
4836-
get_systemtime(FILETIME *ft)
4835+
typedef void (WINAPI *get_time_func)(FILETIME *ft);
4836+
4837+
static get_time_func
4838+
get_systemtime_func(void)
48374839
{
4838-
typedef void (WINAPI *get_time_func)(FILETIME *ft);
48394840
static get_time_func func = (get_time_func)-1;
48404841

48414842
if (func == (get_time_func)-1) {
@@ -4848,8 +4849,14 @@ get_systemtime(FILETIME *ft)
48484849
else
48494850
have_precisetime = 1;
48504851
}
4852+
return func;
4853+
}
4854+
4855+
static void
4856+
get_systemtime(FILETIME *ft)
4857+
{
48514858
if (!ft) return;
4852-
func(ft);
4859+
get_systemtime_func()(ft);
48534860
}
48544861

48554862
/* License: Ruby's */
@@ -5770,6 +5777,7 @@ stati128_handle(HANDLE h, struct stati128 *st)
57705777

57715778
if (GetFileInformationByHandle(h, &info)) {
57725779
FILE_ID_INFO fii;
5780+
get_systemtime_func();
57735781
st->st_size = ((__int64)info.nFileSizeHigh << 32) | info.nFileSizeLow;
57745782
st->st_atime = filetime_to_unixtime(&info.ftLastAccessTime);
57755783
st->st_atimensec = filetime_to_nsec(&info.ftLastAccessTime);
@@ -5915,6 +5923,7 @@ stat_by_find(const WCHAR *path, struct stati128 *st)
59155923
return -1;
59165924
}
59175925
FindClose(h);
5926+
get_systemtime_func();
59185927
st->st_mode = fileattr_to_unixmode(wfd.dwFileAttributes, path, 0);
59195928
st->st_atime = filetime_to_unixtime(&wfd.ftLastAccessTime);
59205929
st->st_atimensec = filetime_to_nsec(&wfd.ftLastAccessTime);

0 commit comments

Comments
 (0)