Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/libstd/sys/windows/ext/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use ffi::{OsString, OsStr};
use sys::os_str::Buf;
use slice;
use sys_common::wtf8::Wtf8Buf;
use sys_common::{FromInner, AsInner};

Expand All @@ -30,6 +31,20 @@ pub trait OsStringExt {
/// will always return the original code units.
#[stable(feature = "rust1", since = "1.0.0")]
fn from_wide(wide: &[u16]) -> Self;

/// Creates an `OsString` from a potentially ill-formed null-terminated
/// UTF-16 pointer.
///
/// This is lossless: calling `.encode_wide()` on the resulting string
/// will always return the original code units.
#[unstable(feature = "from_wide_null", issue = "0")]
unsafe fn from_wide_null(ptr: *const u16) -> OsString {
let mut len = 0;
while *ptr.offset(len) != 0 {
len += 1;
}
OsStringExt::from_wide(slice::from_raw_parts(ptr, len as usize))
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down