(dir_fd: wasip1::Fd)
| 4 | use test_programs::preview1::{create_file, open_scratch_directory}; |
| 5 | |
| 6 | unsafe fn test_readlink(dir_fd: wasip1::Fd) { |
| 7 | // Create a file in the scratch directory. |
| 8 | create_file(dir_fd, "target"); |
| 9 | |
| 10 | // Create a symlink |
| 11 | wasip1::path_symlink("target", dir_fd, "symlink").expect("creating a symlink"); |
| 12 | |
| 13 | // Read link into the buffer |
| 14 | let buf = &mut [0u8; 10]; |
| 15 | let bufused = wasip1::path_readlink(dir_fd, "symlink", buf.as_mut_ptr(), buf.len()) |
| 16 | .expect("readlink should succeed"); |
| 17 | assert_eq!(bufused, 6, "should use 6 bytes of the buffer"); |
| 18 | assert_eq!(&buf[..6], b"target", "buffer should contain 'target'"); |
| 19 | assert_eq!( |
| 20 | &buf[6..], |
| 21 | &[0u8; 4], |
| 22 | "the remaining bytes should be untouched" |
| 23 | ); |
| 24 | |
| 25 | // Read link into smaller buffer than the actual link's length |
| 26 | let buf = &mut [0u8; 4]; |
| 27 | let bufused = wasip1::path_readlink(dir_fd, "symlink", buf.as_mut_ptr(), buf.len()) |
| 28 | .expect("readlink with too-small buffer should silently truncate"); |
| 29 | assert_eq!(bufused, 4); |
| 30 | assert_eq!(buf, b"targ"); |
| 31 | |
| 32 | // Clean up. |
| 33 | wasip1::path_unlink_file(dir_fd, "target").expect("removing a file"); |
| 34 | wasip1::path_unlink_file(dir_fd, "symlink").expect("removing a file"); |
| 35 | } |
| 36 | |
| 37 | unsafe fn test_incremental_readlink(dir_fd: wasip1::Fd) { |
| 38 | let filename = "Действие"; |
no test coverage detected