@@ -13,96 +13,9 @@ use std::path::Path;
1313cfg_if ! {
1414 if #[ cfg( unix) ] {
1515 use std:: ffi:: { CString , OsStr } ;
16+ use std:: mem;
1617 use std:: os:: unix:: prelude:: * ;
1718
18- #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
19- mod os {
20- #[ repr( C ) ]
21- pub struct flock {
22- pub l_type: libc:: c_short,
23- pub l_whence: libc:: c_short,
24- pub l_start: libc:: off_t,
25- pub l_len: libc:: off_t,
26- pub l_pid: libc:: pid_t,
27-
28- // not actually here, but brings in line with freebsd
29- pub l_sysid: libc:: c_int,
30- }
31- }
32-
33- #[ cfg( target_os = "freebsd" ) ]
34- mod os {
35- #[ repr( C ) ]
36- pub struct flock {
37- pub l_start: libc:: off_t,
38- pub l_len: libc:: off_t,
39- pub l_pid: libc:: pid_t,
40- pub l_type: libc:: c_short,
41- pub l_whence: libc:: c_short,
42- pub l_sysid: libc:: c_int,
43- }
44- }
45-
46- #[ cfg( any( target_os = "dragonfly" ,
47- target_os = "netbsd" ,
48- target_os = "openbsd" ) ) ]
49- mod os {
50- #[ repr( C ) ]
51- pub struct flock {
52- pub l_start: libc:: off_t,
53- pub l_len: libc:: off_t,
54- pub l_pid: libc:: pid_t,
55- pub l_type: libc:: c_short,
56- pub l_whence: libc:: c_short,
57-
58- // not actually here, but brings in line with freebsd
59- pub l_sysid: libc:: c_int,
60- }
61- }
62-
63- #[ cfg( target_os = "haiku" ) ]
64- mod os {
65- #[ repr( C ) ]
66- pub struct flock {
67- pub l_type: libc:: c_short,
68- pub l_whence: libc:: c_short,
69- pub l_start: libc:: off_t,
70- pub l_len: libc:: off_t,
71- pub l_pid: libc:: pid_t,
72-
73- // not actually here, but brings in line with freebsd
74- pub l_sysid: libc:: c_int,
75- }
76- }
77-
78- #[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
79- mod os {
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-
93- #[ cfg( target_os = "solaris" ) ]
94- mod os {
95- #[ repr( C ) ]
96- pub struct flock {
97- pub l_type: libc:: c_short,
98- pub l_whence: libc:: c_short,
99- pub l_start: libc:: off_t,
100- pub l_len: libc:: off_t,
101- pub l_sysid: libc:: c_int,
102- pub l_pid: libc:: pid_t,
103- }
104- }
105-
10619 #[ derive( Debug ) ]
10720 pub struct Lock {
10821 fd: libc:: c_int,
@@ -132,19 +45,17 @@ cfg_if! {
13245 }
13346
13447 let lock_type = if exclusive {
135- libc:: F_WRLCK as libc :: c_short
48+ libc:: F_WRLCK
13649 } else {
137- libc:: F_RDLCK as libc :: c_short
50+ libc:: F_RDLCK
13851 } ;
13952
140- let flock = os:: flock {
141- l_start: 0 ,
142- l_len: 0 ,
143- l_pid: 0 ,
144- l_whence: libc:: SEEK_SET as libc:: c_short,
145- l_type: lock_type,
146- l_sysid: 0 ,
147- } ;
53+ let mut flock: libc:: flock = unsafe { mem:: zeroed( ) } ;
54+ flock. l_type = lock_type as libc:: c_short;
55+ flock. l_whence = libc:: SEEK_SET as libc:: c_short;
56+ flock. l_start = 0 ;
57+ flock. l_len = 0 ;
58+
14859 let cmd = if wait { libc:: F_SETLKW } else { libc:: F_SETLK } ;
14960 let ret = unsafe {
15061 libc:: fcntl( fd, cmd, & flock)
@@ -161,14 +72,12 @@ cfg_if! {
16172
16273 impl Drop for Lock {
16374 fn drop( & mut self ) {
164- let flock = os:: flock {
165- l_start: 0 ,
166- l_len: 0 ,
167- l_pid: 0 ,
168- l_whence: libc:: SEEK_SET as libc:: c_short,
169- l_type: libc:: F_UNLCK as libc:: c_short,
170- l_sysid: 0 ,
171- } ;
75+ let mut flock: libc:: flock = unsafe { mem:: zeroed( ) } ;
76+ flock. l_type = libc:: F_UNLCK as libc:: c_short;
77+ flock. l_whence = libc:: SEEK_SET as libc:: c_short;
78+ flock. l_start = 0 ;
79+ flock. l_len = 0 ;
80+
17281 unsafe {
17382 libc:: fcntl( self . fd, libc:: F_SETLK , & flock) ;
17483 libc:: close( self . fd) ;
0 commit comments