@@ -22,7 +22,7 @@ use input::{
2222 keyboard:: { KeyboardEvent , KeyboardEventTrait , KeyState }
2323 }
2424} ;
25- use libc:: { O_RDONLY , O_RDWR , O_WRONLY , c_char} ;
25+ use libc:: { O_ACCMODE , O_RDONLY , O_RDWR , O_WRONLY , c_char} ;
2626use input_linux:: { uinput:: UInputHandle , EventKind , Key , SynchronizeKind } ;
2727use input_linux_sys:: { uinput_setup, input_id, timeval, input_event} ;
2828use nix:: poll:: { poll, PollFd , PollFlags } ;
@@ -152,10 +152,12 @@ struct Interface;
152152
153153impl LibinputInterface for Interface {
154154 fn open_restricted ( & mut self , path : & Path , flags : i32 ) -> Result < OwnedFd , i32 > {
155+ let mode = flags & O_ACCMODE ;
156+
155157 OpenOptions :: new ( )
156158 . custom_flags ( flags)
157- . read ( ( flags & O_RDONLY != 0 ) | ( flags & O_RDWR != 0 ) )
158- . write ( ( flags & O_WRONLY != 0 ) | ( flags & O_RDWR != 0 ) )
159+ . read ( mode == O_RDONLY || mode == O_RDWR )
160+ . write ( mode == O_WRONLY || mode == O_RDWR )
159161 . open ( path)
160162 . map ( |file| file. into ( ) )
161163 . map_err ( |err| err. raw_os_error ( ) . unwrap ( ) )
0 commit comments