@@ -59,15 +59,16 @@ fn main() {
59
59
let result = thread:: Builder :: new ( ) . name ( name. clone ( ) ) . spawn ( move || {
60
60
assert_eq ! ( thread:: current( ) . name( ) , Some ( name. as_str( ) ) ) ;
61
61
62
- let mut buf = vec ! [ 0u8 ; name. len( ) + 1 ] ;
62
+ // POSIX seems to promise at least 15 chars excluding a null terminator.
63
+ let mut buf = vec ! [ 0u8 ; 16 ] ;
63
64
assert_eq ! ( get_thread_name( & mut buf) , 0 ) ;
64
65
let cstr = CStr :: from_bytes_until_nul ( & buf) . unwrap ( ) ;
65
66
if name. len ( ) >= 15 {
66
67
assert ! (
67
68
cstr. to_bytes( ) . len( ) >= 15 ,
68
69
"name is too short: len={}" ,
69
70
cstr. to_bytes( ) . len( )
70
- ) ; // POSIX seems to promise at least 15 chars
71
+ ) ;
71
72
assert ! ( name. as_bytes( ) . starts_with( cstr. to_bytes( ) ) ) ;
72
73
} else {
73
74
assert_eq ! ( name. as_bytes( ) , cstr. to_bytes( ) ) ;
@@ -80,7 +81,7 @@ fn main() {
80
81
// But with a too long name it should fail except:
81
82
// * on FreeBSD where the function has no return, hence cannot indicate failure,
82
83
// * on Android where prctl silently truncates the string.
83
- #[ cfg( not( all ( target_os = "freebsd" , target_os = "android" ) ) ) ]
84
+ #[ cfg( not( any ( target_os = "freebsd" , target_os = "android" ) ) ) ]
84
85
assert_ne ! ( set_thread_name( & std:: ffi:: CString :: new( name) . unwrap( ) ) , 0 ) ;
85
86
}
86
87
} ) ;
0 commit comments