]> git.proxmox.com Git - rustc.git/blob - vendor/sysinfo/src/windows/utils.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / vendor / sysinfo / src / windows / utils.rs
1 // Take a look at the license at the top of the repository in the LICENSE file.
2
3 use winapi::shared::minwindef::FILETIME;
4 use winapi::um::winnt::LPWSTR;
5
6 use std::time::SystemTime;
7
8 #[inline]
9 pub(crate) fn filetime_to_u64(f: FILETIME) -> u64 {
10 (f.dwHighDateTime as u64) << 32 | (f.dwLowDateTime as u64)
11 }
12
13 #[inline]
14 pub(crate) fn get_now() -> u64 {
15 SystemTime::now()
16 .duration_since(SystemTime::UNIX_EPOCH)
17 .map(|n| n.as_secs())
18 .unwrap_or(0)
19 }
20
21 pub(crate) unsafe fn to_str(p: LPWSTR) -> String {
22 let mut i = 0;
23
24 loop {
25 let c = *p.offset(i);
26 if c == 0 {
27 break;
28 }
29 i += 1;
30 }
31 let s = std::slice::from_raw_parts(p, i as _);
32 String::from_utf16(s).unwrap_or_else(|_e| {
33 sysinfo_debug!("Failed to convert to UTF-16 string: {}", _e);
34 String::new()
35 })
36 }