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:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user