Skip to content

Commit e1ec85f

Browse files
committed
Add fallback impl for GetSystemTimeAsFileTime
(only used for NT 3.1)
1 parent 952400b commit e1ec85f

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,15 @@ compat_fn_with_fallback! {
341341
pub fn GetTempPath2W(bufferlength: u32, buffer: PWSTR) -> u32 {
342342
GetTempPathW(bufferlength, buffer)
343343
}
344+
345+
// >= 95 / NT 3.5
346+
// https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimeasfiletime
347+
pub fn GetSystemTimeAsFileTime(lpSystemTimeAsFileTime: *mut FILETIME) -> () {
348+
// implementation based on old MSDN docs
349+
let mut st: SYSTEMTIME = crate::mem::zeroed();
350+
GetSystemTime(&mut st);
351+
crate::sys::cvt(SystemTimeToFileTime(&st, lpSystemTimeAsFileTime)).unwrap();
352+
}
344353
}
345354

346355
compat_fn_optional! {

library/std/src/sys/windows/c/windows_sys.lst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,3 +2608,7 @@ Windows.Win32.System.Threading.LeaveCriticalSection
26082608
Windows.Win32.System.Threading.DeleteCriticalSection
26092609
Windows.Win32.System.Threading.SRWLOCK
26102610
Windows.Win32.System.Threading.CONDITION_VARIABLE
2611+
2612+
// system time fallback
2613+
Windows.Win32.System.SystemInformation.GetSystemTime
2614+
Windows.Win32.System.Time.SystemTimeToFileTime

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ extern "system" {
381381
pub fn GetSystemInfo(lpsysteminfo: *mut SYSTEM_INFO) -> ();
382382
}
383383
#[link(name = "kernel32")]
384+
extern "system" {
385+
pub fn GetSystemTime(lpsystemtime: *mut SYSTEMTIME) -> ();
386+
}
387+
#[link(name = "kernel32")]
384388
extern "system" {
385389
pub fn GetSystemTimeAsFileTime(lpsystemtimeasfiletime: *mut FILETIME) -> ();
386390
}
@@ -594,6 +598,11 @@ extern "system" {
594598
pub fn SwitchToThread() -> BOOL;
595599
}
596600
#[link(name = "kernel32")]
601+
extern "system" {
602+
pub fn SystemTimeToFileTime(lpsystemtime: *const SYSTEMTIME, lpfiletime: *mut FILETIME)
603+
-> BOOL;
604+
}
605+
#[link(name = "kernel32")]
597606
extern "system" {
598607
pub fn TerminateProcess(hprocess: HANDLE, uexitcode: u32) -> BOOL;
599608
}
@@ -4063,6 +4072,23 @@ pub const SYMLINK_FLAG_RELATIVE: u32 = 1u32;
40634072
pub type SYNCHRONIZATION_ACCESS_RIGHTS = u32;
40644073
pub const SYNCHRONIZE: FILE_ACCESS_RIGHTS = 1048576u32;
40654074
#[repr(C)]
4075+
pub struct SYSTEMTIME {
4076+
pub wYear: u16,
4077+
pub wMonth: u16,
4078+
pub wDayOfWeek: u16,
4079+
pub wDay: u16,
4080+
pub wHour: u16,
4081+
pub wMinute: u16,
4082+
pub wSecond: u16,
4083+
pub wMilliseconds: u16,
4084+
}
4085+
impl ::core::marker::Copy for SYSTEMTIME {}
4086+
impl ::core::clone::Clone for SYSTEMTIME {
4087+
fn clone(&self) -> Self {
4088+
*self
4089+
}
4090+
}
4091+
#[repr(C)]
40664092
pub struct SYSTEM_INFO {
40674093
pub Anonymous: SYSTEM_INFO_0,
40684094
pub dwPageSize: u32,

0 commit comments

Comments
 (0)