Skip to content

Commit

Permalink
Merge #1368
Browse files Browse the repository at this point in the history
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 <alexander.thaller@trivago.com>
  • Loading branch information
bors[bot] and Alexander Thaller committed Jan 3, 2021
2 parents 8cff207 + d965259 commit c0c5570
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/fcntl.rs
Expand Up @@ -20,7 +20,7 @@ use crate::sys::uio::IoVec; // For vmsplice
target_os = "fuchsia",
any(target_os = "wasi", target_env = "wasi"),
target_env = "uclibc",
target_env = "freebsd"
target_os = "freebsd"
))]
pub use self::posix_fadvise::*;

Expand Down Expand Up @@ -587,7 +587,7 @@ pub fn fallocate(
target_os = "fuchsia",
any(target_os = "wasi", target_env = "wasi"),
target_env = "uclibc",
target_env = "freebsd"
target_os = "freebsd"
))]
mod posix_fadvise {
use crate::errno::Errno;
Expand Down
2 changes: 1 addition & 1 deletion test/test_fcntl.rs
Expand Up @@ -332,7 +332,7 @@ mod linux_android {
target_os = "fuchsia",
any(target_os = "wasi", target_env = "wasi"),
target_env = "uclibc",
target_env = "freebsd"))]
target_os = "freebsd"))]
mod test_posix_fadvise {

use tempfile::NamedTempFile;
Expand Down

0 comments on commit c0c5570

Please sign in to comment.