@@ -48,6 +48,12 @@ unsafe fn get_posix_path(long_path: &[u16]) -> Option<OsString> {
48
48
use super :: mystd:: os:: unix:: ffi:: OsStringExt ;
49
49
50
50
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`.
51
57
fn cygwin_conv_path (
52
58
what : libc:: c_uint ,
53
59
from : * const libc:: c_void ,
@@ -57,6 +63,9 @@ unsafe fn get_posix_path(long_path: &[u16]) -> Option<OsString> {
57
63
}
58
64
const CCP_WIN_W_TO_POSIX : libc:: c_uint = 3 ;
59
65
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.
60
69
let name_len = unsafe {
61
70
cygwin_conv_path (
62
71
CCP_WIN_W_TO_POSIX ,
@@ -66,11 +75,13 @@ unsafe fn get_posix_path(long_path: &[u16]) -> Option<OsString> {
66
75
)
67
76
} ;
68
77
// Expect at least 1 for null terminator.
78
+ // It's not likely to return error here.
69
79
if name_len < 1 {
70
80
return None ;
71
81
}
72
82
let name_len = name_len as usize ;
73
83
let mut name_buffer = vec ! [ 0_u8 ; name_len] ;
84
+ // Safety: `name_buffer` is large enough.
74
85
let res = unsafe {
75
86
cygwin_conv_path (
76
87
CCP_WIN_W_TO_POSIX ,
@@ -79,6 +90,7 @@ unsafe fn get_posix_path(long_path: &[u16]) -> Option<OsString> {
79
90
name_buffer. len ( ) ,
80
91
)
81
92
} ;
93
+ // It's not likely to return error here.
82
94
if res != 0 {
83
95
return None ;
84
96
}
0 commit comments