@@ -364,7 +364,7 @@ impl OpenOptions {
364364
365365impl File {
366366 pub fn open ( path : & Path , opts : & OpenOptions ) -> io:: Result < File > {
367- let ( dir, file) = open_parent ( path, wasi :: RIGHTS_PATH_OPEN ) ?;
367+ let ( dir, file) = open_parent ( path) ?;
368368 open_at ( & dir, & file, opts)
369369 }
370370
@@ -452,7 +452,7 @@ impl DirBuilder {
452452 }
453453
454454 pub fn mkdir ( & self , p : & Path ) -> io:: Result < ( ) > {
455- let ( dir, file) = open_parent ( p, wasi :: RIGHTS_PATH_CREATE_DIRECTORY ) ?;
455+ let ( dir, file) = open_parent ( p) ?;
456456 dir. create_directory ( osstr2str ( file. as_ref ( ) ) ?)
457457 }
458458}
@@ -478,13 +478,13 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> {
478478}
479479
480480pub fn unlink ( p : & Path ) -> io:: Result < ( ) > {
481- let ( dir, file) = open_parent ( p, wasi :: RIGHTS_PATH_UNLINK_FILE ) ?;
481+ let ( dir, file) = open_parent ( p) ?;
482482 dir. unlink_file ( osstr2str ( file. as_ref ( ) ) ?)
483483}
484484
485485pub fn rename ( old : & Path , new : & Path ) -> io:: Result < ( ) > {
486- let ( old, old_file) = open_parent ( old, wasi :: RIGHTS_PATH_RENAME_SOURCE ) ?;
487- let ( new, new_file) = open_parent ( new, wasi :: RIGHTS_PATH_RENAME_TARGET ) ?;
486+ let ( old, old_file) = open_parent ( old) ?;
487+ let ( new, new_file) = open_parent ( new) ?;
488488 old. rename ( osstr2str ( old_file. as_ref ( ) ) ?, & new, osstr2str ( new_file. as_ref ( ) ) ?)
489489}
490490
@@ -495,12 +495,12 @@ pub fn set_perm(_p: &Path, _perm: FilePermissions) -> io::Result<()> {
495495}
496496
497497pub fn rmdir ( p : & Path ) -> io:: Result < ( ) > {
498- let ( dir, file) = open_parent ( p, wasi :: RIGHTS_PATH_REMOVE_DIRECTORY ) ?;
498+ let ( dir, file) = open_parent ( p) ?;
499499 dir. remove_directory ( osstr2str ( file. as_ref ( ) ) ?)
500500}
501501
502502pub fn readlink ( p : & Path ) -> io:: Result < PathBuf > {
503- let ( dir, file) = open_parent ( p, wasi :: RIGHTS_PATH_READLINK ) ?;
503+ let ( dir, file) = open_parent ( p) ?;
504504 read_link ( & dir, & file)
505505}
506506
@@ -536,13 +536,13 @@ fn read_link(fd: &WasiFd, file: &Path) -> io::Result<PathBuf> {
536536}
537537
538538pub fn symlink ( src : & Path , dst : & Path ) -> io:: Result < ( ) > {
539- let ( dst, dst_file) = open_parent ( dst, wasi :: RIGHTS_PATH_SYMLINK ) ?;
539+ let ( dst, dst_file) = open_parent ( dst) ?;
540540 dst. symlink ( osstr2str ( src. as_ref ( ) ) ?, osstr2str ( dst_file. as_ref ( ) ) ?)
541541}
542542
543543pub fn link ( src : & Path , dst : & Path ) -> io:: Result < ( ) > {
544- let ( src, src_file) = open_parent ( src, wasi :: RIGHTS_PATH_LINK_SOURCE ) ?;
545- let ( dst, dst_file) = open_parent ( dst, wasi :: RIGHTS_PATH_LINK_TARGET ) ?;
544+ let ( src, src_file) = open_parent ( src) ?;
545+ let ( dst, dst_file) = open_parent ( dst) ?;
546546 src. link (
547547 wasi:: LOOKUPFLAGS_SYMLINK_FOLLOW ,
548548 osstr2str ( src_file. as_ref ( ) ) ?,
@@ -552,12 +552,12 @@ pub fn link(src: &Path, dst: &Path) -> io::Result<()> {
552552}
553553
554554pub fn stat ( p : & Path ) -> io:: Result < FileAttr > {
555- let ( dir, file) = open_parent ( p, wasi :: RIGHTS_PATH_FILESTAT_GET ) ?;
555+ let ( dir, file) = open_parent ( p) ?;
556556 metadata_at ( & dir, wasi:: LOOKUPFLAGS_SYMLINK_FOLLOW , & file)
557557}
558558
559559pub fn lstat ( p : & Path ) -> io:: Result < FileAttr > {
560- let ( dir, file) = open_parent ( p, wasi :: RIGHTS_PATH_FILESTAT_GET ) ?;
560+ let ( dir, file) = open_parent ( p) ?;
561561 metadata_at ( & dir, 0 , & file)
562562}
563563
@@ -611,11 +611,11 @@ fn open_at(fd: &WasiFd, path: &Path, opts: &OpenOptions) -> io::Result<File> {
611611///
612612/// Note that this can fail if `p` doesn't look like it can be opened relative
613613/// to any preopened file descriptor.
614- fn open_parent ( p : & Path , rights : wasi :: Rights ) -> io:: Result < ( ManuallyDrop < WasiFd > , PathBuf ) > {
614+ fn open_parent ( p : & Path ) -> io:: Result < ( ManuallyDrop < WasiFd > , PathBuf ) > {
615615 let p = CString :: new ( p. as_os_str ( ) . as_bytes ( ) ) ?;
616616 unsafe {
617617 let mut ret = ptr:: null ( ) ;
618- let fd = libc :: __wasilibc_find_relpath ( p. as_ptr ( ) , rights , 0 , & mut ret) ;
618+ let fd = __wasilibc_find_relpath ( p. as_ptr ( ) , & mut ret) ;
619619 if fd == -1 {
620620 let msg = format ! (
621621 "failed to find a preopened file descriptor \
@@ -635,6 +635,13 @@ fn open_parent(p: &Path, rights: wasi::Rights) -> io::Result<(ManuallyDrop<WasiF
635635
636636 return Ok ( ( ManuallyDrop :: new ( WasiFd :: from_raw ( fd as u32 ) ) , path) ) ;
637637 }
638+
639+ extern "C" {
640+ pub fn __wasilibc_find_relpath (
641+ path : * const libc:: c_char ,
642+ relative_path : * mut * const libc:: c_char ,
643+ ) -> libc:: c_int ;
644+ }
638645}
639646
640647pub fn osstr2str ( f : & OsStr ) -> io:: Result < & str > {
0 commit comments