@@ -130,18 +130,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
130
130
let size = this. read_scalar ( size_op) ?. to_usize ( & * this. tcx ) ?;
131
131
// If we cannot get the current directory, we return null
132
132
// FIXME: Technically we have to set the `errno` global too
133
- if let Ok ( cwd) = env:: current_dir ( ) {
134
- // It is not clear what happens with non-utf8 paths here
135
- let mut bytes = cwd. display ( ) . to_string ( ) . into_bytes ( ) ;
136
- // If the buffer is smaller or equal than the path, we return null.
137
- // FIXME: Technically we have to set the `errno` global too
138
- if ( bytes. len ( ) as u64 ) < size {
139
- // We add a `/0` terminator
140
- bytes. push ( 0 ) ;
141
- // This is ok because the buffer is larger than the path with the null terminator.
142
- this. memory_mut ( ) . get_mut ( buf. alloc_id ) ?. write_bytes ( tcx, buf, & bytes) ?;
143
- return Ok ( Scalar :: Ptr ( buf) )
133
+ match env:: current_dir ( ) {
134
+ Ok ( cwd) =>{
135
+ // It is not clear what happens with non-utf8 paths here
136
+ let mut bytes = cwd. display ( ) . to_string ( ) . into_bytes ( ) ;
137
+ // If the buffer is smaller or equal than the path, we return null.
138
+ if ( bytes. len ( ) as u64 ) < size {
139
+ // We add a `/0` terminator
140
+ bytes. push ( 0 ) ;
141
+ // This is ok because the buffer is larger than the path with the null terminator.
142
+ this. memory_mut ( ) . get_mut ( buf. alloc_id ) ?. write_bytes ( tcx, buf, & bytes) ?;
143
+ return Ok ( Scalar :: Ptr ( buf) )
144
+ }
145
+ this. machine . last_error = 34 ; // ERANGE
144
146
}
147
+ Err ( e) => this. machine . last_error = e. raw_os_error ( ) . unwrap ( ) as u32 ,
145
148
}
146
149
Ok ( Scalar :: ptr_null ( & * this. tcx ) )
147
150
}
0 commit comments