summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md4
-rw-r--r--src/fcntl.rs9
-rw-r--r--test/test_fcntl.rs9
3 files changed, 15 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1139cf09..af4fa9bc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -83,12 +83,16 @@ This project adheres to [Semantic Versioning](https://semver.org/).
### Fixed
+- `posix_fadvise` now returns errors in the conventional way, rather than as a
+ non-zero value in `Ok()`.
+ (#[1538](https://github.com/nix-rust/nix/pull/1538))
- Added more errno definitions for better backwards compatibility with
Nix 0.21.0.
(#[1467](https://github.com/nix-rust/nix/pull/1467))
- Fixed potential undefined behavior in `Signal::try_from` on some platforms.
(#[1484](https://github.com/nix-rust/nix/pull/1484))
+
### Removed
- Removed a couple of termios constants on redox that were never actually
diff --git a/src/fcntl.rs b/src/fcntl.rs
index aded27b4..dd8e59a6 100644
--- a/src/fcntl.rs
+++ b/src/fcntl.rs
@@ -667,9 +667,14 @@ mod posix_fadvise {
offset: libc::off_t,
len: libc::off_t,
advice: PosixFadviseAdvice,
- ) -> Result<libc::c_int> {
+ ) -> Result<()> {
let res = unsafe { libc::posix_fadvise(fd, offset, len, advice as libc::c_int) };
- Errno::result(res)
+
+ if res == 0 {
+ Ok(())
+ } else {
+ Err(Errno::from_i32(res))
+ }
}
}
diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs
index 76252e6e..db2acfbf 100644
--- a/test/test_fcntl.rs
+++ b/test/test_fcntl.rs
@@ -473,17 +473,16 @@ mod test_posix_fadvise {
fn test_success() {
let tmp = NamedTempFile::new().unwrap();
let fd = tmp.as_raw_fd();
- let res = posix_fadvise(fd, 0, 100, PosixFadviseAdvice::POSIX_FADV_WILLNEED).unwrap();
+ let res = posix_fadvise(fd, 0, 100, PosixFadviseAdvice::POSIX_FADV_WILLNEED);
- assert_eq!(res, 0);
+ assert!(res.is_ok());
}
#[test]
fn test_errno() {
let (rd, _wr) = pipe().unwrap();
- let errno = posix_fadvise(rd as RawFd, 0, 100, PosixFadviseAdvice::POSIX_FADV_WILLNEED)
- .unwrap();
- assert_eq!(errno, Errno::ESPIPE as i32);
+ let res = posix_fadvise(rd as RawFd, 0, 100, PosixFadviseAdvice::POSIX_FADV_WILLNEED);
+ assert_eq!(res, Err(Errno::ESPIPE));
}
}