File tree 1 file changed +20
-1
lines changed
library/std/src/os/unix/net
1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -209,7 +209,26 @@ impl SocketAddr {
209
209
} else if self . addr . sun_path [ 0 ] == 0 {
210
210
AddressKind :: Abstract ( & path[ 1 ..len] )
211
211
} else {
212
- AddressKind :: Pathname ( OsStr :: from_bytes ( & path[ ..len - 1 ] ) . as_ref ( ) )
212
+ cfg_if ! {
213
+ if #[ cfg( any( target_os = "macos" ,
214
+ target_os = "ios" ,
215
+ target_os = "freebsd" ,
216
+ target_os = "dragonfly" ,
217
+ target_os = "openbsd" ,
218
+ target_os = "netbsd" ) ) ] {
219
+ // BSD-like systems may not include the last '\0' in length,
220
+ // because they have a sun_len as the length of sun_path
221
+ let sun_len = self . addr. sun_len;
222
+ } else {
223
+ // Trim the last '\0'
224
+ let mut sun_len = len;
225
+ while sun_len > 0 && path[ sun_len] == 0 {
226
+ sun_len -= 1 ;
227
+ }
228
+ }
229
+ }
230
+
231
+ AddressKind :: Pathname ( OsStr :: from_bytes ( & path[ ..sun_len] ) . as_ref ( ) )
213
232
}
214
233
}
215
234
}
You can’t perform that action at this time.
0 commit comments