Skip to content

Commit 4a4cfc0

Browse files
committed
updated changelog
1 parent 6737585 commit 4a4cfc0

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1212
```rust
1313
use nix::fcntl::{readlink, readlinkat};
1414

15-
readlink(&path);
16-
readlinkat(dirfd, &path);
15+
// the buffer argument of `readlink` and `readlinkat` has been removed,
16+
// and the return value is now an owned type (`OsString`).
17+
// Existing code can be updated by removing the buffer argument
18+
// and removing any clone or similar operation on the output
19+
20+
// old code `readlink(&path, &mut buf)` can be replaced with the following
21+
readlink(&path); // this returns OsString
22+
23+
// old code `readlinkat(dirfd, &path, &mut buf)` can be replaced with the following
24+
readlinkat(dirfd, &path); // this returns OsString
1725
```
1826

1927
### Fixed

src/fcntl.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,21 +188,19 @@ fn wrap_readlink_result(v: &mut Vec<u8>, res: ssize_t) -> Result<OsString> {
188188
}
189189

190190
pub fn readlink<'a, P: ?Sized + NixPath>(path: &P) -> Result<OsString> {
191-
let len = libc::PATH_MAX as usize;
192-
let mut v = Vec::with_capacity(len);
191+
let mut v = Vec::with_capacity(libc::PATH_MAX as usize);
193192
let res = path.with_nix_path(|cstr| {
194-
unsafe { libc::readlink(cstr.as_ptr(), v.as_mut_ptr() as *mut c_char, len as size_t) }
193+
unsafe { libc::readlink(cstr.as_ptr(), v.as_mut_ptr() as *mut c_char, v.capacity() as size_t) }
195194
})?;
196195

197196
wrap_readlink_result(&mut v, res)
198197
}
199198

200199

201200
pub fn readlinkat<'a, P: ?Sized + NixPath>(dirfd: RawFd, path: &P) -> Result<OsString> {
202-
let len = libc::PATH_MAX as usize;
203-
let mut v = Vec::with_capacity(len);
201+
let mut v = Vec::with_capacity(libc::PATH_MAX as usize);
204202
let res = path.with_nix_path(|cstr| {
205-
unsafe { libc::readlinkat(dirfd, cstr.as_ptr(), v.as_mut_ptr() as *mut c_char, len as size_t) }
203+
unsafe { libc::readlinkat(dirfd, cstr.as_ptr(), v.as_mut_ptr() as *mut c_char, v.capacity() as size_t) }
206204
})?;
207205

208206
wrap_readlink_result(&mut v, res)

0 commit comments

Comments
 (0)