wasi-common: change behavior of path_readlink to truncate on too-small buffers (#6225)

this is the same behavior as exists in posix readlink(2)
This commit is contained in:
Pat Hickey
2023-04-18 11:12:30 -07:00
committed by GitHub
parent 2494867c5f
commit 24b607cf75
2 changed files with 9 additions and 9 deletions

View File

@@ -22,10 +22,10 @@ unsafe fn test_readlink(dir_fd: wasi::Fd) {
// Read link into smaller buffer than the actual link's length
let buf = &mut [0u8; 4];
let err = wasi::path_readlink(dir_fd, "symlink", buf.as_mut_ptr(), buf.len())
.err()
.expect("readlink with too-small buffer should fail");
assert_errno!(err, wasi::ERRNO_RANGE);
let bufused = wasi::path_readlink(dir_fd, "symlink", buf.as_mut_ptr(), buf.len())
.expect("readlink with too-small buffer should silently truncate");
assert_eq!(bufused, 4);
assert_eq!(buf, b"targ");
// Clean up.
wasi::path_unlink_file(dir_fd, "target").expect("removing a file");