Skip to content

Commit 2bb718c

Browse files
committed
Auto merge of #503 - Idolf:bitflags, r=kamalmarhubi
Fix the style for bitflags! Prefer `libc_bitflags!` over `bitflags!`. Prefer `libc::CONSTANTS` over writing the constant manually. This makes #501 unnecessary, since upstream now contains the `O_TMPFILE` constant.
2 parents 877fb71 + 51b5eac commit 2bb718c

12 files changed

+241
-241
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
3737
([#497](https://github.com/nix-rust/nix/pull/497))
3838
- Added `major` and `minor` in `::nix::sys::stat` for decomposing `dev_t`
3939
([#508](https://github.com/nix-rust/nix/pull/508))
40+
- Fixed the style of many bitflags and use `libc` in more places.
41+
([#503](https://github.com/nix-rust/nix/pull/503))
4042

4143
### Changed
4244
- `epoll_ctl` now could accept None as argument `event`

src/fcntl.rs

+56-56
Original file line numberDiff line numberDiff line change
@@ -137,38 +137,38 @@ pub fn vmsplice(fd: RawFd, iov: &[IoVec<&[u8]>], flags: SpliceFFlags) -> Result<
137137
mod consts {
138138
use libc::{self, c_int, c_uint};
139139

140-
bitflags! {
140+
libc_bitflags! {
141141
pub flags SpliceFFlags: c_uint {
142-
const SPLICE_F_MOVE = libc::SPLICE_F_MOVE,
143-
const SPLICE_F_NONBLOCK = libc::SPLICE_F_NONBLOCK,
144-
const SPLICE_F_MORE = libc::SPLICE_F_MORE,
145-
const SPLICE_F_GIFT = libc::SPLICE_F_GIFT,
142+
SPLICE_F_MOVE,
143+
SPLICE_F_NONBLOCK,
144+
SPLICE_F_MORE,
145+
SPLICE_F_GIFT,
146146
}
147147
}
148148

149149
bitflags!(
150150
pub flags OFlag: c_int {
151-
const O_ACCMODE = 0o00000003,
152-
const O_RDONLY = 0o00000000,
153-
const O_WRONLY = 0o00000001,
154-
const O_RDWR = 0o00000002,
155-
const O_CREAT = 0o00000100,
156-
const O_EXCL = 0o00000200,
157-
const O_NOCTTY = 0o00000400,
158-
const O_TRUNC = 0o00001000,
159-
const O_APPEND = 0o00002000,
160-
const O_NONBLOCK = 0o00004000,
161-
const O_DSYNC = 0o00010000,
162-
const O_DIRECT = 0o00040000,
151+
const O_ACCMODE = libc::O_ACCMODE,
152+
const O_RDONLY = libc::O_RDONLY,
153+
const O_WRONLY = libc::O_WRONLY,
154+
const O_RDWR = libc::O_RDWR,
155+
const O_CREAT = libc::O_CREAT,
156+
const O_EXCL = libc::O_EXCL,
157+
const O_NOCTTY = libc::O_NOCTTY,
158+
const O_TRUNC = libc::O_TRUNC,
159+
const O_APPEND = libc::O_APPEND,
160+
const O_NONBLOCK = libc::O_NONBLOCK,
161+
const O_DSYNC = libc::O_DSYNC,
162+
const O_DIRECT = libc::O_DIRECT,
163163
const O_LARGEFILE = 0o00100000,
164-
const O_DIRECTORY = 0o00200000,
165-
const O_NOFOLLOW = 0o00400000,
164+
const O_DIRECTORY = libc::O_DIRECTORY,
165+
const O_NOFOLLOW = libc::O_NOFOLLOW,
166166
const O_NOATIME = 0o01000000,
167-
const O_CLOEXEC = 0o02000000,
168-
const O_SYNC = 0o04000000,
167+
const O_CLOEXEC = libc::O_CLOEXEC,
168+
const O_SYNC = libc::O_SYNC,
169169
const O_PATH = 0o10000000,
170-
const O_TMPFILE = 0o20000000,
171-
const O_NDELAY = O_NONBLOCK.bits
170+
const O_TMPFILE = libc::O_TMPFILE,
171+
const O_NDELAY = libc::O_NDELAY,
172172
}
173173
);
174174

@@ -191,27 +191,27 @@ mod consts {
191191

192192
#[cfg(any(target_os = "macos", target_os = "ios"))]
193193
mod consts {
194-
use libc::c_int;
194+
use libc::{self, c_int};
195195

196196
bitflags!(
197197
pub flags OFlag: c_int {
198-
const O_ACCMODE = 0x0000003,
199-
const O_RDONLY = 0x0000000,
200-
const O_WRONLY = 0x0000001,
201-
const O_RDWR = 0x0000002,
202-
const O_CREAT = 0x0000200,
203-
const O_EXCL = 0x0000800,
204-
const O_NOCTTY = 0x0020000,
205-
const O_TRUNC = 0x0000400,
206-
const O_APPEND = 0x0000008,
207-
const O_NONBLOCK = 0x0000004,
208-
const O_DSYNC = 0x0400000,
209-
const O_DIRECTORY = 0x0100000,
210-
const O_NOFOLLOW = 0x0000100,
211-
const O_CLOEXEC = 0x1000000,
212-
const O_SYNC = 0x0000080,
198+
const O_ACCMODE = libc::O_ACCMODE,
199+
const O_RDONLY = libc::O_RDONLY,
200+
const O_WRONLY = libc::O_WRONLY,
201+
const O_RDWR = libc::O_RDWR,
202+
const O_CREAT = libc::O_CREAT,
203+
const O_EXCL = libc::O_EXCL,
204+
const O_NOCTTY = libc::O_NOCTTY,
205+
const O_TRUNC = libc::O_TRUNC,
206+
const O_APPEND = libc::O_APPEND,
207+
const O_NONBLOCK = libc::O_NONBLOCK,
208+
const O_DSYNC = libc::O_DSYNC,
209+
const O_DIRECTORY = libc::O_DIRECTORY,
210+
const O_NOFOLLOW = libc::O_NOFOLLOW,
211+
const O_CLOEXEC = libc::O_CLOEXEC,
212+
const O_SYNC = libc::O_SYNC,
213213
const O_NDELAY = O_NONBLOCK.bits,
214-
const O_FSYNC = O_SYNC.bits
214+
const O_FSYNC = libc::O_FSYNC,
215215
}
216216
);
217217

@@ -224,26 +224,26 @@ mod consts {
224224

225225
#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
226226
mod consts {
227-
use libc::c_int;
227+
use libc::{self, c_int};
228228

229229
bitflags!(
230230
pub flags OFlag: c_int {
231-
const O_ACCMODE = 0x0000003,
232-
const O_RDONLY = 0x0000000,
233-
const O_WRONLY = 0x0000001,
234-
const O_RDWR = 0x0000002,
235-
const O_CREAT = 0x0000200,
236-
const O_EXCL = 0x0000800,
237-
const O_NOCTTY = 0x0008000,
238-
const O_TRUNC = 0x0000400,
239-
const O_APPEND = 0x0000008,
240-
const O_NONBLOCK = 0x0000004,
231+
const O_ACCMODE = libc::O_ACCMODE,
232+
const O_RDONLY = libc::O_RDONLY,
233+
const O_WRONLY = libc::O_WRONLY,
234+
const O_RDWR = libc::O_RDWR,
235+
const O_CREAT = libc::O_CREAT,
236+
const O_EXCL = libc::O_EXCL,
237+
const O_NOCTTY = libc::O_NOCTTY,
238+
const O_TRUNC = libc::O_TRUNC,
239+
const O_APPEND = libc::O_APPEND,
240+
const O_NONBLOCK = libc::O_NONBLOCK,
241241
const O_DIRECTORY = 0x0020000,
242-
const O_NOFOLLOW = 0x0000100,
243-
const O_CLOEXEC = 0x0100000,
244-
const O_SYNC = 0x0000080,
245-
const O_NDELAY = O_NONBLOCK.bits,
246-
const O_FSYNC = O_SYNC.bits,
242+
const O_NOFOLLOW = libc::O_NOFOLLOW,
243+
const O_CLOEXEC = libc::O_CLOEXEC,
244+
const O_SYNC = libc::O_SYNC,
245+
const O_NDELAY = libc::O_NDELAY,
246+
const O_FSYNC = libc::O_FSYNC,
247247
const O_SHLOCK = 0x0000080,
248248
const O_EXLOCK = 0x0000020,
249249
const O_DIRECT = 0x0010000,

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// warnings even though the macro expands into something with allow(dead_code)
1010
#![allow(dead_code)]
1111
#![cfg_attr(test, deny(warnings))]
12+
#![recursion_limit = "500"]
1213

1314
#[macro_use]
1415
extern crate bitflags;

src/mount.rs

+33-36
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,45 @@ use {Errno, Result, NixPath};
44

55
bitflags!(
66
pub flags MsFlags: c_ulong {
7-
const MS_RDONLY = 1 << 0, // Mount read-only
8-
const MS_NOSUID = 1 << 1, // Ignore suid and sgid bits
9-
const MS_NODEV = 1 << 2, // Disallow access to device special files
10-
const MS_NOEXEC = 1 << 3, // Disallow program execution
11-
const MS_SYNCHRONOUS = 1 << 4, // Writes are synced at once
12-
const MS_REMOUNT = 1 << 5, // Alter flags of a mounted FS
13-
const MS_MANDLOCK = 1 << 6, // Allow mandatory locks on a FS
14-
const MS_DIRSYNC = 1 << 7, // Directory modifications are synchronous
15-
const MS_NOATIME = 1 << 10, // Do not update access times
16-
const MS_NODIRATIME = 1 << 11, // Do not update directory access times
17-
const MS_BIND = 1 << 12, // Linux 2.4.0 - Bind directory at different place
18-
const MS_MOVE = 1 << 13,
19-
const MS_REC = 1 << 14,
20-
const MS_VERBOSE = 1 << 15, // Deprecated
21-
const MS_SILENT = 1 << 15,
22-
const MS_POSIXACL = 1 << 16,
23-
const MS_UNBINDABLE = 1 << 17,
24-
const MS_PRIVATE = 1 << 18,
25-
const MS_SLAVE = 1 << 19,
26-
const MS_SHARED = 1 << 20,
27-
const MS_RELATIME = 1 << 21,
28-
const MS_KERNMOUNT = 1 << 22,
29-
const MS_I_VERSION = 1 << 23,
30-
const MS_STRICTATIME = 1 << 24,
7+
const MS_RDONLY = libc::MS_RDONLY, // Mount read-only
8+
const MS_NOSUID = libc::MS_NOSUID, // Ignore suid and sgid bits
9+
const MS_NODEV = libc::MS_NODEV, // Disallow access to device special files
10+
const MS_NOEXEC = libc::MS_NOEXEC, // Disallow program execution
11+
const MS_SYNCHRONOUS = libc::MS_SYNCHRONOUS, // Writes are synced at once
12+
const MS_REMOUNT = libc::MS_REMOUNT, // Alter flags of a mounted FS
13+
const MS_MANDLOCK = libc::MS_MANDLOCK, // Allow mandatory locks on a FS
14+
const MS_DIRSYNC = libc::MS_DIRSYNC, // Directory modifications are synchronous
15+
const MS_NOATIME = libc::MS_NOATIME, // Do not update access times
16+
const MS_NODIRATIME = libc::MS_NODIRATIME, // Do not update directory access times
17+
const MS_BIND = libc::MS_BIND, // Linux 2.4.0 - Bind directory at different place
18+
const MS_MOVE = libc::MS_MOVE,
19+
const MS_REC = libc::MS_REC,
20+
const MS_VERBOSE = 1 << 15, // Deprecated
21+
const MS_SILENT = libc::MS_SILENT,
22+
const MS_POSIXACL = libc::MS_POSIXACL,
23+
const MS_UNBINDABLE = libc::MS_UNBINDABLE,
24+
const MS_PRIVATE = libc::MS_PRIVATE,
25+
const MS_SLAVE = libc::MS_SLAVE,
26+
const MS_SHARED = libc::MS_SHARED,
27+
const MS_RELATIME = libc::MS_RELATIME,
28+
const MS_KERNMOUNT = libc::MS_KERNMOUNT,
29+
const MS_I_VERSION = libc::MS_I_VERSION,
30+
const MS_STRICTATIME = libc::MS_STRICTATIME,
3131
const MS_NOSEC = 1 << 28,
3232
const MS_BORN = 1 << 29,
33-
const MS_ACTIVE = 1 << 30,
34-
const MS_NOUSER = 1 << 31,
35-
const MS_RMT_MASK = MS_RDONLY.bits
36-
| MS_SYNCHRONOUS.bits
37-
| MS_MANDLOCK.bits
38-
| MS_I_VERSION.bits,
39-
const MS_MGC_VAL = 0xC0ED0000,
40-
const MS_MGC_MSK = 0xffff0000
33+
const MS_ACTIVE = libc::MS_ACTIVE,
34+
const MS_NOUSER = libc::MS_NOUSER,
35+
const MS_RMT_MASK = libc::MS_RMT_MASK,
36+
const MS_MGC_VAL = libc::MS_MGC_VAL,
37+
const MS_MGC_MSK = libc::MS_MGC_MSK,
4138
}
4239
);
4340

44-
bitflags!(
41+
libc_bitflags!(
4542
pub flags MntFlags: c_int {
46-
const MNT_FORCE = 1 << 0,
47-
const MNT_DETACH = 1 << 1,
48-
const MNT_EXPIRE = 1 << 2
43+
MNT_FORCE,
44+
MNT_DETACH,
45+
MNT_EXPIRE,
4946
}
5047
);
5148

src/sys/epoll.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ use ::Error;
77

88
bitflags!(
99
#[repr(C)]
10-
pub flags EpollFlags: u32 {
11-
const EPOLLIN = 0x001,
12-
const EPOLLPRI = 0x002,
13-
const EPOLLOUT = 0x004,
14-
const EPOLLRDNORM = 0x040,
15-
const EPOLLRDBAND = 0x080,
16-
const EPOLLWRNORM = 0x100,
17-
const EPOLLWRBAND = 0x200,
18-
const EPOLLMSG = 0x400,
19-
const EPOLLERR = 0x008,
20-
const EPOLLHUP = 0x010,
21-
const EPOLLRDHUP = 0x2000,
10+
pub flags EpollFlags: libc::c_int {
11+
const EPOLLIN = libc::EPOLLIN,
12+
const EPOLLPRI = libc::EPOLLPRI,
13+
const EPOLLOUT = libc::EPOLLOUT,
14+
const EPOLLRDNORM = libc::EPOLLRDNORM,
15+
const EPOLLRDBAND = libc::EPOLLRDBAND,
16+
const EPOLLWRNORM = libc::EPOLLWRNORM,
17+
const EPOLLWRBAND = libc::EPOLLWRBAND,
18+
const EPOLLMSG = libc::EPOLLMSG,
19+
const EPOLLERR = libc::EPOLLERR,
20+
const EPOLLHUP = libc::EPOLLHUP,
21+
const EPOLLRDHUP = libc::EPOLLRDHUP,
2222
const EPOLLEXCLUSIVE = 1 << 28,
23-
const EPOLLWAKEUP = 1 << 29,
24-
const EPOLLONESHOT = 1 << 30,
25-
const EPOLLET = 1 << 31
23+
const EPOLLWAKEUP = libc::EPOLLWAKEUP,
24+
const EPOLLONESHOT = libc::EPOLLONESHOT,
25+
const EPOLLET = libc::EPOLLET,
2626
}
2727
);
2828

@@ -48,15 +48,15 @@ pub struct EpollEvent {
4848

4949
impl EpollEvent {
5050
pub fn new(events: EpollFlags, data: u64) -> Self {
51-
EpollEvent { event: libc::epoll_event { events: events.bits(), u64: data } }
51+
EpollEvent { event: libc::epoll_event { events: events.bits() as u32, u64: data } }
5252
}
5353

5454
pub fn empty() -> Self {
5555
unsafe { mem::zeroed::<EpollEvent>() }
5656
}
5757

5858
pub fn events(&self) -> EpollFlags {
59-
EpollFlags::from_bits(self.event.events).unwrap()
59+
EpollFlags::from_bits(self.event.events as libc::c_int).unwrap()
6060
}
6161

6262
pub fn data(&self) -> u64 {

0 commit comments

Comments
 (0)