Skip to content

Commit c0c5570

Browse files
bors[bot]Alexander Thaller
andauthored
Merge #1368
1368: Fix fcntl for FreeBSD platform r=asomers a=AlexanderThaller When compiling the following code with nix `0.19.1` under FreeBSD 12.2: ``` use std::os::unix::io::AsRawFd; fn main() { let f = std::fs::File::create("/tmp/testfile").unwrap(); nix::fcntl::posix_fadvise( f.as_raw_fd(), 0, 0, nix::fcntl::PosixFadviseAdvice::POSIX_FADV_NOREUSE, ).unwrap(); } ``` I get the following error: ``` error[E0433]: failed to resolve: could not find `PosixFadviseAdvice` in `fcntl` --> src/main.rs:10:21 | 10 | nix::fcntl::PosixFadviseAdvice::POSIX_FADV_NOREUSE, | ^^^^^^^^^^^^^^^^^^ could not find `PosixFadviseAdvice` in `fcntl` error[E0425]: cannot find function `posix_fadvise` in module `nix::fcntl` --> src/main.rs:6:17 | 6 | nix::fcntl::posix_fadvise( | ^^^^^^^^^^^^^ not found in `nix::fcntl` error: aborting due to 2 previous errors ``` Checking the documentation I noticed the documentation for the FreeBSD platform was missing: https://docs.rs/nix/0.19.1/x86_64-unknown-freebsd/nix/?search=PosixFadviseAdvice Checking the code I noticed that `target_env` was used instead of `target_os`: * https://doc.rust-lang.org/reference/conditional-compilation.html#target_env * https://doc.rust-lang.org/reference/conditional-compilation.html#target_os Switching to `target_os` fixed the compilation errors. I also ran the tests with the fix and they seemed to be fine: ``` test result: ok. 68 passed; 0 failed; 14 ignored; 0 measured; 0 filtered out ``` I hope this makes sense to fix. Co-authored-by: Alexander Thaller <[email protected]>
2 parents 8cff207 + d965259 commit c0c5570

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/fcntl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::sys::uio::IoVec; // For vmsplice
2020
target_os = "fuchsia",
2121
any(target_os = "wasi", target_env = "wasi"),
2222
target_env = "uclibc",
23-
target_env = "freebsd"
23+
target_os = "freebsd"
2424
))]
2525
pub use self::posix_fadvise::*;
2626

@@ -587,7 +587,7 @@ pub fn fallocate(
587587
target_os = "fuchsia",
588588
any(target_os = "wasi", target_env = "wasi"),
589589
target_env = "uclibc",
590-
target_env = "freebsd"
590+
target_os = "freebsd"
591591
))]
592592
mod posix_fadvise {
593593
use crate::errno::Errno;

test/test_fcntl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ mod linux_android {
332332
target_os = "fuchsia",
333333
any(target_os = "wasi", target_env = "wasi"),
334334
target_env = "uclibc",
335-
target_env = "freebsd"))]
335+
target_os = "freebsd"))]
336336
mod test_posix_fadvise {
337337

338338
use tempfile::NamedTempFile;

0 commit comments

Comments
 (0)