@@ -945,14 +945,26 @@ pub unsafe extern "C" fn path_remove_directory(
945
945
/// Note: This is similar to `renameat` in POSIX.
946
946
#[ no_mangle]
947
947
pub unsafe extern "C" fn path_rename (
948
- fd : Fd ,
948
+ old_fd : Fd ,
949
949
old_path_ptr : * const u8 ,
950
950
old_path_len : usize ,
951
951
new_fd : Fd ,
952
952
new_path_ptr : * const u8 ,
953
953
new_path_len : usize ,
954
954
) -> Errno {
955
- unreachable ( )
955
+ let old_path = slice:: from_raw_parts ( old_path_ptr, old_path_len) ;
956
+ let new_path = slice:: from_raw_parts ( new_path_ptr, new_path_len) ;
957
+
958
+ match ( Descriptor :: get ( old_fd) , Descriptor :: get ( new_fd) ) {
959
+ ( Descriptor :: File ( old_file) , Descriptor :: File ( new_file) ) => {
960
+ match wasi_filesystem:: rename_at ( old_file. fd , old_path, new_file. fd , new_path) {
961
+ Ok ( ( ) ) => ERRNO_SUCCESS ,
962
+ Err ( err) => errno_from_wasi_filesystem ( err) ,
963
+ }
964
+ }
965
+ ( _, Descriptor :: Closed ) | ( Descriptor :: Closed , _) => ERRNO_BADF ,
966
+ _ => ERRNO_NOTDIR ,
967
+ }
956
968
}
957
969
958
970
/// Create a symbolic link.
@@ -965,15 +977,34 @@ pub unsafe extern "C" fn path_symlink(
965
977
new_path_ptr : * const u8 ,
966
978
new_path_len : usize ,
967
979
) -> Errno {
968
- unreachable ( )
980
+ let old_path = slice:: from_raw_parts ( old_path_ptr, old_path_len) ;
981
+ let new_path = slice:: from_raw_parts ( new_path_ptr, new_path_len) ;
982
+
983
+ match Descriptor :: get ( fd) {
984
+ Descriptor :: File ( file) => match wasi_filesystem:: symlink_at ( file. fd , old_path, new_path) {
985
+ Ok ( ( ) ) => ERRNO_SUCCESS ,
986
+ Err ( err) => errno_from_wasi_filesystem ( err) ,
987
+ } ,
988
+ Descriptor :: Closed => ERRNO_BADF ,
989
+ _ => ERRNO_NOTDIR ,
990
+ }
969
991
}
970
992
971
993
/// Unlink a file.
972
994
/// Return `errno::isdir` if the path refers to a directory.
973
995
/// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
974
996
#[ no_mangle]
975
997
pub unsafe extern "C" fn path_unlink_file ( fd : Fd , path_ptr : * const u8 , path_len : usize ) -> Errno {
976
- unreachable ( )
998
+ let path = slice:: from_raw_parts ( path_ptr, path_len) ;
999
+
1000
+ match Descriptor :: get ( fd) {
1001
+ Descriptor :: File ( file) => match wasi_filesystem:: unlink_file_at ( file. fd , path) {
1002
+ Ok ( ( ) ) => ERRNO_SUCCESS ,
1003
+ Err ( err) => errno_from_wasi_filesystem ( err) ,
1004
+ } ,
1005
+ Descriptor :: Closed => ERRNO_BADF ,
1006
+ _ => ERRNO_NOTDIR ,
1007
+ }
977
1008
}
978
1009
979
1010
/// Concurrently poll for the occurrence of a set of events.
0 commit comments