@@ -137,24 +137,33 @@ impl OwnedFd {
137
137
pub fn try_clone ( & self ) -> std:: io:: Result < Self > {
138
138
#[ cfg( feature = "close" ) ]
139
139
{
140
- // We want to atomically duplicate this file descriptor and set the
141
- // CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This
142
- // is a POSIX flag that was added to Linux in 2.6.24.
143
- #[ cfg( not( target_os = "espidf" ) ) ]
144
- let cmd = libc:: F_DUPFD_CLOEXEC ;
145
-
146
- // For ESP-IDF, F_DUPFD is used instead, because the CLOEXEC semantics
147
- // will never be supported, as this is a bare metal framework with
148
- // no capabilities for multi-process execution. While F_DUPFD is also
149
- // not supported yet, it might be (currently it returns ENOSYS).
150
- #[ cfg( target_os = "espidf" ) ]
151
- let cmd = libc:: F_DUPFD ;
152
-
153
- let fd = match unsafe { libc:: fcntl ( self . as_raw_fd ( ) , cmd, 0 ) } {
154
- -1 => return Err ( std:: io:: Error :: last_os_error ( ) ) ,
155
- fd => fd,
156
- } ;
157
- Ok ( unsafe { Self :: from_raw_fd ( fd) } )
140
+ #[ cfg( unix) ]
141
+ {
142
+ // We want to atomically duplicate this file descriptor and set the
143
+ // CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This
144
+ // is a POSIX flag that was added to Linux in 2.6.24.
145
+ #[ cfg( not( target_os = "espidf" ) ) ]
146
+ let cmd = libc:: F_DUPFD_CLOEXEC ;
147
+
148
+ // For ESP-IDF, F_DUPFD is used instead, because the CLOEXEC semantics
149
+ // will never be supported, as this is a bare metal framework with
150
+ // no capabilities for multi-process execution. While F_DUPFD is also
151
+ // not supported yet, it might be (currently it returns ENOSYS).
152
+ #[ cfg( target_os = "espidf" ) ]
153
+ let cmd = libc:: F_DUPFD ;
154
+
155
+ let fd = match unsafe { libc:: fcntl ( self . as_raw_fd ( ) , cmd, 0 ) } {
156
+ -1 => return Err ( std:: io:: Error :: last_os_error ( ) ) ,
157
+ fd => fd,
158
+ } ;
159
+
160
+ Ok ( unsafe { Self :: from_raw_fd ( fd) } )
161
+ }
162
+
163
+ #[ cfg( target_os = "wasi" ) ]
164
+ {
165
+ unreachable ! ( "try_clone is not yet suppported on wasi" ) ;
166
+ }
158
167
}
159
168
160
169
// If the `close` feature is disabled, we expect users to avoid cloning
0 commit comments