From 396008c5931a9a605b6162fe1439c6990f0e2ed2 Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Sat, 23 Mar 2024 13:56:34 -0300 Subject: [PATCH] Proper implementation for `GetSystemTime` and `GetLocalTime` (#73) * Implement * GetLocalTime --- dll/kernel32.cpp | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/dll/kernel32.cpp b/dll/kernel32.cpp index 07e9989..b899b3d 100644 --- a/dll/kernel32.cpp +++ b/dll/kernel32.cpp @@ -1133,19 +1133,36 @@ namespace kernel32 { void WIN_FUNC GetSystemTime(SYSTEMTIME *lpSystemTime) { DEBUG_LOG("GetSystemTime\n"); - lpSystemTime->wYear = 0; - lpSystemTime->wMonth = 0; - lpSystemTime->wDayOfWeek = 0; - lpSystemTime->wDay = 0; - lpSystemTime->wHour = 0; - lpSystemTime->wMinute = 0; - lpSystemTime->wSecond = 0; + + time_t t = time(NULL); + struct tm *tm = gmtime(&t); + assert(tm != NULL); + + lpSystemTime->wYear = tm->tm_year + 1900; + lpSystemTime->wMonth = tm->tm_mon + 1; + lpSystemTime->wDayOfWeek = tm->tm_wday; + lpSystemTime->wDay = tm->tm_mday; + lpSystemTime->wHour = tm->tm_hour; + lpSystemTime->wMinute = tm->tm_min; + lpSystemTime->wSecond = tm->tm_sec; lpSystemTime->wMilliseconds = 0; } void WIN_FUNC GetLocalTime(SYSTEMTIME *lpSystemTime) { DEBUG_LOG("GetLocalTime\n"); - GetSystemTime(lpSystemTime); + + time_t t = time(NULL); + struct tm *tm = localtime(&t); + assert(tm != NULL); + + lpSystemTime->wYear = tm->tm_year + 1900; + lpSystemTime->wMonth = tm->tm_mon + 1; + lpSystemTime->wDayOfWeek = tm->tm_wday; + lpSystemTime->wDay = tm->tm_mday; + lpSystemTime->wHour = tm->tm_hour; + lpSystemTime->wMinute = tm->tm_min; + lpSystemTime->wSecond = tm->tm_sec; + lpSystemTime->wMilliseconds = 0; } int WIN_FUNC SystemTimeToFileTime(const SYSTEMTIME *lpSystemTime, FILETIME *lpFileTime) {