diff options
| author | John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> | 2019-01-06 11:02:30 +0100 |
|---|---|---|
| committer | John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> | 2019-01-06 11:58:13 +0100 |
| commit | 1c4823e81c57fce3aa2770e35c70d6d474f9e98b (patch) | |
| tree | ab56c2b930ab355a57018b1080bedd377acb210e | |
| parent | 1e903c3e96dcc484e83624bda2df0da5409c3d49 (diff) | |
| download | rust-1c4823e81c57fce3aa2770e35c70d6d474f9e98b.tar.gz rust-1c4823e81c57fce3aa2770e35c70d6d474f9e98b.zip | |
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
| -rw-r--r-- | src/librustc_data_structures/flock.rs | 46 |
1 files changed, 5 insertions, 41 deletions
diff --git a/src/librustc_data_structures/flock.rs b/src/librustc_data_structures/flock.rs index a5620ca52e3..2dea249f1c0 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); } } |
