MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / test_readlink

Function test_readlink

crates/test-programs/src/bin/p1_readlink.rs:6–35  ·  view source on GitHub ↗
(dir_fd: wasip1::Fd)

Source from the content-addressed store, hash-verified

4use test_programs::preview1::{create_file, open_scratch_directory};
5
6unsafe 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
37unsafe fn test_incremental_readlink(dir_fd: wasip1::Fd) {
38 let filename = "Действие";

Callers 1

mainFunction · 0.85

Calls 7

path_symlinkFunction · 0.85
path_readlinkFunction · 0.85
path_unlink_fileFunction · 0.85
create_fileFunction · 0.50
expectMethod · 0.45
as_mut_ptrMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected