@@ -60,22 +60,29 @@ impl Error {
60
60
}
61
61
}
62
62
63
- #[ cfg( any( unix, target_os = "redox" ) ) ]
64
- fn os_err_desc ( errno : i32 , buf : & mut [ u8 ] ) -> Option < & str > {
65
- let buf_ptr = buf. as_mut_ptr ( ) as * mut libc:: c_char ;
66
- if unsafe { libc:: strerror_r ( errno, buf_ptr, buf. len ( ) ) } != 0 {
67
- return None ;
68
- }
69
-
70
- // Take up to trailing null byte
71
- let n = buf. len ( ) ;
72
- let idx = buf. iter ( ) . position ( |& b| b == 0 ) . unwrap_or ( n) ;
73
- core:: str:: from_utf8 ( & buf[ ..idx] ) . ok ( )
74
- }
63
+ cfg_if ! {
64
+ if #[ cfg( unix) ] {
65
+ fn os_err_desc( errno: i32 , buf: & mut [ u8 ] ) -> Option <& str > {
66
+ let buf_ptr = buf. as_mut_ptr( ) as * mut libc:: c_char;
67
+ if unsafe { libc:: strerror_r( errno, buf_ptr, buf. len( ) ) } != 0 {
68
+ return None ;
69
+ }
75
70
76
- #[ cfg( not( any( unix, target_os = "redox" ) ) ) ]
77
- fn os_err_desc ( _errno : i32 , _buf : & mut [ u8 ] ) -> Option < & str > {
78
- None
71
+ // Take up to trailing null byte
72
+ let n = buf. len( ) ;
73
+ let idx = buf. iter( ) . position( |& b| b == 0 ) . unwrap_or( n) ;
74
+ core:: str :: from_utf8( & buf[ ..idx] ) . ok( )
75
+ }
76
+ } else if #[ cfg( target_os = "wasi" ) ] {
77
+ fn os_err_desc( errno: i32 , _buf: & mut [ u8 ] ) -> Option <& str > {
78
+ core:: num:: NonZeroU16 :: new( errno as u16 )
79
+ . and_then( wasi:: wasi_unstable:: error_str)
80
+ }
81
+ } else {
82
+ fn os_err_desc( _errno: i32 , _buf: & mut [ u8 ] ) -> Option <& str > {
83
+ None
84
+ }
85
+ }
79
86
}
80
87
81
88
impl fmt:: Debug for Error {
0 commit comments