33#![ stable( feature = "io_safety" ,  since = "1.63.0" ) ]  
44#![ deny( unsafe_op_in_unsafe_fn) ]  
55
6+ #[ cfg( target_os = "motor" ) ]  
7+ use  moto_rt:: libc; 
8+ 
69use  super :: raw:: { AsRawFd ,  FromRawFd ,  IntoRawFd ,  RawFd } ; 
710#[ cfg( not( target_os = "trusty" ) ) ]  
811use  crate :: fs; 
@@ -12,7 +15,8 @@ use crate::mem::ManuallyDrop;
1215    target_arch = "wasm32" ,  
1316    target_env = "sgx" ,  
1417    target_os = "hermit" ,  
15-     target_os = "trusty"  
18+     target_os = "trusty" ,  
19+     target_os = "motor"  
1620) ) ) ] 
1721use  crate :: sys:: cvt; 
1822#[ cfg( not( target_os = "trusty" ) ) ]  
@@ -95,7 +99,12 @@ impl OwnedFd {
9599impl  BorrowedFd < ' _ >  { 
96100    /// Creates a new `OwnedFd` instance that shares the same underlying file 
97101/// description as the existing `BorrowedFd` instance. 
98- #[ cfg( not( any( target_arch = "wasm32" ,  target_os = "hermit" ,  target_os = "trusty" ) ) ) ]  
102+ #[ cfg( not( any(  
103+         target_arch = "wasm32" ,  
104+         target_os = "hermit" ,  
105+         target_os = "trusty" ,  
106+         target_os = "motor"  
107+     ) ) ) ]  
99108    #[ stable( feature = "io_safety" ,  since = "1.63.0" ) ]  
100109    pub  fn  try_clone_to_owned ( & self )  -> crate :: io:: Result < OwnedFd >  { 
101110        // We want to atomically duplicate this file descriptor and set the 
@@ -123,6 +132,15 @@ impl BorrowedFd<'_> {
123132    pub  fn  try_clone_to_owned ( & self )  -> crate :: io:: Result < OwnedFd >  { 
124133        Err ( crate :: io:: Error :: UNSUPPORTED_PLATFORM ) 
125134    } 
135+ 
136+     /// Creates a new `OwnedFd` instance that shares the same underlying file 
137+ /// description as the existing `BorrowedFd` instance. 
138+ #[ cfg( target_os = "motor" ) ]  
139+     #[ stable( feature = "io_safety" ,  since = "1.63.0" ) ]  
140+     pub  fn  try_clone_to_owned ( & self )  -> crate :: io:: Result < OwnedFd >  { 
141+         let  fd = moto_rt:: fs:: duplicate ( self . as_raw_fd ( ) ) . map_err ( crate :: sys:: map_motor_error) ?; 
142+         Ok ( unsafe  {  OwnedFd :: from_raw_fd ( fd)  } ) 
143+     } 
126144} 
127145
128146#[ stable( feature = "io_safety" ,  since = "1.63.0" ) ]  
0 commit comments