diff --git a/src/env_universal_common.rs b/src/env_universal_common.rs index 16c957aa2..1867395dd 100644 --- a/src/env_universal_common.rs +++ b/src/env_universal_common.rs @@ -1,3 +1,5 @@ +#![allow(clippy::bad_bit_mask)] + use crate::common::{ read_loop, str2wcstring, timef, unescape_string, valid_var_name, wcs2zstring, write_loop, UnescapeFlags, UnescapeStringStyle, @@ -7,7 +9,7 @@ use crate::fallback::fish_mkstemp_cloexec; use crate::fds::AutoCloseFd; use crate::fds::{open_cloexec, wopen_cloexec}; use crate::flog::{FLOG, FLOGF}; -use crate::libc::{C_O_EXLOCK, UVAR_FILE_SET_MTIME_HACK}; +use crate::libc::UVAR_FILE_SET_MTIME_HACK; use crate::path::path_get_config; use crate::path::{path_get_config_remoteness, DirRemoteness}; use crate::wchar::prelude::*; @@ -28,6 +30,13 @@ use std::mem::MaybeUninit; use std::os::fd::RawFd; use std::os::unix::prelude::MetadataExt; +// Pull in the O_EXLOCK constant if it is defined, otherwise set it to 0. +#[cfg(any(bsd, target_os = "macos"))] +use libc::O_EXLOCK; + +#[cfg(not(any(bsd, target_os = "macos")))] +const O_EXLOCK: libc::c_int = 0; + /// Callback data, reflecting a change in universal variables. pub struct CallbackData { // The name of the variable. @@ -430,8 +439,6 @@ impl EnvUniversal { let mut locked_by_open = false; let mut flags = O_RDWR | O_CREAT; - #[allow(non_snake_case)] - let O_EXLOCK = unsafe { C_O_EXLOCK() }; if O_EXLOCK != 0 && self.do_flock { flags |= O_EXLOCK; locked_by_open = true; diff --git a/src/libc.c b/src/libc.c index cd4c78076..c1f1ddc35 100644 --- a/src/libc.c +++ b/src/libc.c @@ -64,14 +64,6 @@ int C_PC_CASE_SENSITIVE() { FILE* stdout_stream() { return stdout; } -int C_O_EXLOCK() { -#ifdef O_EXLOCK - return O_EXLOCK; -#else - return 0; -#endif -} - static const bool uvar_file_set_mtime_hack = #ifdef UVAR_FILE_SET_MTIME_HACK true; diff --git a/src/libc.rs b/src/libc.rs index 857112b11..5b26f56b0 100644 --- a/src/libc.rs +++ b/src/libc.rs @@ -47,7 +47,6 @@ extern "C" { buf: *mut libc::c_char, len: libc::size_t, ) -> libc::size_t; - pub fn C_O_EXLOCK() -> c_int; pub fn stdout_stream() -> *mut libc::FILE; pub fn UVAR_FILE_SET_MTIME_HACK() -> bool; pub fn setlinebuf(stream: *mut libc::FILE);