mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-28 07:33:14 -04:00
Fix embedded NULs in C wide strings returned from Windows API (#2264)
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
use std::{
|
||||
ffi::{c_void, OsStr},
|
||||
ffi::{c_void, OsStr, OsString},
|
||||
io,
|
||||
iter::once,
|
||||
mem,
|
||||
ops::BitAnd,
|
||||
os::windows::prelude::OsStrExt,
|
||||
os::windows::prelude::{OsStrExt, OsStringExt},
|
||||
ptr,
|
||||
sync::atomic::{AtomicBool, Ordering},
|
||||
};
|
||||
@@ -37,6 +37,14 @@ pub fn encode_wide(string: impl AsRef<OsStr>) -> Vec<u16> {
|
||||
string.as_ref().encode_wide().chain(once(0)).collect()
|
||||
}
|
||||
|
||||
pub fn decode_wide(mut wide_c_string: &[u16]) -> OsString {
|
||||
if let Some(null_pos) = wide_c_string.iter().position(|c| *c == 0) {
|
||||
wide_c_string = &wide_c_string[..null_pos];
|
||||
}
|
||||
|
||||
OsString::from_wide(wide_c_string)
|
||||
}
|
||||
|
||||
pub fn has_flag<T>(bitset: T, flag: T) -> bool
|
||||
where
|
||||
T: Copy + PartialEq + BitAnd<T, Output = T>,
|
||||
|
||||
Reference in New Issue
Block a user