@@ -676,8 +676,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
676
676
677
677
// `stat` always follows symlinks.
678
678
let metadata = match FileMetadata :: from_path ( this, & path, true ) ? {
679
- Some ( metadata) => metadata,
680
- None => return this. write_int ( - 1 , dest) , // `FileMetadata` has set errno
679
+ Ok ( metadata) => metadata,
680
+ Err ( e ) => return this. set_last_err_and_return_neg1 ( e , dest) ,
681
681
} ;
682
682
let res = this. macos_stat_write_buf ( metadata, buf_op) ?;
683
683
this. write_int ( res, dest)
@@ -706,8 +706,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
706
706
}
707
707
708
708
let metadata = match FileMetadata :: from_path ( this, & path, false ) ? {
709
- Some ( metadata) => metadata,
710
- None => return this. write_int ( - 1 , dest) , // `FileMetadata` has set errno
709
+ Ok ( metadata) => metadata,
710
+ Err ( e ) => return this. set_last_err_and_return_neg1 ( e , dest) ,
711
711
} ;
712
712
let res = this. macos_stat_write_buf ( metadata, buf_op) ?;
713
713
this. write_int ( res, dest)
@@ -734,8 +734,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
734
734
}
735
735
736
736
let metadata = match FileMetadata :: from_fd_num ( this, fd) ? {
737
- Some ( metadata) => metadata,
738
- None => return this. write_int ( - 1 , dest) , // `FileMetadata` has set errno
737
+ Ok ( metadata) => metadata,
738
+ Err ( e ) => return this. set_last_err_and_return_neg1 ( e , dest) ,
739
739
} ;
740
740
let res = this. macos_stat_write_buf ( metadata, buf_op) ?;
741
741
this. write_int ( res, dest)
@@ -824,8 +824,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
824
824
FileMetadata :: from_path ( this, & path, follow_symlink) ?
825
825
} ;
826
826
let metadata = match metadata {
827
- Some ( metadata) => metadata,
828
- None => return this. write_int ( - 1 , dest) ,
827
+ Ok ( metadata) => metadata,
828
+ Err ( e ) => return this. set_last_err_and_return_neg1 ( e , dest) ,
829
829
} ;
830
830
831
831
// The `mode` field specifies the type of the file and the permissions over the file for
@@ -1699,7 +1699,7 @@ impl FileMetadata {
1699
1699
ecx : & mut MiriInterpCx < ' tcx > ,
1700
1700
path : & Path ,
1701
1701
follow_symlink : bool ,
1702
- ) -> InterpResult < ' tcx , Option < FileMetadata > > {
1702
+ ) -> InterpResult < ' tcx , Result < FileMetadata , Scalar > > {
1703
1703
let metadata =
1704
1704
if follow_symlink { std:: fs:: metadata ( path) } else { std:: fs:: symlink_metadata ( path) } ;
1705
1705
@@ -1709,9 +1709,9 @@ impl FileMetadata {
1709
1709
fn from_fd_num < ' tcx > (
1710
1710
ecx : & mut MiriInterpCx < ' tcx > ,
1711
1711
fd_num : i32 ,
1712
- ) -> InterpResult < ' tcx , Option < FileMetadata > > {
1712
+ ) -> InterpResult < ' tcx , Result < FileMetadata , Scalar > > {
1713
1713
let Some ( fd) = ecx. machine . fds . get ( fd_num) else {
1714
- return ecx. fd_not_found ( ) . map ( |_ : i32 | None ) ;
1714
+ return Ok ( Err ( ecx. eval_libc ( "EBADF" ) ) ) ;
1715
1715
} ;
1716
1716
1717
1717
let file = & fd
@@ -1731,12 +1731,11 @@ impl FileMetadata {
1731
1731
fn from_meta < ' tcx > (
1732
1732
ecx : & mut MiriInterpCx < ' tcx > ,
1733
1733
metadata : Result < std:: fs:: Metadata , std:: io:: Error > ,
1734
- ) -> InterpResult < ' tcx , Option < FileMetadata > > {
1734
+ ) -> InterpResult < ' tcx , Result < FileMetadata , Scalar > > {
1735
1735
let metadata = match metadata {
1736
1736
Ok ( metadata) => metadata,
1737
1737
Err ( e) => {
1738
- ecx. set_last_error_from_io_error ( e) ?;
1739
- return Ok ( None ) ;
1738
+ return Ok ( Err ( ecx. io_error_to_errnum ( e) ?) ) ;
1740
1739
}
1741
1740
} ;
1742
1741
@@ -1759,6 +1758,6 @@ impl FileMetadata {
1759
1758
let modified = extract_sec_and_nsec ( metadata. modified ( ) ) ?;
1760
1759
1761
1760
// FIXME: Provide more fields using platform specific methods.
1762
- Ok ( Some ( FileMetadata { mode, size, created, accessed, modified } ) )
1761
+ Ok ( Ok ( FileMetadata { mode, size, created, accessed, modified } ) )
1763
1762
}
1764
1763
}
0 commit comments