Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fcntl for FreeBSD platform #1368

Merged
merged 1 commit into from
Jan 3, 2021
Merged

Fix fcntl for FreeBSD platform #1368

merged 1 commit into from
Jan 3, 2021

Conversation

AlexanderThaller
Copy link
Contributor

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:

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.

Need to use the right cfg option for the conditional compilation.
target_os is the right option to use when targeting FreeBSD. target_env
was used before which seems to be a typo.
Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

bors r+

@bors bors bot merged commit c0c5570 into nix-rust:master Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants