1- use super :: abi:: {
1+ use super :: fd:: FileDesc ;
2+ use super :: hermit_abi:: {
23 self , dirent64, stat as stat_struct, DT_DIR , DT_LNK , DT_REG , DT_UNKNOWN , O_APPEND , O_CREAT ,
34 O_EXCL , O_RDONLY , O_RDWR , O_TRUNC , O_WRONLY , S_IFDIR , S_IFLNK , S_IFMT , S_IFREG ,
45} ;
5- use super :: fd:: FileDesc ;
66use crate :: ffi:: { CStr , OsStr , OsString } ;
77use crate :: fmt;
88use crate :: io:: { self , Error , ErrorKind } ;
@@ -206,9 +206,7 @@ impl Iterator for ReadDir {
206206 return None ;
207207 }
208208
209- let dir = unsafe {
210- & * ( self . inner . dir . as_ptr ( ) . add ( offset) as * const dirent64 )
211- } ;
209+ let dir = unsafe { & * ( self . inner . dir . as_ptr ( ) . add ( offset) as * const dirent64 ) } ;
212210
213211 if counter == self . pos {
214212 self . pos += 1 ;
@@ -217,9 +215,8 @@ impl Iterator for ReadDir {
217215 // plus the length of the file name. Consequently, file name has a size of d_reclen minus
218216 // the size of dirent64. The file name is always a C string and terminated by `\0`.
219217 // Consequently, we are able to ignore the last byte.
220- let name_bytes = unsafe {
221- CStr :: from_ptr ( & dir. d_name as * const _ as * const i8 ) . to_bytes ( )
222- } ;
218+ let name_bytes =
219+ unsafe { CStr :: from_ptr ( & dir. d_name as * const _ as * const i8 ) . to_bytes ( ) } ;
223220 let entry = DirEntry {
224221 root : self . inner . root . clone ( ) ,
225222 ino : dir. d_ino ,
@@ -361,7 +358,7 @@ impl File {
361358 mode = 0 ;
362359 }
363360
364- let fd = unsafe { cvt ( abi :: open ( path. as_ptr ( ) , flags, mode) ) ? } ;
361+ let fd = unsafe { cvt ( hermit_abi :: open ( path. as_ptr ( ) , flags, mode) ) ? } ;
365362 Ok ( File ( unsafe { FileDesc :: from_raw_fd ( fd as i32 ) } ) )
366363 }
367364
@@ -442,7 +439,7 @@ impl DirBuilder {
442439
443440 pub fn mkdir ( & self , path : & Path ) -> io:: Result < ( ) > {
444441 run_path_with_cstr ( path, & |path| {
445- cvt ( unsafe { abi :: mkdir ( path. as_ptr ( ) , self . mode ) } ) . map ( |_| ( ) )
442+ cvt ( unsafe { hermit_abi :: mkdir ( path. as_ptr ( ) , self . mode ) } ) . map ( |_| ( ) )
446443 } )
447444 }
448445
@@ -504,7 +501,8 @@ impl FromRawFd for File {
504501}
505502
506503pub fn readdir ( path : & Path ) -> io:: Result < ReadDir > {
507- let fd_raw = run_path_with_cstr ( path, & |path| cvt ( unsafe { abi:: opendir ( path. as_ptr ( ) ) } ) ) ?;
504+ let fd_raw =
505+ run_path_with_cstr ( path, & |path| cvt ( unsafe { hermit_abi:: opendir ( path. as_ptr ( ) ) } ) ) ?;
508506 let fd = unsafe { FileDesc :: from_raw_fd ( fd_raw as i32 ) } ;
509507 let root = path. to_path_buf ( ) ;
510508
@@ -515,8 +513,9 @@ pub fn readdir(path: &Path) -> io::Result<ReadDir> {
515513 // reserve memory to receive all directory entries
516514 vec. resize ( sz, 0 ) ;
517515
518- let readlen =
519- unsafe { abi:: getdents64 ( fd. as_raw_fd ( ) , vec. as_mut_ptr ( ) as * mut dirent64 , sz) } ;
516+ let readlen = unsafe {
517+ hermit_abi:: getdents64 ( fd. as_raw_fd ( ) , vec. as_mut_ptr ( ) as * mut dirent64 , sz)
518+ } ;
520519 if readlen > 0 {
521520 // shrink down to the minimal size
522521 vec. resize ( readlen. try_into ( ) . unwrap ( ) , 0 ) ;
@@ -525,7 +524,7 @@ pub fn readdir(path: &Path) -> io::Result<ReadDir> {
525524
526525 // if the buffer is too small, getdents64 returns EINVAL
527526 // otherwise, getdents64 returns an error number
528- if readlen != ( -abi :: errno:: EINVAL ) . into ( ) {
527+ if readlen != ( -hermit_abi :: errno:: EINVAL ) . into ( ) {
529528 return Err ( Error :: from_raw_os_error ( readlen. try_into ( ) . unwrap ( ) ) ) ;
530529 }
531530
@@ -543,7 +542,7 @@ pub fn readdir(path: &Path) -> io::Result<ReadDir> {
543542}
544543
545544pub fn unlink ( path : & Path ) -> io:: Result < ( ) > {
546- run_path_with_cstr ( path, & |path| cvt ( unsafe { abi :: unlink ( path. as_ptr ( ) ) } ) . map ( |_| ( ) ) )
545+ run_path_with_cstr ( path, & |path| cvt ( unsafe { hermit_abi :: unlink ( path. as_ptr ( ) ) } ) . map ( |_| ( ) ) )
547546}
548547
549548pub fn rename ( _old : & Path , _new : & Path ) -> io:: Result < ( ) > {
@@ -555,7 +554,7 @@ pub fn set_perm(_p: &Path, _perm: FilePermissions) -> io::Result<()> {
555554}
556555
557556pub fn rmdir ( path : & Path ) -> io:: Result < ( ) > {
558- run_path_with_cstr ( path, & |path| cvt ( unsafe { abi :: rmdir ( path. as_ptr ( ) ) } ) . map ( |_| ( ) ) )
557+ run_path_with_cstr ( path, & |path| cvt ( unsafe { hermit_abi :: rmdir ( path. as_ptr ( ) ) } ) . map ( |_| ( ) ) )
559558}
560559
561560pub fn remove_dir_all ( _path : & Path ) -> io:: Result < ( ) > {
@@ -577,15 +576,15 @@ pub fn link(_original: &Path, _link: &Path) -> io::Result<()> {
577576pub fn stat ( path : & Path ) -> io:: Result < FileAttr > {
578577 run_path_with_cstr ( path, & |path| {
579578 let mut stat_val: stat_struct = unsafe { mem:: zeroed ( ) } ;
580- cvt ( unsafe { abi :: stat ( path. as_ptr ( ) , & mut stat_val) } ) ?;
579+ cvt ( unsafe { hermit_abi :: stat ( path. as_ptr ( ) , & mut stat_val) } ) ?;
581580 Ok ( FileAttr :: from_stat ( stat_val) )
582581 } )
583582}
584583
585584pub fn lstat ( path : & Path ) -> io:: Result < FileAttr > {
586585 run_path_with_cstr ( path, & |path| {
587586 let mut stat_val: stat_struct = unsafe { mem:: zeroed ( ) } ;
588- cvt ( unsafe { abi :: lstat ( path. as_ptr ( ) , & mut stat_val) } ) ?;
587+ cvt ( unsafe { hermit_abi :: lstat ( path. as_ptr ( ) , & mut stat_val) } ) ?;
589588 Ok ( FileAttr :: from_stat ( stat_val) )
590589 } )
591590}
0 commit comments