Skip to content

Commit 7285be2

Browse files
seritoolsmbilker
authored andcommitted
Add fallback impl for GetSystemTimeAsFileTime
(only used for NT 3.1)
1 parent 540709b commit 7285be2

File tree

1 file changed

+26
-0
lines changed
  • library/std/src/sys/windows

1 file changed

+26
-0
lines changed

library/std/src/sys/windows/c.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,20 @@ if #[cfg(not(target_vendor = "uwp"))] {
199199
}
200200
}
201201

202+
#[repr(C)]
203+
pub struct SYSTEMTIME {
204+
wYear: WORD,
205+
wMonth: WORD,
206+
wDayOfWeek: WORD,
207+
wDay: WORD,
208+
wHour: WORD,
209+
wMinute: WORD,
210+
wSecond: WORD,
211+
wMilliseconds: WORD,
212+
}
213+
214+
pub type LPSYSTEMTIME = *mut SYSTEMTIME;
215+
202216
pub unsafe extern "system" fn WriteFileEx(
203217
hFile: BorrowedHandle<'_>,
204218
lpBuffer: *mut ::core::ffi::c_void,
@@ -407,6 +421,15 @@ compat_fn_with_fallback! {
407421
pub fn GetProcessId(handle: HANDLE) -> DWORD {
408422
rtabort!("unavailable")
409423
}
424+
425+
// >= 95 / NT 3.5
426+
// https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimeasfiletime
427+
pub fn GetSystemTimeAsFileTime(lpSystemTimeAsFileTime: LPFILETIME) -> () {
428+
// implementation based on old MSDN docs
429+
let mut st: SYSTEMTIME = crate::mem::zeroed();
430+
GetSystemTime(&mut st);
431+
crate::sys::cvt(SystemTimeToFileTime(&st, lpSystemTimeAsFileTime)).unwrap();
432+
}
410433
}
411434

412435
compat_fn_optional! {
@@ -469,4 +492,7 @@ extern "system" {
469492
) -> HANDLE;
470493

471494
pub fn PulseEvent(hEvent: HANDLE) -> BOOL;
495+
496+
pub fn GetSystemTime(lpSystemTime: LPSYSTEMTIME);
497+
pub fn SystemTimeToFileTime(lpSystemTime: *const SYSTEMTIME, lpFileTime: LPFILETIME) -> BOOL;
472498
}

0 commit comments

Comments
 (0)