@@ -23,6 +23,17 @@ pub struct FileHandler {
23
23
low : i32 ,
24
24
}
25
25
26
+ impl FileHandler {
27
+ fn next_fd ( & self ) -> i32 {
28
+ self . low + 1
29
+ }
30
+
31
+ fn register_fd ( & mut self , fd : i32 , handle : FileHandle ) {
32
+ self . low = fd;
33
+ self . handles . insert ( fd, handle) . unwrap_none ( ) ;
34
+ }
35
+ }
36
+
26
37
impl Default for FileHandler {
27
38
fn default ( ) -> Self {
28
39
FileHandler {
@@ -107,10 +118,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
107
118
let path = this. read_os_str_from_c_str ( this. read_scalar ( path_op) ?. not_undef ( ) ?) ?;
108
119
109
120
let fd = options. open ( & path) . map ( |file| {
110
- let mut fh = & mut this. machine . file_handler ;
111
- fh . low += 1 ;
112
- fh. handles . insert ( fh . low , FileHandle { file, writable } ) . unwrap_none ( ) ;
113
- fh . low
121
+ let fh = & mut this. machine . file_handler ;
122
+ let fd = fh . next_fd ( ) ;
123
+ fh. register_fd ( fd , FileHandle { file, writable } ) ;
124
+ fd
114
125
} ) ;
115
126
116
127
this. try_unwrap_io_result ( fd)
@@ -153,9 +164,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
153
164
None => return this. handle_not_found ( ) ,
154
165
} ;
155
166
let fd_result = file_result. map ( |duplicated| {
156
- let new_fd = std:: cmp:: max ( fh. low + 1 , arg) ;
157
- fh. low = new_fd;
158
- fh. handles . insert ( fh. low , FileHandle { file : duplicated, writable } ) . unwrap_none ( ) ;
167
+ let new_fd = std:: cmp:: max ( fh. next_fd ( ) , arg) ;
168
+ fh. register_fd ( new_fd, FileHandle { file : duplicated, writable } ) ;
159
169
new_fd
160
170
} ) ;
161
171
this. try_unwrap_io_result ( fd_result)
0 commit comments