1- use super :: get_file_type;
21use super :: oshandle:: RawOsHandle ;
3- use crate :: handle:: { Handle , HandleRights } ;
2+ use super :: { get_file_type, get_rights} ;
3+ use crate :: handle:: Handle ;
44use crate :: sys:: osother:: { OsOther , OsOtherExt } ;
5- use crate :: wasi:: { types, RightsExt } ;
5+ use crate :: wasi:: types;
66use std:: convert:: TryFrom ;
77use std:: fs:: { File , OpenOptions } ;
88use std:: io;
9- use std:: os:: unix:: prelude:: { AsRawFd , FromRawFd , IntoRawFd } ;
9+ use std:: os:: unix:: prelude:: { FromRawFd , IntoRawFd } ;
1010
1111impl TryFrom < File > for OsOther {
1212 type Error = io:: Error ;
@@ -22,45 +22,6 @@ impl TryFrom<File> for OsOther {
2222 }
2323}
2424
25- fn get_rights ( file : & File , file_type : & types:: Filetype ) -> io:: Result < HandleRights > {
26- use yanix:: { fcntl, file:: OFlag } ;
27- let ( base, inheriting) = match file_type {
28- types:: Filetype :: BlockDevice => (
29- types:: Rights :: block_device_base ( ) ,
30- types:: Rights :: block_device_inheriting ( ) ,
31- ) ,
32- types:: Filetype :: CharacterDevice => {
33- use yanix:: file:: isatty;
34- if unsafe { isatty ( file. as_raw_fd ( ) ) ? } {
35- ( types:: Rights :: tty_base ( ) , types:: Rights :: tty_base ( ) )
36- } else {
37- (
38- types:: Rights :: character_device_base ( ) ,
39- types:: Rights :: character_device_inheriting ( ) ,
40- )
41- }
42- }
43- types:: Filetype :: SocketDgram | types:: Filetype :: SocketStream => (
44- types:: Rights :: socket_base ( ) ,
45- types:: Rights :: socket_inheriting ( ) ,
46- ) ,
47- types:: Filetype :: SymbolicLink | types:: Filetype :: Unknown => (
48- types:: Rights :: regular_file_base ( ) ,
49- types:: Rights :: regular_file_inheriting ( ) ,
50- ) ,
51- _ => unreachable ! ( "these should have been handled already!" ) ,
52- } ;
53- let mut rights = HandleRights :: new ( base, inheriting) ;
54- let flags = unsafe { fcntl:: get_status_flags ( file. as_raw_fd ( ) ) ? } ;
55- let accmode = flags & OFlag :: ACCMODE ;
56- if accmode == OFlag :: RDONLY {
57- rights. base &= !types:: Rights :: FD_WRITE ;
58- } else if accmode == OFlag :: WRONLY {
59- rights. base &= !types:: Rights :: FD_READ ;
60- }
61- Ok ( rights)
62- }
63-
6425impl OsOtherExt for OsOther {
6526 fn from_null ( ) -> io:: Result < Box < dyn Handle > > {
6627 let file = OpenOptions :: new ( )
0 commit comments