Skip to content

Commit e587a3f

Browse files
committed
rustc_data_structures: use libc types/constants in flock
1 parent 4affbae commit e587a3f

File tree

1 file changed

+10
-145
lines changed

1 file changed

+10
-145
lines changed

src/librustc_data_structures/flock.rs

+10-145
Original file line numberDiff line numberDiff line change
@@ -26,143 +26,6 @@ cfg_if! {
2626
use std::os::unix::prelude::*;
2727
use libc;
2828

29-
#[cfg(any(target_os = "linux", target_os = "android"))]
30-
mod os {
31-
use libc;
32-
33-
#[repr(C)]
34-
pub struct flock {
35-
pub l_type: libc::c_short,
36-
pub l_whence: libc::c_short,
37-
pub l_start: libc::off_t,
38-
pub l_len: libc::off_t,
39-
pub l_pid: libc::pid_t,
40-
41-
// not actually here, but brings in line with freebsd
42-
pub l_sysid: libc::c_int,
43-
}
44-
45-
pub const F_RDLCK: libc::c_short = 0;
46-
pub const F_WRLCK: libc::c_short = 1;
47-
pub const F_UNLCK: libc::c_short = 2;
48-
pub const F_SETLK: libc::c_int = 6;
49-
pub const F_SETLKW: libc::c_int = 7;
50-
}
51-
52-
#[cfg(target_os = "freebsd")]
53-
mod os {
54-
use libc;
55-
56-
#[repr(C)]
57-
pub struct flock {
58-
pub l_start: libc::off_t,
59-
pub l_len: libc::off_t,
60-
pub l_pid: libc::pid_t,
61-
pub l_type: libc::c_short,
62-
pub l_whence: libc::c_short,
63-
pub l_sysid: libc::c_int,
64-
}
65-
66-
pub const F_RDLCK: libc::c_short = 1;
67-
pub const F_UNLCK: libc::c_short = 2;
68-
pub const F_WRLCK: libc::c_short = 3;
69-
pub const F_SETLK: libc::c_int = 12;
70-
pub const F_SETLKW: libc::c_int = 13;
71-
}
72-
73-
#[cfg(any(target_os = "dragonfly",
74-
target_os = "bitrig",
75-
target_os = "netbsd",
76-
target_os = "openbsd"))]
77-
mod os {
78-
use libc;
79-
80-
#[repr(C)]
81-
pub struct flock {
82-
pub l_start: libc::off_t,
83-
pub l_len: libc::off_t,
84-
pub l_pid: libc::pid_t,
85-
pub l_type: libc::c_short,
86-
pub l_whence: libc::c_short,
87-
88-
// not actually here, but brings in line with freebsd
89-
pub l_sysid: libc::c_int,
90-
}
91-
92-
pub const F_RDLCK: libc::c_short = 1;
93-
pub const F_UNLCK: libc::c_short = 2;
94-
pub const F_WRLCK: libc::c_short = 3;
95-
pub const F_SETLK: libc::c_int = 8;
96-
pub const F_SETLKW: libc::c_int = 9;
97-
}
98-
99-
#[cfg(target_os = "haiku")]
100-
mod os {
101-
use libc;
102-
103-
#[repr(C)]
104-
pub struct flock {
105-
pub l_type: libc::c_short,
106-
pub l_whence: libc::c_short,
107-
pub l_start: libc::off_t,
108-
pub l_len: libc::off_t,
109-
pub l_pid: libc::pid_t,
110-
111-
// not actually here, but brings in line with freebsd
112-
pub l_sysid: libc::c_int,
113-
}
114-
115-
pub const F_RDLCK: libc::c_short = 0x0040;
116-
pub const F_UNLCK: libc::c_short = 0x0200;
117-
pub const F_WRLCK: libc::c_short = 0x0400;
118-
pub const F_SETLK: libc::c_int = 0x0080;
119-
pub const F_SETLKW: libc::c_int = 0x0100;
120-
}
121-
122-
#[cfg(any(target_os = "macos", target_os = "ios"))]
123-
mod os {
124-
use libc;
125-
126-
#[repr(C)]
127-
pub struct flock {
128-
pub l_start: libc::off_t,
129-
pub l_len: libc::off_t,
130-
pub l_pid: libc::pid_t,
131-
pub l_type: libc::c_short,
132-
pub l_whence: libc::c_short,
133-
134-
// not actually here, but brings in line with freebsd
135-
pub l_sysid: libc::c_int,
136-
}
137-
138-
pub const F_RDLCK: libc::c_short = 1;
139-
pub const F_UNLCK: libc::c_short = 2;
140-
pub const F_WRLCK: libc::c_short = 3;
141-
pub const F_SETLK: libc::c_int = 8;
142-
pub const F_SETLKW: libc::c_int = 9;
143-
}
144-
145-
#[cfg(target_os = "solaris")]
146-
mod os {
147-
use libc;
148-
149-
#[repr(C)]
150-
pub struct flock {
151-
pub l_type: libc::c_short,
152-
pub l_whence: libc::c_short,
153-
pub l_start: libc::off_t,
154-
pub l_len: libc::off_t,
155-
pub l_sysid: libc::c_int,
156-
pub l_pid: libc::pid_t,
157-
}
158-
159-
pub const F_RDLCK: libc::c_short = 1;
160-
pub const F_WRLCK: libc::c_short = 2;
161-
pub const F_UNLCK: libc::c_short = 3;
162-
pub const F_SETLK: libc::c_int = 6;
163-
pub const F_SETLKW: libc::c_int = 7;
164-
}
165-
16629
#[derive(Debug)]
16730
pub struct Lock {
16831
fd: libc::c_int,
@@ -192,20 +55,21 @@ cfg_if! {
19255
}
19356

19457
let lock_type = if exclusive {
195-
os::F_WRLCK
58+
libc::F_WRLCK
19659
} else {
197-
os::F_RDLCK
60+
libc::F_RDLCK
19861
};
19962

200-
let flock = os::flock {
63+
let flock = libc::flock {
20164
l_start: 0,
20265
l_len: 0,
20366
l_pid: 0,
20467
l_whence: libc::SEEK_SET as libc::c_short,
205-
l_type: lock_type,
68+
l_type: lock_type as libc::c_short,
69+
#[cfg(any(target_os = "freebsd", target_os = "solaris"))]
20670
l_sysid: 0,
20771
};
208-
let cmd = if wait { os::F_SETLKW } else { os::F_SETLK };
72+
let cmd = if wait { libc::F_SETLKW } else { libc::F_SETLK };
20973
let ret = unsafe {
21074
libc::fcntl(fd, cmd, &flock)
21175
};
@@ -221,16 +85,17 @@ cfg_if! {
22185

22286
impl Drop for Lock {
22387
fn drop(&mut self) {
224-
let flock = os::flock {
88+
let flock = libc::flock {
22589
l_start: 0,
22690
l_len: 0,
22791
l_pid: 0,
22892
l_whence: libc::SEEK_SET as libc::c_short,
229-
l_type: os::F_UNLCK,
93+
l_type: libc::F_UNLCK as libc::c_short,
94+
#[cfg(any(target_os = "freebsd", target_os = "solaris"))]
23095
l_sysid: 0,
23196
};
23297
unsafe {
233-
libc::fcntl(self.fd, os::F_SETLK, &flock);
98+
libc::fcntl(self.fd, libc::F_SETLK, &flock);
23499
libc::close(self.fd);
235100
}
236101
}

0 commit comments

Comments
 (0)