Auto merge of #2351 - RalfJung:readlink, r=RalfJung
extend a comment in readlink
This commit is contained in:
commit
aada09f79a
@ -1639,6 +1639,9 @@ fn readlink(
|
|||||||
let result = std::fs::read_link(pathname);
|
let result = std::fs::read_link(pathname);
|
||||||
match result {
|
match result {
|
||||||
Ok(resolved) => {
|
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(
|
let resolved = this.convert_path_separator(
|
||||||
Cow::Borrowed(resolved.as_ref()),
|
Cow::Borrowed(resolved.as_ref()),
|
||||||
crate::shims::os_str::PathConversion::HostToTarget,
|
crate::shims::os_str::PathConversion::HostToTarget,
|
||||||
@ -1648,8 +1651,6 @@ fn readlink(
|
|||||||
if path_bytes.len() > bufsize {
|
if path_bytes.len() > bufsize {
|
||||||
path_bytes = &path_bytes[..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())?;
|
this.write_bytes_ptr(buf, path_bytes.iter().copied())?;
|
||||||
Ok(path_bytes.len().try_into().unwrap())
|
Ok(path_bytes.len().try_into().unwrap())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user