@@ -66,14 +66,14 @@ fn get_fd_path<A: Allocator>(allocator: A, fd: BorrowedFd<'_>) -> nix::Result<Op
6666}
6767
6868pub trait ToAbsolutePath {
69- unsafe fn to_absolute_path < R , F : FnOnce ( Option < & BStr > ) -> nix:: Result < R > > (
69+ fn to_absolute_path < R , F : FnOnce ( Option < & BStr > ) -> nix:: Result < R > > (
7070 self ,
7171 f : F ,
7272 ) -> nix:: Result < R > ;
7373}
7474
7575impl ToAbsolutePath for BorrowedFd < ' _ > {
76- unsafe fn to_absolute_path < R , F : FnOnce ( Option < & BStr > ) -> nix:: Result < R > > (
76+ fn to_absolute_path < R , F : FnOnce ( Option < & BStr > ) -> nix:: Result < R > > (
7777 self ,
7878 f : F ,
7979 ) -> nix:: Result < R > {
@@ -99,51 +99,46 @@ impl PathAt<'_, '_> {
9999}
100100
101101impl ToAbsolutePath for PathAt < ' _ , ' _ > {
102- unsafe fn to_absolute_path < R , F : FnOnce ( Option < & BStr > ) -> nix:: Result < R > > (
102+ fn to_absolute_path < R , F : FnOnce ( Option < & BStr > ) -> nix:: Result < R > > (
103103 self ,
104104 f : F ,
105105 ) -> nix:: Result < R > {
106- // SAFETY: self.1 is a valid NUL-terminated string.
107- let pathname = unsafe { CStr :: from_ptr ( self . 1 . as_ptr ( ) ) } . to_bytes ( ) . as_bstr ( ) ;
106+ let pathname = self . 1 . count ( ) . as_bytes ( ) . as_bstr ( ) ;
108107
109- if pathname. first ( ) . copied ( ) == Some ( b'/' ) {
110- f ( pathname . into ( ) )
108+ if pathname. starts_with ( b"/" ) {
109+ f ( Some ( pathname ) )
111110 } else {
112- // SAFETY: delegates the same caller-provided descriptor.
113- unsafe {
114- self . 0 . to_absolute_path ( |base| {
115- let Some ( base) = base else {
116- return f ( None ) ;
117- } ;
118- if pathname. is_empty ( ) {
119- return f ( Some ( base) ) ;
120- }
121-
122- let arena = sigsafe_alloc:: arena ( ) ;
123- let needs_separator = !base. ends_with ( b"/" ) ;
124- let mut abs_path = Vec :: with_capacity_in (
125- base. len ( ) + usize:: from ( needs_separator) + pathname. len ( ) ,
126- & arena,
127- ) ;
128- abs_path. extend_from_slice ( base) ;
129- if needs_separator {
130- abs_path. push ( b'/' ) ;
131- }
132- abs_path. extend_from_slice ( pathname) ;
133- f ( Some ( abs_path. as_slice ( ) . as_bstr ( ) ) )
134- } )
135- }
111+ self . 0 . to_absolute_path ( |base| {
112+ let Some ( base) = base else {
113+ return f ( None ) ;
114+ } ;
115+ if pathname. is_empty ( ) {
116+ return f ( Some ( base) ) ;
117+ }
118+
119+ let arena = sigsafe_alloc:: arena ( ) ;
120+ let needs_separator = !base. ends_with ( b"/" ) ;
121+ let mut abs_path = Vec :: with_capacity_in (
122+ base. len ( ) + usize:: from ( needs_separator) + pathname. len ( ) ,
123+ & arena,
124+ ) ;
125+ abs_path. extend_from_slice ( base) ;
126+ if needs_separator {
127+ abs_path. push ( b'/' ) ;
128+ }
129+ abs_path. extend_from_slice ( pathname) ;
130+ f ( Some ( abs_path. as_slice ( ) . as_bstr ( ) ) )
131+ } )
136132 }
137133 }
138134}
139135
140- impl ToAbsolutePath for * const c_char {
141- unsafe fn to_absolute_path < R , F : FnOnce ( Option < & BStr > ) -> nix:: Result < R > > (
136+ impl ToAbsolutePath for sigsafe :: CStr < ' _ , sigsafe :: Thin > {
137+ fn to_absolute_path < R , F : FnOnce ( Option < & BStr > ) -> nix:: Result < R > > (
142138 self ,
143139 f : F ,
144140 ) -> nix:: Result < R > {
145- // SAFETY: delegates the same caller-provided C string pointer.
146- unsafe { PathAt ( CWD , sigsafe:: CStr :: from_ptr ( self ) ) . to_absolute_path ( f) }
141+ PathAt ( CWD , self ) . to_absolute_path ( f)
147142 }
148143}
149144
0 commit comments