From 1c4823e81c57fce3aa2770e35c70d6d474f9e98b Mon Sep 17 00:00:00 2001 From: John Paul Adrian Glaubitz Date: Sun, 6 Jan 2019 11:02:30 +0100 Subject: [PATCH] flock: Use fcntl constants directly from libc crate on Unix targets Since the values for the fcntl constants can vary from architecture to architecture, it is better to use the values defined in the libc crate instead of assigning literals in the flock code which would make the assumption that all architectures use the same values. Fixes #57007 --- src/librustc_data_structures/flock.rs | 46 +++------------------------ 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/src/librustc_data_structures/flock.rs b/src/librustc_data_structures/flock.rs index a5620ca52e3f1..2dea249f1c07c 100644 --- a/src/librustc_data_structures/flock.rs +++ b/src/librustc_data_structures/flock.rs @@ -31,12 +31,6 @@ cfg_if! { // not actually here, but brings in line with freebsd pub l_sysid: libc::c_int, } - - pub const F_RDLCK: libc::c_short = 0; - pub const F_WRLCK: libc::c_short = 1; - pub const F_UNLCK: libc::c_short = 2; - pub const F_SETLK: libc::c_int = 6; - pub const F_SETLKW: libc::c_int = 7; } #[cfg(target_os = "freebsd")] @@ -52,12 +46,6 @@ cfg_if! { pub l_whence: libc::c_short, pub l_sysid: libc::c_int, } - - pub const F_RDLCK: libc::c_short = 1; - pub const F_UNLCK: libc::c_short = 2; - pub const F_WRLCK: libc::c_short = 3; - pub const F_SETLK: libc::c_int = 12; - pub const F_SETLKW: libc::c_int = 13; } #[cfg(any(target_os = "dragonfly", @@ -78,12 +66,6 @@ cfg_if! { // not actually here, but brings in line with freebsd pub l_sysid: libc::c_int, } - - pub const F_RDLCK: libc::c_short = 1; - pub const F_UNLCK: libc::c_short = 2; - pub const F_WRLCK: libc::c_short = 3; - pub const F_SETLK: libc::c_int = 8; - pub const F_SETLKW: libc::c_int = 9; } #[cfg(target_os = "haiku")] @@ -101,12 +83,6 @@ cfg_if! { // not actually here, but brings in line with freebsd pub l_sysid: libc::c_int, } - - pub const F_RDLCK: libc::c_short = 0x0040; - pub const F_UNLCK: libc::c_short = 0x0200; - pub const F_WRLCK: libc::c_short = 0x0400; - pub const F_SETLK: libc::c_int = 0x0080; - pub const F_SETLKW: libc::c_int = 0x0100; } #[cfg(any(target_os = "macos", target_os = "ios"))] @@ -124,12 +100,6 @@ cfg_if! { // not actually here, but brings in line with freebsd pub l_sysid: libc::c_int, } - - pub const F_RDLCK: libc::c_short = 1; - pub const F_UNLCK: libc::c_short = 2; - pub const F_WRLCK: libc::c_short = 3; - pub const F_SETLK: libc::c_int = 8; - pub const F_SETLKW: libc::c_int = 9; } #[cfg(target_os = "solaris")] @@ -145,12 +115,6 @@ cfg_if! { pub l_sysid: libc::c_int, pub l_pid: libc::pid_t, } - - pub const F_RDLCK: libc::c_short = 1; - pub const F_WRLCK: libc::c_short = 2; - pub const F_UNLCK: libc::c_short = 3; - pub const F_SETLK: libc::c_int = 6; - pub const F_SETLKW: libc::c_int = 7; } #[derive(Debug)] @@ -182,9 +146,9 @@ cfg_if! { } let lock_type = if exclusive { - os::F_WRLCK + libc::F_WRLCK as libc::c_short } else { - os::F_RDLCK + libc::F_RDLCK as libc::c_short }; let flock = os::flock { @@ -195,7 +159,7 @@ cfg_if! { l_type: lock_type, l_sysid: 0, }; - let cmd = if wait { os::F_SETLKW } else { os::F_SETLK }; + let cmd = if wait { libc::F_SETLKW } else { libc::F_SETLK }; let ret = unsafe { libc::fcntl(fd, cmd, &flock) }; @@ -216,11 +180,11 @@ cfg_if! { l_len: 0, l_pid: 0, l_whence: libc::SEEK_SET as libc::c_short, - l_type: os::F_UNLCK, + l_type: libc::F_UNLCK as libc::c_short, l_sysid: 0, }; unsafe { - libc::fcntl(self.fd, os::F_SETLK, &flock); + libc::fcntl(self.fd, libc::F_SETLK, &flock); libc::close(self.fd); } }