@@ -172,14 +172,13 @@ fn test_thread_local_errno() {
172172}
173173
174174/// Tests whether clock support exists at all
175- #[ cfg( not( target_os = "freebsd" ) ) ]
176175fn test_clocks ( ) {
177176 let mut tp = std:: mem:: MaybeUninit :: < libc:: timespec > :: uninit ( ) ;
178177 let is_error = unsafe { libc:: clock_gettime ( libc:: CLOCK_REALTIME , tp. as_mut_ptr ( ) ) } ;
179178 assert_eq ! ( is_error, 0 ) ;
180179 let is_error = unsafe { libc:: clock_gettime ( libc:: CLOCK_MONOTONIC , tp. as_mut_ptr ( ) ) } ;
181180 assert_eq ! ( is_error, 0 ) ;
182- #[ cfg( target_os = "linux" ) ]
181+ #[ cfg( any ( target_os = "linux" , target_os = "freebsd" ) ) ]
183182 {
184183 let is_error = unsafe { libc:: clock_gettime ( libc:: CLOCK_REALTIME_COARSE , tp. as_mut_ptr ( ) ) } ;
185184 assert_eq ! ( is_error, 0 ) ;
@@ -238,51 +237,6 @@ fn test_isatty() {
238237 }
239238}
240239
241- #[ cfg( not( target_os = "freebsd" ) ) ]
242- fn test_posix_mkstemp ( ) {
243- use std:: ffi:: CString ;
244- use std:: ffi:: OsStr ;
245- use std:: os:: unix:: ffi:: OsStrExt ;
246- use std:: os:: unix:: io:: FromRawFd ;
247- use std:: path:: Path ;
248-
249- let valid_template = "fooXXXXXX" ;
250- // C needs to own this as `mkstemp(3)` says:
251- // "Since it will be modified, `template` must not be a string constant, but
252- // should be declared as a character array."
253- // There seems to be no `as_mut_ptr` on `CString` so we need to use `into_raw`.
254- let ptr = CString :: new ( valid_template) . unwrap ( ) . into_raw ( ) ;
255- let fd = unsafe { libc:: mkstemp ( ptr) } ;
256- // Take ownership back in Rust to not leak memory.
257- let slice = unsafe { CString :: from_raw ( ptr) } ;
258- assert ! ( fd > 0 ) ;
259- let osstr = OsStr :: from_bytes ( slice. to_bytes ( ) ) ;
260- let path: & Path = osstr. as_ref ( ) ;
261- let name = path. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
262- assert ! ( name. ne( "fooXXXXXX" ) ) ;
263- assert ! ( name. starts_with( "foo" ) ) ;
264- assert_eq ! ( name. len( ) , 9 ) ;
265- assert_eq ! (
266- name. chars( ) . skip( 3 ) . filter( char :: is_ascii_alphanumeric) . collect:: <Vec <char >>( ) . len( ) ,
267- 6
268- ) ;
269- let file = unsafe { File :: from_raw_fd ( fd) } ;
270- assert ! ( file. set_len( 0 ) . is_ok( ) ) ;
271-
272- let invalid_templates = vec ! [ "foo" , "barXX" , "XXXXXXbaz" , "whatXXXXXXever" , "X" ] ;
273- for t in invalid_templates {
274- let ptr = CString :: new ( t) . unwrap ( ) . into_raw ( ) ;
275- let fd = unsafe { libc:: mkstemp ( ptr) } ;
276- let _ = unsafe { CString :: from_raw ( ptr) } ;
277- // "On error, -1 is returned, and errno is set to
278- // indicate the error"
279- assert_eq ! ( fd, -1 ) ;
280- let e = std:: io:: Error :: last_os_error ( ) ;
281- assert_eq ! ( e. raw_os_error( ) , Some ( libc:: EINVAL ) ) ;
282- assert_eq ! ( e. kind( ) , std:: io:: ErrorKind :: InvalidInput ) ;
283- }
284- }
285-
286240fn test_memcpy ( ) {
287241 unsafe {
288242 let src = [ 1i8 , 2 , 3 ] ;
@@ -406,9 +360,6 @@ fn test_reallocarray() {
406360fn main ( ) {
407361 test_posix_gettimeofday ( ) ;
408362
409- #[ cfg( not( target_os = "freebsd" ) ) ] // FIXME we should support this on FreeBSD as well
410- test_posix_mkstemp ( ) ;
411-
412363 test_posix_realpath_alloc ( ) ;
413364 test_posix_realpath_noalloc ( ) ;
414365 test_posix_realpath_errors ( ) ;
@@ -417,7 +368,6 @@ fn main() {
417368
418369 test_isatty ( ) ;
419370
420- #[ cfg( not( target_os = "freebsd" ) ) ] // FIXME we should support this on FreeBSD as well
421371 test_clocks ( ) ;
422372
423373 test_dlsym ( ) ;
0 commit comments