mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-28 04:35:09 +00:00
Use libc O_EXLOCK instead of our own
Rust libc supports O_EXLOCK on supported platforms (BSD/macOS), use that instead of re-exposing it.
This commit is contained in:
parent
2ffec7463e
commit
70ed4806b4
3 changed files with 10 additions and 12 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
#![allow(clippy::bad_bit_mask)]
|
||||||
|
|
||||||
use crate::common::{
|
use crate::common::{
|
||||||
read_loop, str2wcstring, timef, unescape_string, valid_var_name, wcs2zstring, write_loop,
|
read_loop, str2wcstring, timef, unescape_string, valid_var_name, wcs2zstring, write_loop,
|
||||||
UnescapeFlags, UnescapeStringStyle,
|
UnescapeFlags, UnescapeStringStyle,
|
||||||
|
@ -7,7 +9,7 @@ use crate::fallback::fish_mkstemp_cloexec;
|
||||||
use crate::fds::AutoCloseFd;
|
use crate::fds::AutoCloseFd;
|
||||||
use crate::fds::{open_cloexec, wopen_cloexec};
|
use crate::fds::{open_cloexec, wopen_cloexec};
|
||||||
use crate::flog::{FLOG, FLOGF};
|
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;
|
||||||
use crate::path::{path_get_config_remoteness, DirRemoteness};
|
use crate::path::{path_get_config_remoteness, DirRemoteness};
|
||||||
use crate::wchar::prelude::*;
|
use crate::wchar::prelude::*;
|
||||||
|
@ -28,6 +30,13 @@ use std::mem::MaybeUninit;
|
||||||
use std::os::fd::RawFd;
|
use std::os::fd::RawFd;
|
||||||
use std::os::unix::prelude::MetadataExt;
|
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.
|
/// Callback data, reflecting a change in universal variables.
|
||||||
pub struct CallbackData {
|
pub struct CallbackData {
|
||||||
// The name of the variable.
|
// The name of the variable.
|
||||||
|
@ -430,8 +439,6 @@ impl EnvUniversal {
|
||||||
let mut locked_by_open = false;
|
let mut locked_by_open = false;
|
||||||
let mut flags = O_RDWR | O_CREAT;
|
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 {
|
if O_EXLOCK != 0 && self.do_flock {
|
||||||
flags |= O_EXLOCK;
|
flags |= O_EXLOCK;
|
||||||
locked_by_open = true;
|
locked_by_open = true;
|
||||||
|
|
|
@ -64,14 +64,6 @@ int C_PC_CASE_SENSITIVE() {
|
||||||
|
|
||||||
FILE* stdout_stream() { return stdout; }
|
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 =
|
static const bool uvar_file_set_mtime_hack =
|
||||||
#ifdef UVAR_FILE_SET_MTIME_HACK
|
#ifdef UVAR_FILE_SET_MTIME_HACK
|
||||||
true;
|
true;
|
||||||
|
|
|
@ -47,7 +47,6 @@ extern "C" {
|
||||||
buf: *mut libc::c_char,
|
buf: *mut libc::c_char,
|
||||||
len: libc::size_t,
|
len: libc::size_t,
|
||||||
) -> libc::size_t;
|
) -> libc::size_t;
|
||||||
pub fn C_O_EXLOCK() -> c_int;
|
|
||||||
pub fn stdout_stream() -> *mut libc::FILE;
|
pub fn stdout_stream() -> *mut libc::FILE;
|
||||||
pub fn UVAR_FILE_SET_MTIME_HACK() -> bool;
|
pub fn UVAR_FILE_SET_MTIME_HACK() -> bool;
|
||||||
pub fn setlinebuf(stream: *mut libc::FILE);
|
pub fn setlinebuf(stream: *mut libc::FILE);
|
||||||
|
|
Loading…
Reference in a new issue