@@ -18,18 +18,27 @@ cfg_if! {
18
18
use libc:: __errno_location as errno_location;
19
19
} else if #[ cfg( any( target_os = "solaris" , target_os = "illumos" ) ) ] {
20
20
use libc:: ___errno as errno_location;
21
- } else if #[ cfg( any( target_os = "macos" , target_os = "freebsd" , target_os = "dragonfly" ) ) ] {
21
+ } else if #[ cfg( any( target_os = "macos" , target_os = "freebsd" ) ) ] {
22
22
use libc:: __error as errno_location;
23
23
} else if #[ cfg( target_os = "haiku" ) ] {
24
24
use libc:: _errnop as errno_location;
25
25
}
26
26
}
27
27
28
+ cfg_if ! {
29
+ if #[ cfg( target_os = "vxworks" ) ] {
30
+ use libc:: errnoGet as get_errno;
31
+ } else if #[ cfg( target_os = "dragonfly" ) ] {
32
+ // Until rust-lang/rust#29594 is stable, we cannot get the errno value
33
+ // on DragonFlyBSD. So we just return an out-of-range errno.
34
+ unsafe fn get_errno( ) -> libc:: c_int { -1 }
35
+ } else {
36
+ unsafe fn get_errno( ) -> libc:: c_int { * errno_location( ) }
37
+ }
38
+ }
39
+
28
40
pub fn last_os_error ( ) -> Error {
29
- #[ cfg( not( target_os = "vxworks" ) ) ]
30
- let errno = unsafe { * errno_location ( ) } ;
31
- #[ cfg( target_os = "vxworks" ) ]
32
- let errno = unsafe { libc:: errnoGet ( ) } ;
41
+ let errno = unsafe { get_errno ( ) } ;
33
42
if errno > 0 {
34
43
Error :: from ( NonZeroU32 :: new ( errno as u32 ) . unwrap ( ) )
35
44
} else {
0 commit comments