-
Notifications
You must be signed in to change notification settings - Fork 677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix readlink/readlinkat to return too long only when it is long #1109
Changes from 3 commits
ea10209
e743336
3d5eadd
07e2ea9
e99c267
6737585
4a4cfc0
fa50f63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,16 @@ This project adheres to [Semantic Versioning](http://semver.org/). | |
## [Unreleased] - ReleaseDate | ||
### Added | ||
### Changed | ||
- Changed `readlink` and `readlinkat` to return `osString` | ||
- Changed `readlink` and `readlinkat` to return `OsString` | ||
([#1109](https://github.com/nix-rust/nix/pull/1109)) | ||
|
||
```rust | ||
use nix::fcntl::{readlink, readlinkat}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line isn't important to readers. You can suppress it with a leading |
||
|
||
readlink(&path); | ||
readlinkat(dirfd, &path); | ||
``` | ||
|
||
### Fixed | ||
### Removed | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,19 +188,21 @@ fn wrap_readlink_result(v: &mut Vec<u8>, res: ssize_t) -> Result<OsString> { | |
} | ||
|
||
pub fn readlink<'a, P: ?Sized + NixPath>(path: &P) -> Result<OsString> { | ||
let mut v = vec![0u8; libc::PATH_MAX as usize]; | ||
let len = libc::PATH_MAX as usize; | ||
let mut v = Vec::with_capacity(len); | ||
let res = path.with_nix_path(|cstr| { | ||
unsafe { libc::readlink(cstr.as_ptr(), v.as_mut_ptr() as *mut c_char, v.len() as size_t) } | ||
unsafe { libc::readlink(cstr.as_ptr(), v.as_mut_ptr() as *mut c_char, len as size_t) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You seem to be unaware of the let mut v = Vec::with_capacity(libc::PATH_MAX as usize);
let res = path.with_nix_path(|cstr| {
unsafe { libc::readlink(cstr.as_ptr(), v.as_mut_ptr() as *mut c_char, v.capacity() as size_t) }
|
||
})?; | ||
|
||
wrap_readlink_result(&mut v, res) | ||
} | ||
|
||
|
||
pub fn readlinkat<'a, P: ?Sized + NixPath>(dirfd: RawFd, path: &P) -> Result<OsString> { | ||
let mut v = vec![0u8; libc::PATH_MAX as usize]; | ||
let len = libc::PATH_MAX as usize; | ||
let mut v = Vec::with_capacity(len); | ||
let res = path.with_nix_path(|cstr| { | ||
unsafe { libc::readlinkat(dirfd, cstr.as_ptr(), v.as_mut_ptr() as *mut c_char, v.len() as size_t) } | ||
unsafe { libc::readlinkat(dirfd, cstr.as_ptr(), v.as_mut_ptr() as *mut c_char, len as size_t) } | ||
})?; | ||
|
||
wrap_readlink_result(&mut v, res) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example isn't going to mean much to a reader. I'm thinking something in English, like "the
buffer
argument ofreadlink
andreadlinkat
has been removed, and the return value is now an owned type. Existing code can be updated by removing the buffer argument and removing anyclone
or similar operation on the output."