@@ -147,12 +147,21 @@ fn test_rwlock_libc_static_initializer() {
147
147
#[ cfg( target_os = "linux" ) ]
148
148
fn test_prctl_thread_name ( ) {
149
149
use std:: ffi:: CString ;
150
+ use libc:: c_long;
150
151
unsafe {
152
+ let mut buf = [ 255 ; 10 ] ;
153
+ assert_eq ! ( libc:: prctl( libc:: PR_GET_NAME , buf. as_mut_ptr( ) as c_long, 0 as c_long, 0 as c_long, 0 as c_long) , 0 ) ;
154
+ assert_eq ! ( b"<unnamed>\0 " , & buf) ;
151
155
let thread_name = CString :: new ( "hello" ) . expect ( "CString::new failed" ) ;
152
- assert_eq ! ( libc:: prctl( libc:: PR_SET_NAME , thread_name. as_ptr( ) as libc:: c_long, 0 as libc:: c_long, 0 as libc:: c_long, 0 as libc:: c_long) , 0 ) ;
153
- let mut buf = [ 0 ; 6 ] ;
154
- assert_eq ! ( libc:: prctl( libc:: PR_GET_NAME , buf. as_mut_ptr( ) as libc:: c_long, 0 as libc:: c_long, 0 as libc:: c_long, 0 as libc:: c_long) , 0 ) ;
155
- assert_eq ! ( thread_name. as_bytes_with_nul( ) , buf) ;
156
+ assert_eq ! ( libc:: prctl( libc:: PR_SET_NAME , thread_name. as_ptr( ) as c_long, 0 as c_long, 0 as c_long, 0 as c_long) , 0 ) ;
157
+ let mut buf = [ 255 ; 6 ] ;
158
+ assert_eq ! ( libc:: prctl( libc:: PR_GET_NAME , buf. as_mut_ptr( ) as c_long, 0 as c_long, 0 as c_long, 0 as c_long) , 0 ) ;
159
+ assert_eq ! ( b"hello\0 " , & buf) ;
160
+ let long_thread_name = CString :: new ( "01234567890123456789" ) . expect ( "CString::new failed" ) ;
161
+ assert_eq ! ( libc:: prctl( libc:: PR_SET_NAME , long_thread_name. as_ptr( ) as c_long, 0 as c_long, 0 as c_long, 0 as c_long) , 0 ) ;
162
+ let mut buf = [ 255 ; 16 ] ;
163
+ assert_eq ! ( libc:: prctl( libc:: PR_GET_NAME , buf. as_mut_ptr( ) as c_long, 0 as c_long, 0 as c_long, 0 as c_long) , 0 ) ;
164
+ assert_eq ! ( b"012345678901234\0 " , & buf) ;
156
165
}
157
166
}
158
167
0 commit comments