@@ -18,18 +18,27 @@ cfg_if! {
1818 use libc:: __errno_location as errno_location;
1919 } else if #[ cfg( any( target_os = "solaris" , target_os = "illumos" ) ) ] {
2020 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" ) ) ] {
2222 use libc:: __error as errno_location;
2323 } else if #[ cfg( target_os = "haiku" ) ] {
2424 use libc:: _errnop as errno_location;
2525 }
2626}
2727
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+
2840pub 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 ( ) } ;
3342 if errno > 0 {
3443 Error :: from ( NonZeroU32 :: new ( errno as u32 ) . unwrap ( ) )
3544 } else {
0 commit comments