@@ -26,143 +26,6 @@ cfg_if! {
26
26
use std:: os:: unix:: prelude:: * ;
27
27
use libc;
28
28
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
-
166
29
#[ derive( Debug ) ]
167
30
pub struct Lock {
168
31
fd: libc:: c_int,
@@ -192,20 +55,21 @@ cfg_if! {
192
55
}
193
56
194
57
let lock_type = if exclusive {
195
- os :: F_WRLCK
58
+ libc :: F_WRLCK
196
59
} else {
197
- os :: F_RDLCK
60
+ libc :: F_RDLCK
198
61
} ;
199
62
200
- let flock = os :: flock {
63
+ let flock = libc :: flock {
201
64
l_start: 0 ,
202
65
l_len: 0 ,
203
66
l_pid: 0 ,
204
67
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" ) ) ]
206
70
l_sysid: 0 ,
207
71
} ;
208
- let cmd = if wait { os :: F_SETLKW } else { os :: F_SETLK } ;
72
+ let cmd = if wait { libc :: F_SETLKW } else { libc :: F_SETLK } ;
209
73
let ret = unsafe {
210
74
libc:: fcntl( fd, cmd, & flock)
211
75
} ;
@@ -221,16 +85,17 @@ cfg_if! {
221
85
222
86
impl Drop for Lock {
223
87
fn drop( & mut self ) {
224
- let flock = os :: flock {
88
+ let flock = libc :: flock {
225
89
l_start: 0 ,
226
90
l_len: 0 ,
227
91
l_pid: 0 ,
228
92
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" ) ) ]
230
95
l_sysid: 0 ,
231
96
} ;
232
97
unsafe {
233
- libc:: fcntl( self . fd, os :: F_SETLK , & flock) ;
98
+ libc:: fcntl( self . fd, libc :: F_SETLK , & flock) ;
234
99
libc:: close( self . fd) ;
235
100
}
236
101
}
0 commit comments