1
- use super :: abi:: {
1
+ use super :: fd:: FileDesc ;
2
+ use super :: hermit_abi:: {
2
3
self , dirent64, stat as stat_struct, DT_DIR , DT_LNK , DT_REG , DT_UNKNOWN , O_APPEND , O_CREAT ,
3
4
O_EXCL , O_RDONLY , O_RDWR , O_TRUNC , O_WRONLY , S_IFDIR , S_IFLNK , S_IFMT , S_IFREG ,
4
5
} ;
5
- use super :: fd:: FileDesc ;
6
6
use crate :: ffi:: { CStr , OsStr , OsString } ;
7
7
use crate :: fmt;
8
8
use crate :: io:: { self , Error , ErrorKind } ;
@@ -206,9 +206,7 @@ impl Iterator for ReadDir {
206
206
return None ;
207
207
}
208
208
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 ) } ;
212
210
213
211
if counter == self . pos {
214
212
self . pos += 1 ;
@@ -217,9 +215,8 @@ impl Iterator for ReadDir {
217
215
// plus the length of the file name. Consequently, file name has a size of d_reclen minus
218
216
// the size of dirent64. The file name is always a C string and terminated by `\0`.
219
217
// 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 ( ) } ;
223
220
let entry = DirEntry {
224
221
root : self . inner . root . clone ( ) ,
225
222
ino : dir. d_ino ,
@@ -361,7 +358,7 @@ impl File {
361
358
mode = 0 ;
362
359
}
363
360
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) ) ? } ;
365
362
Ok ( File ( unsafe { FileDesc :: from_raw_fd ( fd as i32 ) } ) )
366
363
}
367
364
@@ -442,7 +439,7 @@ impl DirBuilder {
442
439
443
440
pub fn mkdir ( & self , path : & Path ) -> io:: Result < ( ) > {
444
441
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 ( |_| ( ) )
446
443
} )
447
444
}
448
445
@@ -504,7 +501,8 @@ impl FromRawFd for File {
504
501
}
505
502
506
503
pub 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 ( ) ) } ) ) ?;
508
506
let fd = unsafe { FileDesc :: from_raw_fd ( fd_raw as i32 ) } ;
509
507
let root = path. to_path_buf ( ) ;
510
508
@@ -515,8 +513,9 @@ pub fn readdir(path: &Path) -> io::Result<ReadDir> {
515
513
// reserve memory to receive all directory entries
516
514
vec. resize ( sz, 0 ) ;
517
515
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
+ } ;
520
519
if readlen > 0 {
521
520
// shrink down to the minimal size
522
521
vec. resize ( readlen. try_into ( ) . unwrap ( ) , 0 ) ;
@@ -525,7 +524,7 @@ pub fn readdir(path: &Path) -> io::Result<ReadDir> {
525
524
526
525
// if the buffer is too small, getdents64 returns EINVAL
527
526
// otherwise, getdents64 returns an error number
528
- if readlen != ( -abi :: errno:: EINVAL ) . into ( ) {
527
+ if readlen != ( -hermit_abi :: errno:: EINVAL ) . into ( ) {
529
528
return Err ( Error :: from_raw_os_error ( readlen. try_into ( ) . unwrap ( ) ) ) ;
530
529
}
531
530
@@ -543,7 +542,7 @@ pub fn readdir(path: &Path) -> io::Result<ReadDir> {
543
542
}
544
543
545
544
pub 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 ( |_| ( ) ) )
547
546
}
548
547
549
548
pub fn rename ( _old : & Path , _new : & Path ) -> io:: Result < ( ) > {
@@ -555,7 +554,7 @@ pub fn set_perm(_p: &Path, _perm: FilePermissions) -> io::Result<()> {
555
554
}
556
555
557
556
pub 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 ( |_| ( ) ) )
559
558
}
560
559
561
560
pub fn remove_dir_all ( _path : & Path ) -> io:: Result < ( ) > {
@@ -577,15 +576,15 @@ pub fn link(_original: &Path, _link: &Path) -> io::Result<()> {
577
576
pub fn stat ( path : & Path ) -> io:: Result < FileAttr > {
578
577
run_path_with_cstr ( path, & |path| {
579
578
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) } ) ?;
581
580
Ok ( FileAttr :: from_stat ( stat_val) )
582
581
} )
583
582
}
584
583
585
584
pub fn lstat ( path : & Path ) -> io:: Result < FileAttr > {
586
585
run_path_with_cstr ( path, & |path| {
587
586
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) } ) ?;
589
588
Ok ( FileAttr :: from_stat ( stat_val) )
590
589
} )
591
590
}
0 commit comments