Skip to content

Commit d75c599

Browse files
committed
Add docs for cygwin_conv_path
1 parent 45c5c34 commit d75c599

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/symbolize/gimli/libs_windows.rs

+12
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ unsafe fn get_posix_path(long_path: &[u16]) -> Option<OsString> {
4848
use super::mystd::os::unix::ffi::OsStringExt;
4949

5050
unsafe extern "C" {
51+
// Doc: https://cygwin.com/cygwin-api/func-cygwin-conv-path.html
52+
// Src: https://github.com/cygwin/cygwin/blob/718a15ba50e0d01c79800bd658c2477f9a603540/winsup/cygwin/path.cc#L3902
53+
// Safety:
54+
// * `what` should be `CCP_WIN_W_TO_POSIX` here
55+
// * `from` is `*const u16`, null-terminated, UTF-16 path
56+
// * `to` is `*mut u8` buffer, the buffer size is `size`.
5157
fn cygwin_conv_path(
5258
what: libc::c_uint,
5359
from: *const libc::c_void,
@@ -57,6 +63,9 @@ unsafe fn get_posix_path(long_path: &[u16]) -> Option<OsString> {
5763
}
5864
const CCP_WIN_W_TO_POSIX: libc::c_uint = 3;
5965

66+
// If `size` is 0, returns needed buffer size, including null terminator;
67+
// or -1 if error.
68+
// Safety: **Confirmed from source:** If `size` is 0, `to` is not used.
6069
let name_len = unsafe {
6170
cygwin_conv_path(
6271
CCP_WIN_W_TO_POSIX,
@@ -66,11 +75,13 @@ unsafe fn get_posix_path(long_path: &[u16]) -> Option<OsString> {
6675
)
6776
};
6877
// Expect at least 1 for null terminator.
78+
// It's not likely to return error here.
6979
if name_len < 1 {
7080
return None;
7181
}
7282
let name_len = name_len as usize;
7383
let mut name_buffer = vec![0_u8; name_len];
84+
// Safety: `name_buffer` is large enough.
7485
let res = unsafe {
7586
cygwin_conv_path(
7687
CCP_WIN_W_TO_POSIX,
@@ -79,6 +90,7 @@ unsafe fn get_posix_path(long_path: &[u16]) -> Option<OsString> {
7990
name_buffer.len(),
8091
)
8192
};
93+
// It's not likely to return error here.
8294
if res != 0 {
8395
return None;
8496
}

0 commit comments

Comments
 (0)