diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-11 17:13:00 +0000 |
---|---|---|
committer | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-11 17:13:00 +0000 |
commit | 5e463aa51f0e644d54c21f0db2effa4b757f982a (patch) | |
tree | 26a91b122325b8a5396e82ba315de20bb0830c06 /test | |
parent | 074caea7c8b21ea359e9277d54a08b561394acdd (diff) | |
parent | f723b1822de9bd446cc6d038f4e78f7b0f58a48b (diff) | |
download | nix-5e463aa51f0e644d54c21f0db2effa4b757f982a.zip |
Merge #1089
1089: implement posix_fadvise r=asomers a=kevinwern
See:
https://github.com/CraneStation/wasi-common/issues/16
http://man7.org/linux/man-pages/man2/posix_fadvise.2.html
Conditional compilation derived from corresponding libc conditions:
Fuchsia:
https://github.com/rust-lang/libc/blob/0b02c4060a750983cebcccdf1f35a5ec4cdcf516/src/fuchsia/mod.rs#L3807
https://github.com/rust-lang/libc/blob/0e702c1b4e2e56788e8b67d3efd9c242807c3d4b/src/lib.rs#L104-L109
uClibc:
https://github.com/rust-lang/libc/blob/11c762c535cb43dda3d9d87a0845c55201a905fb/src/unix/uclibc/mod.rs#L1676
https://github.com/rust-lang/libc/blob/ce7e3a7e866dd7109a971b694a2bf58bd08f101a/src/unix/mod.rs#L1141-L1143
https://github.com/rust-lang/libc/blob/0e702c1b4e2e56788e8b67d3efd9c242807c3d4b/src/lib.rs#L116-L121
Linux, android, emscripten:
https://github.com/rust-lang/libc/blob/11c762c535cb43dda3d9d87a0845c55201a905fb/src/unix/linux_like/mod.rs#L1303
https://github.com/rust-lang/libc/blob/ce7e3a7e866dd7109a971b694a2bf58bd08f101a/src/unix/mod.rs#L1147-L1151
https://github.com/rust-lang/libc/blob/0e702c1b4e2e56788e8b67d3efd9c242807c3d4b/src/lib.rs#L116-L121
FreeBSD:
https://github.com/rust-lang/libc/blob/e0ff1e68b9e34173e9c4c3217d1b0fc81a7d352d/src/unix/bsd/freebsdlike/freebsd/mod.rs#L1223
https://github.com/rust-lang/libc/blob/ce7e3a7e866dd7109a971b694a2bf58bd08f101a/src/unix/bsd/freebsdlike/mod.rs#L1307-L1309
https://github.com/rust-lang/libc/blob/ce7e3a7e866dd7109a971b694a2bf58bd08f101a/src/unix/bsd/mod.rs#L683-L685
https://github.com/rust-lang/libc/blob/ce7e3a7e866dd7109a971b694a2bf58bd08f101a/src/unix/mod.rs#L1152-L1159
https://github.com/rust-lang/libc/blob/0e702c1b4e2e56788e8b67d3efd9c242807c3d4b/src/lib.rs#L116-L121
WASI:
https://github.com/rust-lang/libc/blob/0e702c1b4e2e56788e8b67d3efd9c242807c3d4b/src/wasi.rs#L1001
https://github.com/rust-lang/libc/blob/0e702c1b4e2e56788e8b67d3efd9c242807c3d4b/src/lib.rs#L134-L139
Co-authored-by: Kevin Wern <kevin.m.wern@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/test_fcntl.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index 8d02f147..05851828 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -180,3 +180,36 @@ mod linux_android { assert_eq!(100, read(fd, &mut buf).unwrap()); } } + +#[cfg(any(target_os = "linux", + target_os = "android", + target_os = "emscripten", + target_os = "fuchsia", + any(target_os = "wasi", target_env = "wasi"), + target_env = "uclibc", + target_env = "freebsd"))] +mod test_posix_fadvise { + + use tempfile::NamedTempFile; + use std::os::unix::io::{RawFd, AsRawFd}; + use nix::errno::Errno; + use nix::fcntl::*; + use nix::unistd::pipe; + + #[test] + 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(); + + assert_eq!(res, 0); + } + + #[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); + } +} |