Skip to content

Commit e2f9531

Browse files
committed
Merge #725
725: Match syntax of libc_bitflags! with bitflags! r=asomers Also update a couple of constant declarations while we're at it.
2 parents e092257 + 4e2bf09 commit e2f9531

20 files changed

+556
-570
lines changed

CONVENTIONS.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ For example,
5252

5353
```rust
5454
libc_bitflags!{
55-
pub flags ProtFlags: libc::c_int {
56-
PROT_NONE,
57-
PROT_READ,
58-
PROT_WRITE,
59-
PROT_EXEC,
55+
pub struct ProtFlags: libc::c_int {
56+
PROT_NONE;
57+
PROT_READ;
58+
PROT_WRITE;
59+
PROT_EXEC;
6060
#[cfg(any(target_os = "linux", target_os = "android"))]
61-
PROT_GROWSDOWN,
61+
PROT_GROWSDOWN;
6262
#[cfg(any(target_os = "linux", target_os = "android"))]
63-
PROT_GROWSUP,
63+
PROT_GROWSUP;
6464
}
6565
}
6666
```

src/fcntl.rs

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,16 @@ mod ffi {
2020
pub const F_GET_SEALS: c_int = 1034;
2121
}
2222

23-
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
2423
libc_bitflags!{
25-
pub flags AtFlags: c_int {
26-
AT_SYMLINK_NOFOLLOW,
24+
pub struct AtFlags: c_int {
25+
AT_SYMLINK_NOFOLLOW;
2726
#[cfg(any(target_os = "linux", target_os = "android"))]
28-
AT_NO_AUTOMOUNT,
27+
AT_NO_AUTOMOUNT;
2928
#[cfg(any(target_os = "linux", target_os = "android"))]
30-
AT_EMPTY_PATH
29+
AT_EMPTY_PATH;
3130
}
3231
}
3332

34-
#[cfg(any(target_os = "ios", target_os = "macos"))]
35-
bitflags!(
36-
pub struct AtFlags: c_int {
37-
// hack because bitflags require one entry
38-
const EMPTY = 0x0;
39-
}
40-
);
41-
4233
pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag, mode: Mode) -> Result<RawFd> {
4334
let fd = try!(path.with_nix_path(|cstr| {
4435
unsafe { libc::open(cstr.as_ptr(), oflag.bits(), mode.bits() as c_uint) }
@@ -54,7 +45,7 @@ pub fn openat<P: ?Sized + NixPath>(dirfd: RawFd, path: &P, oflag: OFlag, mode: M
5445
Errno::result(fd)
5546
}
5647

57-
fn wrap_readlink_result<'a>(buffer: &'a mut[u8], res: ssize_t)
48+
fn wrap_readlink_result<'a>(buffer: &'a mut[u8], res: ssize_t)
5849
-> Result<&'a OsStr> {
5950
match Errno::result(res) {
6051
Err(err) => Err(err),
@@ -204,11 +195,11 @@ mod consts {
204195
use libc::{self, c_int, c_uint};
205196

206197
libc_bitflags! {
207-
pub flags SpliceFFlags: c_uint {
208-
SPLICE_F_MOVE,
209-
SPLICE_F_NONBLOCK,
210-
SPLICE_F_MORE,
211-
SPLICE_F_GIFT,
198+
pub struct SpliceFFlags: c_uint {
199+
SPLICE_F_MOVE;
200+
SPLICE_F_NONBLOCK;
201+
SPLICE_F_MORE;
202+
SPLICE_F_GIFT;
212203
}
213204
}
214205

@@ -239,8 +230,8 @@ mod consts {
239230
);
240231

241232
libc_bitflags!(
242-
pub flags FdFlag: c_int {
243-
FD_CLOEXEC
233+
pub struct FdFlag: c_int {
234+
FD_CLOEXEC;
244235
}
245236
);
246237

@@ -261,49 +252,49 @@ mod consts {
261252
use libc::{self,c_int};
262253

263254
libc_bitflags!(
264-
pub flags OFlag: c_int {
265-
O_ACCMODE,
266-
O_RDONLY,
267-
O_WRONLY,
268-
O_RDWR,
269-
O_NONBLOCK,
270-
O_APPEND,
271-
O_SHLOCK,
272-
O_EXLOCK,
273-
O_ASYNC,
274-
O_SYNC,
275-
O_NOFOLLOW,
276-
O_CREAT,
277-
O_TRUNC,
278-
O_EXCL,
279-
O_NOCTTY,
280-
O_DIRECTORY,
281-
O_CLOEXEC,
282-
O_FSYNC,
283-
O_NDELAY,
255+
pub struct OFlag: c_int {
256+
O_ACCMODE;
257+
O_RDONLY;
258+
O_WRONLY;
259+
O_RDWR;
260+
O_NONBLOCK;
261+
O_APPEND;
262+
O_SHLOCK;
263+
O_EXLOCK;
264+
O_ASYNC;
265+
O_SYNC;
266+
O_NOFOLLOW;
267+
O_CREAT;
268+
O_TRUNC;
269+
O_EXCL;
270+
O_NOCTTY;
271+
O_DIRECTORY;
272+
O_CLOEXEC;
273+
O_FSYNC;
274+
O_NDELAY;
284275
#[cfg(any(target_os = "netbsd", target_os = "openbsd", target_os = "macos",
285276
target_os = "ios"))]
286-
O_DSYNC,
277+
O_DSYNC;
287278
#[cfg(any(target_os = "netbsd", target_os = "dragonfly", target_os = "freebsd"))]
288-
O_DIRECT,
279+
O_DIRECT;
289280
#[cfg(any(target_os = "netbsd", target_os = "openbsd"))]
290-
O_RSYNC,
281+
O_RSYNC;
291282
#[cfg(target_os = "freebsd")]
292-
O_EXEC,
283+
O_EXEC;
293284
#[cfg(target_os = "freebsd")]
294-
O_TTY_INIT,
285+
O_TTY_INIT;
295286
#[cfg(target_os = "netbsd")]
296-
O_ALT_IO,
287+
O_ALT_IO;
297288
#[cfg(target_os = "netbsd")]
298-
O_NOSIGPIPE,
289+
O_NOSIGPIPE;
299290
#[cfg(target_os = "netbsd")]
300-
O_SEARCH,
291+
O_SEARCH;
301292
}
302293
);
303294

304295
libc_bitflags!(
305-
pub flags FdFlag: c_int {
306-
FD_CLOEXEC
296+
pub struct FdFlag: c_int {
297+
FD_CLOEXEC;
307298
}
308299
);
309300
}

src/macros.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
/// # Example
88
/// ```
99
/// libc_bitflags!{
10-
/// pub flags ProtFlags: libc::c_int {
11-
/// PROT_NONE,
12-
/// PROT_READ,
13-
/// PROT_WRITE,
14-
/// PROT_EXEC,
10+
/// pub struct ProtFlags: libc::c_int {
11+
/// PROT_NONE;
12+
/// PROT_READ;
13+
/// PROT_WRITE;
14+
/// PROT_EXEC;
1515
/// #[cfg(any(target_os = "linux", target_os = "android"))]
16-
/// PROT_GROWSDOWN,
16+
/// PROT_GROWSDOWN;
1717
/// #[cfg(any(target_os = "linux", target_os = "android"))]
18-
/// PROT_GROWSUP,
18+
/// PROT_GROWSUP;
1919
/// }
2020
/// }
2121
/// ```
@@ -26,14 +26,14 @@
2626
///
2727
/// ```
2828
/// libc_bitflags!{
29-
/// pub flags SaFlags: libc::c_ulong {
30-
/// SA_NOCLDSTOP as libc::c_ulong,
31-
/// SA_NOCLDWAIT,
32-
/// SA_NODEFER as libc::c_ulong,
33-
/// SA_ONSTACK,
34-
/// SA_RESETHAND as libc::c_ulong,
35-
/// SA_RESTART as libc::c_ulong,
36-
/// SA_SIGINFO,
29+
/// pub struct SaFlags: libc::c_ulong {
30+
/// SA_NOCLDSTOP as libc::c_ulong;
31+
/// SA_NOCLDWAIT;
32+
/// SA_NODEFER as libc::c_ulong;
33+
/// SA_ONSTACK;
34+
/// SA_RESETHAND as libc::c_ulong;
35+
/// SA_RESTART as libc::c_ulong;
36+
/// SA_SIGINFO;
3737
/// }
3838
/// }
3939
/// ```
@@ -49,7 +49,7 @@ macro_rules! libc_bitflags {
4949
) => {
5050
bitflags! {
5151
$($attrs)*
52-
flags $BitFlags: $T {
52+
struct $BitFlags: $T {
5353
$($flags)*
5454
}
5555
}
@@ -132,7 +132,7 @@ macro_rules! libc_bitflags {
132132
}
133133
};
134134

135-
// Munch last ident if not followed by a comma.
135+
// Munch last ident if not followed by a semicolon.
136136
(@accumulate_flags
137137
$prefix:tt,
138138
[$($flags:tt)*];
@@ -164,11 +164,11 @@ macro_rules! libc_bitflags {
164164
}
165165
};
166166

167-
// Munch an ident; covers terminating comma case.
167+
// Munch an ident; covers terminating semicolon case.
168168
(@accumulate_flags
169169
$prefix:tt,
170170
[$($flags:tt)*];
171-
$flag:ident, $($tail:tt)*
171+
$flag:ident; $($tail:tt)*
172172
) => {
173173
libc_bitflags! {
174174
@accumulate_flags
@@ -181,12 +181,12 @@ macro_rules! libc_bitflags {
181181
}
182182
};
183183

184-
// Munch an ident and cast it to the given type; covers terminating comma
184+
// Munch an ident and cast it to the given type; covers terminating semicolon
185185
// case.
186186
(@accumulate_flags
187187
$prefix:tt,
188188
[$($flags:tt)*];
189-
$flag:ident as $ty:ty, $($tail:tt)*
189+
$flag:ident as $ty:ty; $($tail:tt)*
190190
) => {
191191
libc_bitflags! {
192192
@accumulate_flags
@@ -202,7 +202,7 @@ macro_rules! libc_bitflags {
202202
// (non-pub) Entry rule.
203203
(
204204
$(#[$attr:meta])*
205-
flags $BitFlags:ident: $T:ty {
205+
struct $BitFlags:ident: $T:ty {
206206
$($vals:tt)*
207207
}
208208
) => {
@@ -221,7 +221,7 @@ macro_rules! libc_bitflags {
221221
// (pub) Entry rule.
222222
(
223223
$(#[$attr:meta])*
224-
pub flags $BitFlags:ident: $T:ty {
224+
pub struct $BitFlags:ident: $T:ty {
225225
$($vals:tt)*
226226
}
227227
) => {

src/mount.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ bitflags!(
3939
);
4040

4141
libc_bitflags!(
42-
pub flags MntFlags: c_int {
43-
MNT_FORCE,
44-
MNT_DETACH,
45-
MNT_EXPIRE,
42+
pub struct MntFlags: c_int {
43+
MNT_FORCE;
44+
MNT_DETACH;
45+
MNT_EXPIRE;
4646
}
4747
);
4848

src/mqueue.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ use sys::stat::Mode;
1010
use std::mem;
1111

1212
libc_bitflags!{
13-
pub flags MQ_OFlag: libc::c_int {
14-
O_RDONLY,
15-
O_WRONLY,
16-
O_RDWR,
17-
O_CREAT,
18-
O_EXCL,
19-
O_NONBLOCK,
20-
O_CLOEXEC,
13+
pub struct MQ_OFlag: libc::c_int {
14+
O_RDONLY;
15+
O_WRONLY;
16+
O_RDWR;
17+
O_CREAT;
18+
O_EXCL;
19+
O_NONBLOCK;
20+
O_CLOEXEC;
2121
}
2222
}
2323

2424
libc_bitflags!{
25-
pub flags FdFlag: libc::c_int {
26-
FD_CLOEXEC,
25+
pub struct FdFlag: libc::c_int {
26+
FD_CLOEXEC;
2727
}
2828
}
2929

src/poll.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ impl PollFd {
4242

4343
libc_bitflags! {
4444
/// These flags define the different events that can be monitored by `poll` and `ppoll`
45-
pub flags EventFlags: libc::c_short {
45+
pub struct EventFlags: libc::c_short {
4646
/// There is data to read.
47-
POLLIN,
47+
POLLIN;
4848
/// There is some exceptional condition on the file descriptor.
4949
///
5050
/// Possibilities include:
@@ -56,37 +56,37 @@ libc_bitflags! {
5656
/// [ioctl_tty(2)](http://man7.org/linux/man-pages/man2/ioctl_tty.2.html)).
5757
/// * A cgroup.events file has been modified (see
5858
/// [cgroups(7)](http://man7.org/linux/man-pages/man7/cgroups.7.html)).
59-
POLLPRI,
59+
POLLPRI;
6060
/// Writing is now possible, though a write larger that the
6161
/// available space in a socket or pipe will still block (unless
6262
/// `O_NONBLOCK` is set).
63-
POLLOUT,
63+
POLLOUT;
6464
/// Equivalent to [`POLLIN`](constant.POLLIN.html)
65-
POLLRDNORM,
65+
POLLRDNORM;
6666
/// Equivalent to [`POLLOUT`](constant.POLLOUT.html)
67-
POLLWRNORM,
67+
POLLWRNORM;
6868
/// Priority band data can be read (generally unused on Linux).
69-
POLLRDBAND,
69+
POLLRDBAND;
7070
/// Priority data may be written.
71-
POLLWRBAND,
71+
POLLWRBAND;
7272
/// Error condition (only returned in
7373
/// [`PollFd::revents`](struct.PollFd.html#method.revents);
7474
/// ignored in [`PollFd::new`](struct.PollFd.html#method.new)).
7575
/// This bit is also set for a file descriptor referring to the
7676
/// write end of a pipe when the read end has been closed.
77-
POLLERR,
77+
POLLERR;
7878
/// Hang up (only returned in [`PollFd::revents`](struct.PollFd.html#method.revents);
7979
/// ignored in [`PollFd::new`](struct.PollFd.html#method.new)).
8080
/// Note that when reading from a channel such as a pipe or a stream
8181
/// socket, this event merely indicates that the peer closed its
8282
/// end of the channel. Subsequent reads from the channel will
8383
/// return 0 (end of file) only after all outstanding data in the
8484
/// channel has been consumed.
85-
POLLHUP,
85+
POLLHUP;
8686
/// Invalid request: `fd` not open (only returned in
8787
/// [`PollFd::revents`](struct.PollFd.html#method.revents);
8888
/// ignored in [`PollFd::new`](struct.PollFd.html#method.new)).
89-
POLLNVAL,
89+
POLLNVAL;
9090
}
9191
}
9292

0 commit comments

Comments
 (0)