From c9b207eba63b814cf39652fc9573318a7efc938b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 9 Jul 2022 12:49:37 -0400 Subject: [PATCH] extend a comment in readlink --- src/shims/unix/fs.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/shims/unix/fs.rs b/src/shims/unix/fs.rs index c6884557103..c7d7789f03a 100644 --- a/src/shims/unix/fs.rs +++ b/src/shims/unix/fs.rs @@ -1639,6 +1639,9 @@ fn readlink( let result = std::fs::read_link(pathname); match result { Ok(resolved) => { + // 'readlink' truncates the resolved path if the provided buffer is not large + // enough, and does *not* add a null terminator. That means we cannot use the usual + // `write_path_to_c_str` and have to re-implement parts of it ourselves. let resolved = this.convert_path_separator( Cow::Borrowed(resolved.as_ref()), crate::shims::os_str::PathConversion::HostToTarget, @@ -1648,8 +1651,6 @@ fn readlink( if path_bytes.len() > bufsize { path_bytes = &path_bytes[..bufsize] } - // 'readlink' truncates the resolved path if - // the provided buffer is not large enough. this.write_bytes_ptr(buf, path_bytes.iter().copied())?; Ok(path_bytes.len().try_into().unwrap()) }