summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fcntl.rs93
-rw-r--r--src/macros.rs46
-rw-r--r--src/mount.rs8
-rw-r--r--src/mqueue.rs20
-rw-r--r--src/poll.rs22
-rw-r--r--src/sched.rs48
-rw-r--r--src/sys/epoll.rs44
-rw-r--r--src/sys/event.rs118
-rw-r--r--src/sys/eventfd.rs8
-rw-r--r--src/sys/mman.rs72
-rw-r--r--src/sys/quota.rs36
-rw-r--r--src/sys/select.rs111
-rw-r--r--src/sys/signal.rs48
-rw-r--r--src/sys/signalfd.rs6
-rw-r--r--src/sys/socket/mod.rs132
-rw-r--r--src/sys/stat.rs53
-rw-r--r--src/sys/termios.rs184
-rw-r--r--src/sys/utsname.rs39
-rw-r--r--src/sys/wait.rs24
19 files changed, 549 insertions, 563 deletions
diff --git a/src/fcntl.rs b/src/fcntl.rs
index 7bf43645..e42c923e 100644
--- a/src/fcntl.rs
+++ b/src/fcntl.rs
@@ -20,25 +20,16 @@ mod ffi {
pub const F_GET_SEALS: c_int = 1034;
}
-#[cfg(not(any(target_os = "ios", target_os = "macos")))]
libc_bitflags!{
- pub flags AtFlags: c_int {
- AT_SYMLINK_NOFOLLOW,
+ pub struct AtFlags: c_int {
+ AT_SYMLINK_NOFOLLOW;
#[cfg(any(target_os = "linux", target_os = "android"))]
- AT_NO_AUTOMOUNT,
+ AT_NO_AUTOMOUNT;
#[cfg(any(target_os = "linux", target_os = "android"))]
- AT_EMPTY_PATH
+ AT_EMPTY_PATH;
}
}
-#[cfg(any(target_os = "ios", target_os = "macos"))]
-bitflags!(
- pub struct AtFlags: c_int {
- // hack because bitflags require one entry
- const EMPTY = 0x0;
- }
-);
-
pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag, mode: Mode) -> Result<RawFd> {
let fd = try!(path.with_nix_path(|cstr| {
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
Errno::result(fd)
}
-fn wrap_readlink_result<'a>(buffer: &'a mut[u8], res: ssize_t)
+fn wrap_readlink_result<'a>(buffer: &'a mut[u8], res: ssize_t)
-> Result<&'a OsStr> {
match Errno::result(res) {
Err(err) => Err(err),
@@ -204,11 +195,11 @@ mod consts {
use libc::{self, c_int, c_uint};
libc_bitflags! {
- pub flags SpliceFFlags: c_uint {
- SPLICE_F_MOVE,
- SPLICE_F_NONBLOCK,
- SPLICE_F_MORE,
- SPLICE_F_GIFT,
+ pub struct SpliceFFlags: c_uint {
+ SPLICE_F_MOVE;
+ SPLICE_F_NONBLOCK;
+ SPLICE_F_MORE;
+ SPLICE_F_GIFT;
}
}
@@ -239,8 +230,8 @@ mod consts {
);
libc_bitflags!(
- pub flags FdFlag: c_int {
- FD_CLOEXEC
+ pub struct FdFlag: c_int {
+ FD_CLOEXEC;
}
);
@@ -261,49 +252,49 @@ mod consts {
use libc::{self,c_int};
libc_bitflags!(
- pub flags OFlag: c_int {
- O_ACCMODE,
- O_RDONLY,
- O_WRONLY,
- O_RDWR,
- O_NONBLOCK,
- O_APPEND,
- O_SHLOCK,
- O_EXLOCK,
- O_ASYNC,
- O_SYNC,
- O_NOFOLLOW,
- O_CREAT,
- O_TRUNC,
- O_EXCL,
- O_NOCTTY,
- O_DIRECTORY,
- O_CLOEXEC,
- O_FSYNC,
- O_NDELAY,
+ pub struct OFlag: c_int {
+ O_ACCMODE;
+ O_RDONLY;
+ O_WRONLY;
+ O_RDWR;
+ O_NONBLOCK;
+ O_APPEND;
+ O_SHLOCK;
+ O_EXLOCK;
+ O_ASYNC;
+ O_SYNC;
+ O_NOFOLLOW;
+ O_CREAT;
+ O_TRUNC;
+ O_EXCL;
+ O_NOCTTY;
+ O_DIRECTORY;
+ O_CLOEXEC;
+ O_FSYNC;
+ O_NDELAY;
#[cfg(any(target_os = "netbsd", target_os = "openbsd", target_os = "macos",
target_os = "ios"))]
- O_DSYNC,
+ O_DSYNC;
#[cfg(any(target_os = "netbsd", target_os = "dragonfly", target_os = "freebsd"))]
- O_DIRECT,
+ O_DIRECT;
#[cfg(any(target_os = "netbsd", target_os = "openbsd"))]
- O_RSYNC,
+ O_RSYNC;
#[cfg(target_os = "freebsd")]
- O_EXEC,
+ O_EXEC;
#[cfg(target_os = "freebsd")]
- O_TTY_INIT,
+ O_TTY_INIT;
#[cfg(target_os = "netbsd")]
- O_ALT_IO,
+ O_ALT_IO;
#[cfg(target_os = "netbsd")]
- O_NOSIGPIPE,
+ O_NOSIGPIPE;
#[cfg(target_os = "netbsd")]
- O_SEARCH,
+ O_SEARCH;
}
);
libc_bitflags!(
- pub flags FdFlag: c_int {
- FD_CLOEXEC
+ pub struct FdFlag: c_int {
+ FD_CLOEXEC;
}
);
}
diff --git a/src/macros.rs b/src/macros.rs
index d8284f71..7a0eb07c 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -7,15 +7,15 @@
/// # Example
/// ```
/// libc_bitflags!{
-/// pub flags ProtFlags: libc::c_int {
-/// PROT_NONE,
-/// PROT_READ,
-/// PROT_WRITE,
-/// PROT_EXEC,
+/// pub struct ProtFlags: libc::c_int {
+/// PROT_NONE;
+/// PROT_READ;
+/// PROT_WRITE;
+/// PROT_EXEC;
/// #[cfg(any(target_os = "linux", target_os = "android"))]
-/// PROT_GROWSDOWN,
+/// PROT_GROWSDOWN;
/// #[cfg(any(target_os = "linux", target_os = "android"))]
-/// PROT_GROWSUP,
+/// PROT_GROWSUP;
/// }
/// }
/// ```
@@ -26,14 +26,14 @@
///
/// ```
/// libc_bitflags!{
-/// pub flags SaFlags: libc::c_ulong {
-/// SA_NOCLDSTOP as libc::c_ulong,
-/// SA_NOCLDWAIT,
-/// SA_NODEFER as libc::c_ulong,
-/// SA_ONSTACK,
-/// SA_RESETHAND as libc::c_ulong,
-/// SA_RESTART as libc::c_ulong,
-/// SA_SIGINFO,
+/// pub struct SaFlags: libc::c_ulong {
+/// SA_NOCLDSTOP as libc::c_ulong;
+/// SA_NOCLDWAIT;
+/// SA_NODEFER as libc::c_ulong;
+/// SA_ONSTACK;
+/// SA_RESETHAND as libc::c_ulong;
+/// SA_RESTART as libc::c_ulong;
+/// SA_SIGINFO;
/// }
/// }
/// ```
@@ -49,7 +49,7 @@ macro_rules! libc_bitflags {
) => {
bitflags! {
$($attrs)*
- flags $BitFlags: $T {
+ struct $BitFlags: $T {
$($flags)*
}
}
@@ -132,7 +132,7 @@ macro_rules! libc_bitflags {
}
};
- // Munch last ident if not followed by a comma.
+ // Munch last ident if not followed by a semicolon.
(@accumulate_flags
$prefix:tt,
[$($flags:tt)*];
@@ -164,11 +164,11 @@ macro_rules! libc_bitflags {
}
};
- // Munch an ident; covers terminating comma case.
+ // Munch an ident; covers terminating semicolon case.
(@accumulate_flags
$prefix:tt,
[$($flags:tt)*];
- $flag:ident, $($tail:tt)*
+ $flag:ident; $($tail:tt)*
) => {
libc_bitflags! {
@accumulate_flags
@@ -181,12 +181,12 @@ macro_rules! libc_bitflags {
}
};
- // Munch an ident and cast it to the given type; covers terminating comma
+ // Munch an ident and cast it to the given type; covers terminating semicolon
// case.
(@accumulate_flags
$prefix:tt,
[$($flags:tt)*];
- $flag:ident as $ty:ty, $($tail:tt)*
+ $flag:ident as $ty:ty; $($tail:tt)*
) => {
libc_bitflags! {
@accumulate_flags
@@ -202,7 +202,7 @@ macro_rules! libc_bitflags {
// (non-pub) Entry rule.
(
$(#[$attr:meta])*
- flags $BitFlags:ident: $T:ty {
+ struct $BitFlags:ident: $T:ty {
$($vals:tt)*
}
) => {
@@ -221,7 +221,7 @@ macro_rules! libc_bitflags {
// (pub) Entry rule.
(
$(#[$attr:meta])*
- pub flags $BitFlags:ident: $T:ty {
+ pub struct $BitFlags:ident: $T:ty {
$($vals:tt)*
}
) => {
diff --git a/src/mount.rs b/src/mount.rs
index 75e918c6..ccfd5427 100644
--- a/src/mount.rs
+++ b/src/mount.rs
@@ -39,10 +39,10 @@ bitflags!(
);
libc_bitflags!(
- pub flags MntFlags: c_int {
- MNT_FORCE,
- MNT_DETACH,
- MNT_EXPIRE,
+ pub struct MntFlags: c_int {
+ MNT_FORCE;
+ MNT_DETACH;
+ MNT_EXPIRE;
}
);
diff --git a/src/mqueue.rs b/src/mqueue.rs
index 2c127502..af4ebe77 100644
--- a/src/mqueue.rs
+++ b/src/mqueue.rs
@@ -10,20 +10,20 @@ use sys::stat::Mode;
use std::mem;
libc_bitflags!{
- pub flags MQ_OFlag: libc::c_int {
- O_RDONLY,
- O_WRONLY,
- O_RDWR,
- O_CREAT,
- O_EXCL,
- O_NONBLOCK,
- O_CLOEXEC,
+ pub struct MQ_OFlag: libc::c_int {
+ O_RDONLY;
+ O_WRONLY;
+ O_RDWR;
+ O_CREAT;
+ O_EXCL;
+ O_NONBLOCK;
+ O_CLOEXEC;
}
}
libc_bitflags!{
- pub flags FdFlag: libc::c_int {
- FD_CLOEXEC,
+ pub struct FdFlag: libc::c_int {
+ FD_CLOEXEC;
}
}
diff --git a/src/poll.rs b/src/poll.rs
index 60c31ace..25ff170f 100644
--- a/src/poll.rs
+++ b/src/poll.rs
@@ -42,9 +42,9 @@ impl PollFd {
libc_bitflags! {
/// These flags define the different events that can be monitored by `poll` and `ppoll`
- pub flags EventFlags: libc::c_short {
+ pub struct EventFlags: libc::c_short {
/// There is data to read.
- POLLIN,
+ POLLIN;
/// There is some exceptional condition on the file descriptor.
///
/// Possibilities include:
@@ -56,25 +56,25 @@ libc_bitflags! {
/// [ioctl_tty(2)](http://man7.org/linux/man-pages/man2/ioctl_tty.2.html)).
/// * A cgroup.events file has been modified (see
/// [cgroups(7)](http://man7.org/linux/man-pages/man7/cgroups.7.html)).
- POLLPRI,
+ POLLPRI;
/// Writing is now possible, though a write larger that the
/// available space in a socket or pipe will still block (unless
/// `O_NONBLOCK` is set).
- POLLOUT,
+ POLLOUT;
/// Equivalent to [`POLLIN`](constant.POLLIN.html)
- POLLRDNORM,
+ POLLRDNORM;
/// Equivalent to [`POLLOUT`](constant.POLLOUT.html)
- POLLWRNORM,
+ POLLWRNORM;
/// Priority band data can be read (generally unused on Linux).
- POLLRDBAND,
+ POLLRDBAND;
/// Priority data may be written.
- POLLWRBAND,
+ POLLWRBAND;
/// Error condition (only returned in
/// [`PollFd::revents`](struct.PollFd.html#method.revents);
/// ignored in [`PollFd::new`](struct.PollFd.html#method.new)).
/// This bit is also set for a file descriptor referring to the
/// write end of a pipe when the read end has been closed.
- POLLERR,
+ POLLERR;
/// Hang up (only returned in [`PollFd::revents`](struct.PollFd.html#method.revents);
/// ignored in [`PollFd::new`](struct.PollFd.html#method.new)).
/// Note that when reading from a channel such as a pipe or a stream
@@ -82,11 +82,11 @@ libc_bitflags! {
/// end of the channel. Subsequent reads from the channel will
/// return 0 (end of file) only after all outstanding data in the
/// channel has been consumed.
- POLLHUP,
+ POLLHUP;
/// Invalid request: `fd` not open (only returned in
/// [`PollFd::revents`](struct.PollFd.html#method.revents);
/// ignored in [`PollFd::new`](struct.PollFd.html#method.new)).
- POLLNVAL,
+ POLLNVAL;
}
}
diff --git a/src/sched.rs b/src/sched.rs
index 9543e50d..943b432b 100644
--- a/src/sched.rs
+++ b/src/sched.rs
@@ -8,30 +8,30 @@ use ::unistd::Pid;
// For some functions taking with a parameter of type CloneFlags,
// only a subset of these flags have an effect.
libc_bitflags!{
- pub flags CloneFlags: libc::c_int {
- CLONE_VM,
- CLONE_FS,
- CLONE_FILES,
- CLONE_SIGHAND,
- CLONE_PTRACE,
- CLONE_VFORK,
- CLONE_PARENT,
- CLONE_THREAD,
- CLONE_NEWNS,
- CLONE_SYSVSEM,
- CLONE_SETTLS,
- CLONE_PARENT_SETTID,
- CLONE_CHILD_CLEARTID,
- CLONE_DETACHED,
- CLONE_UNTRACED,
- CLONE_CHILD_SETTID,
- CLONE_NEWCGROUP,
- CLONE_NEWUTS,
- CLONE_NEWIPC,
- CLONE_NEWUSER,
- CLONE_NEWPID,
- CLONE_NEWNET,
- CLONE_IO,
+ pub struct CloneFlags: libc::c_int {
+ CLONE_VM;
+ CLONE_FS;
+ CLONE_FILES;
+ CLONE_SIGHAND;
+ CLONE_PTRACE;
+ CLONE_VFORK;
+ CLONE_PARENT;
+ CLONE_THREAD;
+ CLONE_NEWNS;
+ CLONE_SYSVSEM;
+ CLONE_SETTLS;
+ CLONE_PARENT_SETTID;
+ CLONE_CHILD_CLEARTID;
+ CLONE_DETACHED;
+ CLONE_UNTRACED;
+ CLONE_CHILD_SETTID;
+ CLONE_NEWCGROUP;
+ CLONE_NEWUTS;
+ CLONE_NEWIPC;
+ CLONE_NEWUSER;
+ CLONE_NEWPID;
+ CLONE_NEWNET;
+ CLONE_IO;
}
}
diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs
index df48b9af..5ab766dc 100644
--- a/src/sys/epoll.rs
+++ b/src/sys/epoll.rs
@@ -6,38 +6,38 @@ use std::mem;
use ::Error;
libc_bitflags!(
- pub flags EpollFlags: libc::c_int {
- EPOLLIN,
- EPOLLPRI,
- EPOLLOUT,
- EPOLLRDNORM,
- EPOLLRDBAND,
- EPOLLWRNORM,
- EPOLLWRBAND,
- EPOLLMSG,
- EPOLLERR,
- EPOLLHUP,
- EPOLLRDHUP,
+ pub struct EpollFlags: libc::c_int {
+ EPOLLIN;
+ EPOLLPRI;
+ EPOLLOUT;
+ EPOLLRDNORM;
+ EPOLLRDBAND;
+ EPOLLWRNORM;
+ EPOLLWRBAND;
+ EPOLLMSG;
+ EPOLLERR;
+ EPOLLHUP;
+ EPOLLRDHUP;
#[cfg(target_os = "linux")] // Added in 4.5; not in Android.
- EPOLLEXCLUSIVE,
+ EPOLLEXCLUSIVE;
#[cfg(not(target_arch = "mips"))]
- EPOLLWAKEUP,
- EPOLLONESHOT,
- EPOLLET,
+ EPOLLWAKEUP;
+ EPOLLONESHOT;
+ EPOLLET;
}
);
#[derive(Clone, Copy, Eq, PartialEq)]
-#[repr(C)]
+#[repr(i32)]
pub enum EpollOp {
- EpollCtlAdd = 1,
- EpollCtlDel = 2,
- EpollCtlMod = 3
+ EpollCtlAdd = libc::EPOLL_CTL_ADD,
+ EpollCtlDel = libc::EPOLL_CTL_DEL,
+ EpollCtlMod = libc::EPOLL_CTL_MOD,
}
libc_bitflags!{
- pub flags EpollCreateFlags: c_int {
- EPOLL_CLOEXEC,
+ pub struct EpollCreateFlags: c_int {
+ EPOLL_CLOEXEC;
}
}
diff --git a/src/sys/event.rs b/src/sys/event.rs
index 9215c654..1f9c1251 100644
--- a/src/sys/event.rs
+++ b/src/sys/event.rs
@@ -84,11 +84,11 @@ pub type type_of_event_flag = u16;
#[cfg(any(target_os = "netbsd"))]
pub type type_of_event_flag = u32;
libc_bitflags!{
- pub flags EventFlag: type_of_event_flag {
- EV_ADD,
- EV_CLEAR,
- EV_DELETE,
- EV_DISABLE,
+ pub struct EventFlag: type_of_event_flag {
+ EV_ADD;
+ EV_CLEAR;
+ EV_DELETE;
+ EV_DISABLE;
// No released version of OpenBSD supports EV_DISPATCH or EV_RECEIPT.
// These have been commited to the -current branch though and are
// expected to be part of the OpenBSD 6.2 release in Nov 2017.
@@ -97,117 +97,117 @@ libc_bitflags!{
#[cfg(any(target_os = "dragonfly", target_os = "freebsd",
target_os = "ios", target_os = "macos",
target_os = "netbsd"))]
- EV_DISPATCH,
+ EV_DISPATCH;
#[cfg(target_os = "freebsd")]
- EV_DROP,
- EV_ENABLE,
- EV_EOF,
- EV_ERROR,
+ EV_DROP;
+ EV_ENABLE;
+ EV_EOF;
+ EV_ERROR;
#[cfg(any(target_os = "macos", target_os = "ios"))]
- EV_FLAG0,
- EV_FLAG1,
+ EV_FLAG0;
+ EV_FLAG1;
#[cfg(target_os = "dragonfly")]
- EV_NODATA,
- EV_ONESHOT,
+ EV_NODATA;
+ EV_ONESHOT;
#[cfg(any(target_os = "macos", target_os = "ios"))]
- EV_OOBAND,
+ EV_OOBAND;
#[cfg(any(target_os = "macos", target_os = "ios"))]
- EV_POLL,
+ EV_POLL;
#[cfg(any(target_os = "dragonfly", target_os = "freebsd",
target_os = "ios", target_os = "macos",
target_os = "netbsd"))]
- EV_RECEIPT,
- EV_SYSFLAGS,
+ EV_RECEIPT;
+ EV_SYSFLAGS;
}
}
libc_bitflags!(
- pub flags FilterFlag: u32 {
+ pub struct FilterFlag: u32 {
#[cfg(any(target_os = "macos", target_os = "ios"))]
- NOTE_ABSOLUTE,
- NOTE_ATTRIB,
- NOTE_CHILD,
- NOTE_DELETE,
+ NOTE_ABSOLUTE;
+ NOTE_ATTRIB;
+ NOTE_CHILD;
+ NOTE_DELETE;
#[cfg(target_os = "openbsd")]
- NOTE_EOF,
- NOTE_EXEC,
- NOTE_EXIT,
+ NOTE_EOF;
+ NOTE_EXEC;
+ NOTE_EXIT;
#[cfg(any(target_os = "macos", target_os = "ios"))]
- NOTE_EXIT_REPARENTED,
+ NOTE_EXIT_REPARENTED;
#[cfg(any(target_os = "macos", target_os = "ios"))]
- NOTE_EXITSTATUS,
- NOTE_EXTEND,
+ NOTE_EXITSTATUS;
+ NOTE_EXTEND;
#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly"))]
- NOTE_FFAND,
+ NOTE_FFAND;
#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly"))]
- NOTE_FFCOPY,
+ NOTE_FFCOPY;
#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly"))]
- NOTE_FFCTRLMASK,
+ NOTE_FFCTRLMASK;
#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly"))]
- NOTE_FFLAGSMASK,
+ NOTE_FFLAGSMASK;
#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly"))]
- NOTE_FFNOP,
+ NOTE_FFNOP;
#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly"))]
- NOTE_FFOR,
- NOTE_FORK,
- NOTE_LINK,
- NOTE_LOWAT,
+ NOTE_FFOR;
+ NOTE_FORK;
+ NOTE_LINK;
+ NOTE_LOWAT;
#[cfg(target_os = "freebsd")]
- NOTE_MSECONDS,
+ NOTE_MSECONDS;
#[cfg(any(target_os = "macos", target_os = "ios"))]
- NOTE_NONE,
+ NOTE_NONE;
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd"))]
- NOTE_NSECONDS,
+ NOTE_NSECONDS;
#[cfg(target_os = "dragonfly")]
- NOTE_OOB,
- NOTE_PCTRLMASK,
- NOTE_PDATAMASK,
+ NOTE_OOB;
+ NOTE_PCTRLMASK;
+ NOTE_PDATAMASK;
#[cfg(any(target_os = "macos", target_os = "ios"))]
- NOTE_REAP,
- NOTE_RENAME,
- NOTE_REVOKE,
+ NOTE_REAP;
+ NOTE_RENAME;
+ NOTE_REVOKE;
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd"))]
- NOTE_SECONDS,
+ NOTE_SECONDS;
#[cfg(any(target_os = "macos", target_os = "ios"))]
- NOTE_SIGNAL,
- NOTE_TRACK,
- NOTE_TRACKERR,
+ NOTE_SIGNAL;
+ NOTE_TRACK;
+ NOTE_TRACKERR;
#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly"))]
- NOTE_TRIGGER,
+ NOTE_TRIGGER;
#[cfg(target_os = "openbsd")]
- NOTE_TRUNCATE,
+ NOTE_TRUNCATE;
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd"))]
- NOTE_USECONDS,
+ NOTE_USECONDS;
#[cfg(any(target_os = "macos", target_os = "ios"))]
- NOTE_VM_ERROR,
+ NOTE_VM_ERROR;
#[cfg(any(target_os = "macos", target_os = "ios"))]
- NOTE_VM_PRESSURE,
+ NOTE_VM_PRESSURE;
#[cfg(any(target_os = "macos", target_os = "ios"))]
- NOTE_VM_PRESSURE_SUDDEN_TERMINATE,
+ NOTE_VM_PRESSURE_SUDDEN_TERMINATE;
#[cfg(any(target_os = "macos", target_os = "ios"))]
- NOTE_VM_PRESSURE_TERMINATE,
- NOTE_WRITE,
+ NOTE_VM_PRESSURE_TERMINATE;
+ NOTE_WRITE;
}
);
diff --git a/src/sys/eventfd.rs b/src/sys/eventfd.rs
index ad23dec7..51091478 100644
--- a/src/sys/eventfd.rs
+++ b/src/sys/eventfd.rs
@@ -3,10 +3,10 @@ use std::os::unix::io::RawFd;
use {Errno, Result};
libc_bitflags! {
- pub flags EfdFlags: libc::c_int {
- EFD_CLOEXEC, // Since Linux 2.6.27
- EFD_NONBLOCK, // Since Linux 2.6.27
- EFD_SEMAPHORE, // Since Linux 2.6.30
+ pub struct EfdFlags: libc::c_int {
+ EFD_CLOEXEC; // Since Linux 2.6.27
+ EFD_NONBLOCK; // Since Linux 2.6.27
+ EFD_SEMAPHORE; // Since Linux 2.6.30
}
}
diff --git a/src/sys/mman.rs b/src/sys/mman.rs
index e1ddc38f..dc21899b 100644
--- a/src/sys/mman.rs
+++ b/src/sys/mman.rs
@@ -6,94 +6,94 @@ use std::os::unix::io::RawFd;
libc_bitflags!{
/// Desired memory protection of a memory mapping.
- pub flags ProtFlags: libc::c_int {
+ pub struct ProtFlags: libc::c_int {
/// Pages cannot be accessed.
- PROT_NONE,
+ PROT_NONE;
/// Pages can be read.
- PROT_READ,
+ PROT_READ;
/// Pages can be written.
- PROT_WRITE,
+ PROT_WRITE;
/// Pages can be executed
- PROT_EXEC,
+ PROT_EXEC;
/// Apply protection up to the end of a mapping that grows upwards.
#[cfg(any(target_os = "android", target_os = "linux"))]
- PROT_GROWSDOWN,
+ PROT_GROWSDOWN;
/// Apply protection down to the beginning of a mapping that grows downwards.
#[cfg(any(target_os = "android", target_os = "linux"))]
- PROT_GROWSUP,
+ PROT_GROWSUP;
}
}
libc_bitflags!{
/// Additional parameters for `mmap()`.
- pub flags MapFlags: c_int {
+ pub struct MapFlags: c_int {
/// Compatibility flag. Ignored.
- MAP_FILE,
+ MAP_FILE;
/// Share this mapping. Mutually exclusive with `MAP_PRIVATE`.
- MAP_SHARED,
+ MAP_SHARED;
/// Create a private copy-on-write mapping. Mutually exclusive with `MAP_SHARED`.
- MAP_PRIVATE,
+ MAP_PRIVATE;
/// Place the mapping at exactly the address specified in `addr`.
- MAP_FIXED,
+ MAP_FIXED;
/// Synonym for `MAP_ANONYMOUS`.
- MAP_ANON,
+ MAP_ANON;
/// The mapping is not backed by any file.
#[cfg(any(target_os = "android", target_os = "linux", target_os = "freebsd"))]
- MAP_ANONYMOUS,
+ MAP_ANONYMOUS;
/// Put the mapping into the first 2GB of the process address space.
#[cfg(any(all(any(target_os = "android", target_os = "linux"),
any(target_arch = "x86", target_arch = "x86_64")),
all(target_os = "linux", target_env = "musl", any(target_arch = "x86", target_pointer_width = "64")),
all(target_os = "freebsd", target_pointer_width = "64")))]
- MAP_32BIT,
+ MAP_32BIT;
/// Used for stacks; indicates to the kernel that the mapping should extend downward in memory.
#[cfg(any(target_os = "android", target_os = "linux"))]
- MAP_GROWSDOWN,
+ MAP_GROWSDOWN;
/// Compatibility flag. Ignored.
#[cfg(any(target_os = "android", target_os = "linux"))]
- MAP_DENYWRITE,
+ MAP_DENYWRITE;
/// Compatibility flag. Ignored.
#[cfg(any(target_os = "android", target_os = "linux"))]
- MAP_EXECUTABLE,
+ MAP_EXECUTABLE;
/// Mark the mmaped region to be locked in the same way as `mlock(2)`.
#[cfg(any(target_os = "android", target_os = "linux"))]
- MAP_LOCKED,
+ MAP_LOCKED;
/// Do not reserve swap space for this mapping.
///
/// This was removed in FreeBSD 11.
#[cfg(not(target_os = "freebsd"))]
- MAP_NORESERVE,
+ MAP_NORESERVE;
/// Populate page tables for a mapping.
#[cfg(any(target_os = "android", target_os = "linux"))]
- MAP_POPULATE,
+ MAP_POPULATE;
/// Only meaningful when used with `MAP_POPULATE`. Don't perform read-ahead.
#[cfg(any(target_os = "android", target_os = "linux"))]
- MAP_NONBLOCK,
+ MAP_NONBLOCK;
/// Allocate the mapping using "huge pages."
#[cfg(any(target_os = "android", target_os = "linux"))]
- MAP_HUGETLB,
+ MAP_HUGETLB;
/// Lock the mapped region into memory as with `mlock(2)`.
#[cfg(target_os = "netbsd")]
- MAP_WIRED,
+ MAP_WIRED;
/// Causes dirtied data in the specified range to be flushed to disk only when necessary.
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
- MAP_NOSYNC,
+ MAP_NOSYNC;
/// Rename private pages to a file.
///
/// This was removed in FreeBSD 11.
#[cfg(any(target_os = "dragonfly", target_os = "netbsd", target_os = "openbsd"))]
- MAP_RENAME,
+ MAP_RENAME;
/// Region may contain semaphores.
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
- MAP_HASSEMAPHORE,
+ MAP_HASSEMAPHORE;
/// Region grows down, like a stack.
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
- MAP_STACK,
+ MAP_STACK;
/// Pages in this mapping are not retained in the kernel's memory cache.
#[cfg(any(target_os = "ios", target_os = "macos"))]
- MAP_NOCACHE,
+ MAP_NOCACHE;
#[cfg(any(target_os = "ios", target_os = "macos"))]
- MAP_JIT,
+ MAP_JIT;
}
}
@@ -185,19 +185,19 @@ libc_enum!{
libc_bitflags!{
/// Configuration flags for `msync`.
- pub flags MsFlags: c_int {
+ pub struct MsFlags: c_int {
/// Schedule an update but return immediately.
- MS_ASYNC,
+ MS_ASYNC;
/// Invalidate all cached data.
- MS_INVALIDATE,
+ MS_INVALIDATE;
/// Invalidate pages, but leave them mapped.
#[cfg(any(target_os = "ios", target_os = "macos"))]
- MS_KILLPAGES,
+ MS_KILLPAGES;
/// Deactivate pages, but leave them mapped.
#[cfg(any(target_os = "ios", target_os = "macos"))]
- MS_DEACTIVATE,
+ MS_DEACTIVATE;
/// Perform an update and wait for it to complete.
- MS_SYNC,
+ MS_SYNC;
}
}
diff --git a/src/sys/quota.rs b/src/sys/quota.rs
index 0b39fcf2..1cd143bd 100644
--- a/src/sys/quota.rs
+++ b/src/sys/quota.rs
@@ -1,5 +1,5 @@
use {Errno, Result, NixPath};
-use libc::{c_int, c_char};
+use libc::{self, c_int, c_char};
#[cfg(all(target_os = "linux",
any(target_arch = "x86",
@@ -41,17 +41,17 @@ pub mod quota {
libc_bitflags!(
#[derive(Default)]
- pub flags QuotaValidFlags: u32 {
- QIF_BLIMITS,
- QIF_SPACE,
- QIF_ILIMITS,
- QIF_INODES,
- QIF_BTIME,
- QIF_ITIME,
- QIF_LIMITS,
- QIF_USAGE,
- QIF_TIMES,
- QIF_ALL,
+ pub struct QuotaValidFlags: u32 {
+ QIF_BLIMITS;
+ QIF_SPACE;
+ QIF_ILIMITS;
+ QIF_INODES;
+ QIF_BTIME;
+ QIF_ITIME;
+ QIF_LIMITS;
+ QIF_USAGE;
+ QIF_TIMES;
+ QIF_ALL;
}
);
@@ -70,14 +70,6 @@ pub mod quota {
}
}
-mod ffi {
- use libc::{c_int, c_char};
-
- extern {
- pub fn quotactl(cmd: c_int, special: * const c_char, id: c_int, data: *mut c_char) -> c_int;
- }
-}
-
use std::ptr;
fn quotactl<P: ?Sized + NixPath>(cmd: quota::QuotaCmd, special: Option<&P>, id: c_int, addr: *mut c_char) -> Result<()> {
@@ -85,8 +77,8 @@ fn quotactl<P: ?Sized + NixPath>(cmd: quota::QuotaCmd, special: Option<&P>, id:
Errno::clear();
let res = try!(
match special {
- Some(dev) => dev.with_nix_path(|path| ffi::quotactl(cmd.as_int(), path.as_ptr(), id, addr)),
- None => Ok(ffi::quotactl(cmd.as_int(), ptr::null(), id, addr)),
+ Some(dev) => dev.with_nix_path(|path| libc::quotactl(cmd.as_int(), path.as_ptr(), id, addr)),
+ None => Ok(libc::quotactl(cmd.as_int(), ptr::null(), id, addr)),
}
);
diff --git a/src/sys/select.rs b/src/sys/select.rs
index 82b2aad3..07190fa1 100644
--- a/src/sys/select.rs
+++ b/src/sys/select.rs
@@ -1,57 +1,37 @@
-use std::ptr::null_mut;
+use std::mem;
use std::os::unix::io::RawFd;
-use libc::{c_int, timeval};
+use std::ptr::null_mut;
+use libc::{self, c_int};
use {Errno, Result};
use sys::time::TimeVal;
-pub const FD_SETSIZE: RawFd = 1024;
+pub use libc::FD_SETSIZE;
-#[cfg(any(target_os = "macos", target_os = "ios"))]
+// FIXME: Change to repr(transparent) once it's stable
#[repr(C)]
-#[derive(Clone)]
-pub struct FdSet {
- bits: [i32; FD_SETSIZE as usize / 32]
-}
-
-#[cfg(any(target_os = "macos", target_os = "ios"))]
-const BITS: usize = 32;
-
-#[cfg(not(any(target_os = "macos", target_os = "ios")))]
-#[repr(C)]
-#[derive(Clone)]
-pub struct FdSet {
- bits: [u64; FD_SETSIZE as usize / 64]
-}
-
-#[cfg(not(any(target_os = "macos", target_os = "ios")))]
-const BITS: usize = 64;
+pub struct FdSet(libc::fd_set);
impl FdSet {
pub fn new() -> FdSet {
- FdSet {
- bits: [0; FD_SETSIZE as usize / BITS]
- }
+ let mut fdset = unsafe { mem::uninitialized() };
+ unsafe { libc::FD_ZERO(&mut fdset) };
+ FdSet(fdset)
}
pub fn insert(&mut self, fd: RawFd) {
- let fd = fd as usize;
- self.bits[fd / BITS] |= 1 << (fd % BITS);
+ unsafe { libc::FD_SET(fd, &mut self.0) };
}
pub fn remove(&mut self, fd: RawFd) {
- let fd = fd as usize;
- self.bits[fd / BITS] &= !(1 << (fd % BITS));
+ unsafe { libc::FD_CLR(fd, &mut self.0) };
}
- pub fn contains(&self, fd: RawFd) -> bool {
- let fd = fd as usize;
- self.bits[fd / BITS] & (1 << (fd % BITS)) > 0
+ pub fn contains(&mut self, fd: RawFd) -> bool {
+ unsafe { libc::FD_ISSET(fd, &mut self.0) }
}
pub fn clear(&mut self) {
- for bits in &mut self.bits {
- *bits = 0
- }
+ unsafe { libc::FD_ZERO(&mut self.0) };
}
/// Finds the highest file descriptor in the set.
@@ -74,16 +54,11 @@ impl FdSet {
/// ```
///
/// [`select`]: fn.select.html
- pub fn highest(&self) -> Option<RawFd> {
- for (i, &block) in self.bits.iter().enumerate().rev() {
- if block != 0 {
- // Highest bit is located at `BITS - 1 - n.leading_zeros()`. Examples:
- // 0b00000001
- // 7 leading zeros, result should be 0 (bit at index 0 is 1)
- // 0b001xxxxx
- // 2 leading zeros, result should be 5 (bit at index 5 is 1) - x may be 0 or 1
-
- return Some((i * BITS + BITS - 1 - block.leading_zeros() as usize) as RawFd);
+ pub fn highest(&mut self) -> Option<RawFd> {
+ for i in (0..libc::FD_SETSIZE).rev() {
+ let i = i as RawFd;
+ if unsafe { libc::FD_ISSET(i, self as *mut _ as *mut libc::fd_set) } {
+ return Some(i)
}
}
@@ -91,19 +66,6 @@ impl FdSet {
}
}
-mod ffi {
- use libc::{c_int, timeval};
- use super::FdSet;
-
- extern {
- pub fn select(nfds: c_int,
- readfds: *mut FdSet,
- writefds: *mut FdSet,
- errorfds: *mut FdSet,
- timeout: *mut timeval) -> c_int;
- }
-}
-
/// Monitors file descriptors for readiness (see [select(2)]).
///
/// Returns the total number of ready file descriptors in all sets. The sets are changed so that all
@@ -136,28 +98,28 @@ where
E: Into<Option<&'a mut FdSet>>,
T: Into<Option<&'a mut TimeVal>>,
{
- let readfds = readfds.into();
- let writefds = writefds.into();
- let errorfds = errorfds.into();
+ let mut readfds = readfds.into();
+ let mut writefds = writefds.into();
+ let mut errorfds = errorfds.into();
let timeout = timeout.into();
let nfds = nfds.into().unwrap_or_else(|| {
- readfds.iter()
- .chain(writefds.iter())
- .chain(errorfds.iter())
+ readfds.iter_mut()
+ .chain(writefds.iter_mut())
+ .chain(errorfds.iter_mut())
.map(|set| set.highest().unwrap_or(-1))
.max()
.unwrap_or(-1) + 1
});
- let readfds = readfds.map(|set| set as *mut FdSet).unwrap_or(null_mut());
- let writefds = writefds.map(|set| set as *mut FdSet).unwrap_or(null_mut());
- let errorfds = errorfds.map(|set| set as *mut FdSet).unwrap_or(null_mut());
- let timeout = timeout.map(|tv| tv as *mut TimeVal as *mut timeval)
+ let readfds = readfds.map(|set| set as *mut _ as *mut libc::fd_set).unwrap_or(null_mut());
+ let writefds = writefds.map(|set| set as *mut _ as *mut libc::fd_set).unwrap_or(null_mut());
+ let errorfds = errorfds.map(|set| set as *mut _ as *mut libc::fd_set).unwrap_or(null_mut());
+ let timeout = timeout.map(|tv| tv as *mut _ as *mut libc::timeval)
.unwrap_or(null_mut());
let res = unsafe {
- ffi::select(nfds, readfds, writefds, errorfds, timeout)
+ libc::select(nfds, readfds, writefds, errorfds, timeout)
};
Errno::result(res)
@@ -166,6 +128,7 @@ where
#[cfg(test)]
mod tests {
use super::*;
+ use std::os::unix::io::RawFd;
use sys::time::{TimeVal, TimeValLike};
use unistd::{write, pipe};
@@ -174,7 +137,7 @@ mod tests {
let mut fd_set = FdSet::new();
for i in 0..FD_SETSIZE {
- assert!(!fd_set.contains(i));
+ assert!(!fd_set.contains(i as RawFd));
}
fd_set.insert(7);
@@ -187,14 +150,14 @@ mod tests {
let mut fd_set = FdSet::new();
for i in 0..FD_SETSIZE {
- assert!(!fd_set.contains(i));
+ assert!(!fd_set.contains(i as RawFd));
}
fd_set.insert(7);
fd_set.remove(7);
for i in 0..FD_SETSIZE {
- assert!(!fd_set.contains(i));
+ assert!(!fd_set.contains(i as RawFd));
}
}
@@ -202,13 +165,13 @@ mod tests {
fn fdset_clear() {
let mut fd_set = FdSet::new();
fd_set.insert(1);
- fd_set.insert(FD_SETSIZE / 2);
- fd_set.insert(FD_SETSIZE - 1);
+ fd_set.insert((FD_SETSIZE / 2) as RawFd);
+ fd_set.insert((FD_SETSIZE - 1) as RawFd);
fd_set.clear();
for i in 0..FD_SETSIZE {
- assert!(!fd_set.contains(i));
+ assert!(!fd_set.contains(i as RawFd));
}
}
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index a5ec9e3c..c53b5f5c 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -201,14 +201,14 @@ pub const SIGUNUSED : Signal = SIGSYS;
#[cfg(not(target_os = "android"))]
libc_bitflags!{
- pub flags SaFlags: libc::c_int {
- SA_NOCLDSTOP,
- SA_NOCLDWAIT,
- SA_NODEFER,
- SA_ONSTACK,
- SA_RESETHAND,
- SA_RESTART,
- SA_SIGINFO,
+ pub struct SaFlags: libc::c_int {
+ SA_NOCLDSTOP;
+ SA_NOCLDWAIT;
+ SA_NODEFER;
+ SA_ONSTACK;
+ SA_RESETHAND;
+ SA_RESTART;
+ SA_SIGINFO;
}
}
@@ -217,27 +217,27 @@ libc_bitflags!{
// FIXME: https://github.com/rust-lang/libc/pull/511
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
libc_bitflags!{
- pub flags SaFlags: libc::c_ulong {
- SA_NOCLDSTOP as libc::c_ulong,
- SA_NOCLDWAIT as libc::c_ulong,
- SA_NODEFER as libc::c_ulong,
- SA_ONSTACK as libc::c_ulong,
- SA_RESETHAND as libc::c_ulong,
- SA_RESTART as libc::c_ulong,
- SA_SIGINFO as libc::c_ulong,
+ pub struct SaFlags: libc::c_ulong {
+ SA_NOCLDSTOP as libc::c_ulong;
+ SA_NOCLDWAIT as libc::c_ulong;
+ SA_NODEFER as libc::c_ulong;
+ SA_ONSTACK as libc::c_ulong;
+ SA_RESETHAND as libc::c_ulong;
+ SA_RESTART as libc::c_ulong;
+ SA_SIGINFO as libc::c_ulong;
}
}
#[cfg(all(target_os = "android", target_pointer_width = "64"))]
libc_bitflags!{
- pub flags SaFlags: libc::c_uint {
- SA_NOCLDSTOP as libc::c_uint,
- SA_NOCLDWAIT as libc::c_uint,
- SA_NODEFER as libc::c_uint,
- SA_ONSTACK as libc::c_uint,
- SA_RESETHAND as libc::c_uint,
- SA_RESTART as libc::c_uint,
- SA_SIGINFO as libc::c_uint,
+ pub struct SaFlags: libc::c_uint {
+ SA_NOCLDSTOP as libc::c_uint;
+ SA_NOCLDWAIT as libc::c_uint;
+ SA_NODEFER as libc::c_uint;
+ SA_ONSTACK as libc::c_uint;
+ SA_RESETHAND as libc::c_uint;
+ SA_RESTART as libc::c_uint;
+ SA_SIGINFO as libc::c_uint;
}
}
diff --git a/src/sys/signalfd.rs b/src/sys/signalfd.rs
index fcf2efa9..abc96b8c 100644
--- a/src/sys/signalfd.rs
+++ b/src/sys/signalfd.rs
@@ -26,9 +26,9 @@ use std::mem;
libc_bitflags!{
- pub flags SfdFlags: libc::c_int {
- SFD_NONBLOCK,
- SFD_CLOEXEC,
+ pub struct SfdFlags: libc::c_int {
+ SFD_NONBLOCK;
+ SFD_CLOEXEC;
}
}
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index e0f957d8..eccd5e2d 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -3,8 +3,6 @@
//! [Further reading](http://man7.org/linux/man-pages/man7/socket.7.html)
use {Error, Errno, Result};
use features;
-use fcntl::{fcntl, FD_CLOEXEC, O_NONBLOCK};
-use fcntl::FcntlArg::{F_SETFD, F_SETFL};
use libc::{self, c_void, c_int, socklen_t, size_t, pid_t, uid_t, gid_t};
use std::{mem, ptr, slice};
use std::os::unix::io::RawFd;
@@ -92,25 +90,46 @@ pub enum SockProtocol {
KextControl = libc::SYSPROTO_CONTROL,
}
-bitflags!(
- /// Extra flags - Supported by Linux 2.6.27, normalized on other platforms
+libc_bitflags!{
+ /// Additional socket options
pub struct SockFlag: c_int {
- const SOCK_NONBLOCK = 0o0004000;
- const SOCK_CLOEXEC = 0o2000000;
+ /// Set non-blocking mode on the new socket
+ #[cfg(any(target_os = "android",
+ target_os = "dragonfly",
+ target_os = "freebsd",
+ target_os = "linux",
+ target_os = "netbsd",
+ target_os = "openbsd"))]
+ SOCK_NONBLOCK;
+ /// Set close-on-exec on the new descriptor
+ #[cfg(any(target_os = "android",
+ target_os = "dragonfly",
+ target_os = "freebsd",
+ target_os = "linux",
+ target_os = "netbsd",
+ target_os = "openbsd"))]
+ SOCK_CLOEXEC;
+ /// Return `EPIPE` instead of raising `SIGPIPE`
+ #[cfg(target_os = "netbsd")]
+ SOCK_NOSIGPIPE;
+ /// For domains `AF_INET(6)`, only allow `connect(2)`, `sendto(2)`, or `sendmsg(2)`
+ /// to the DNS port (typically 53)
+ #[cfg(target_os = "openbsd")]
+ SOCK_DNS;
}
-);
+}
libc_bitflags!{
/// Flags for send/recv and their relatives
- pub flags MsgFlags: libc::c_int {
+ pub struct MsgFlags: libc::c_int {
/// Sends or requests out-of-band data on sockets that support this notion
/// (e.g., of type [`Stream`](enum.SockType.html)); the underlying protocol must also
/// support out-of-band data.
- MSG_OOB,
+ MSG_OOB;
/// Peeks at an incoming message. The data is treated as unread and the next
/// [`recv()`](fn.recv.html)
/// or similar function shall still return this data.
- MSG_PEEK,
+ MSG_PEEK;
/// Enables nonblocking operation; if the operation would block,
/// `EAGAIN` or `EWOULDBLOCK` is returned. This provides similar
/// behavior to setting the `O_NONBLOCK` flag
@@ -121,9 +140,9 @@ libc_bitflags!{
/// which will affect all threads in
/// the calling process and as well as other processes that hold
/// file descriptors referring to the same open file description.
- MSG_DONTWAIT,
+ MSG_DONTWAIT;
/// Receive flags: Control Data was discarded (buffer too small)
- MSG_CTRUNC,
+ MSG_CTRUNC;
/// For raw ([`Packet`](addr/enum.AddressFamily.html)), Internet datagram
/// (since Linux 2.4.27/2.6.8),
/// netlink (since Linux 2.6.22) and UNIX datagram (since Linux 3.4)
@@ -132,15 +151,15 @@ libc_bitflags!{
/// domain ([unix(7)](https://linux.die.net/man/7/unix)) sockets.
///
/// For use with Internet stream sockets, see [tcp(7)](https://linux.die.net/man/7/tcp).
- MSG_TRUNC,
+ MSG_TRUNC;
/// Terminates a record (when this notion is supported, as for
/// sockets of type [`SeqPacket`](enum.SockType.html)).
- MSG_EOR,
+ MSG_EOR;
/// This flag specifies that queued errors should be received from
/// the socket error queue. (For more details, see
/// [recvfrom(2)](https://linux.die.net/man/2/recvfrom))
#[cfg(any(target_os = "linux", target_os = "android"))]
- MSG_ERRQUEUE,
+ MSG_ERRQUEUE;
/// Set the `close-on-exec` flag for the file descriptor received via a UNIX domain
/// file descriptor using the `SCM_RIGHTS` operation (described in
/// [unix(7)](https://linux.die.net/man/7/unix)).
@@ -149,7 +168,7 @@ libc_bitflags!{
///
/// Only used in [`recvmsg`](fn.recvmsg.html) function.
#[cfg(any(target_os = "linux", target_os = "android"))]
- MSG_CMSG_CLOEXEC,
+ MSG_CMSG_CLOEXEC;
}
}
@@ -449,13 +468,24 @@ pub fn socket<T: Into<Option<SockProtocol>>>(domain: AddressFamily, ty: SockType
// TODO: Check the kernel version
let res = try!(Errno::result(unsafe { ffi::socket(domain as c_int, ty, protocol) }));
- if !feat_atomic {
- if flags.contains(SOCK_CLOEXEC) {
- try!(fcntl(res, F_SETFD(FD_CLOEXEC)));
- }
+ #[cfg(any(target_os = "android",
+ target_os = "dragonfly",
+ target_os = "freebsd",
+ target_os = "linux",
+ target_os = "netbsd",
+ target_os = "openbsd"))]
+ {
+ use fcntl::{fcntl, FD_CLOEXEC, O_NONBLOCK};
+ use fcntl::FcntlArg::{F_SETFD, F_SETFL};
- if flags.contains(SOCK_NONBLOCK) {
- try!(fcntl(res, F_SETFL(O_NONBLOCK)));
+ if !feat_atomic {
+ if flags.contains(SOCK_CLOEXEC) {
+ try!(fcntl(res, F_SETFD(FD_CLOEXEC)));
+ }
+
+ if flags.contains(SOCK_NONBLOCK) {
+ try!(fcntl(res, F_SETFL(O_NONBLOCK)));
+ }
}
}
@@ -483,15 +513,26 @@ pub fn socketpair<T: Into<Option<SockProtocol>>>(domain: AddressFamily, ty: Sock
};
try!(Errno::result(res));
- if !feat_atomic {
- if flags.contains(SOCK_CLOEXEC) {
- try!(fcntl(fds[0], F_SETFD(FD_CLOEXEC)));
- try!(fcntl(fds[1], F_SETFD(FD_CLOEXEC)));
- }
+ #[cfg(any(target_os = "android",
+ target_os = "dragonfly",
+ target_os = "freebsd",
+ target_os = "linux",
+ target_os = "netbsd",
+ target_os = "openbsd"))]
+ {
+ use fcntl::{fcntl, FD_CLOEXEC, O_NONBLOCK};
+ use fcntl::FcntlArg::{F_SETFD, F_SETFL};
- if flags.contains(SOCK_NONBLOCK) {
- try!(fcntl(fds[0], F_SETFL(O_NONBLOCK)));
- try!(fcntl(fds[1], F_SETFL(O_NONBLOCK)));
+ if !feat_atomic {
+ if flags.contains(SOCK_CLOEXEC) {
+ try!(fcntl(fds[0], F_SETFD(FD_CLOEXEC)));
+ try!(fcntl(fds[1], F_SETFD(FD_CLOEXEC)));
+ }
+
+ if flags.contains(SOCK_NONBLOCK) {
+ try!(fcntl(fds[0], F_SETFL(O_NONBLOCK)));
+ try!(fcntl(fds[1], F_SETFL(O_NONBLOCK)));
+ }
}
}
Ok((fds[0], fds[1]))
@@ -554,14 +595,37 @@ pub fn accept4(sockfd: RawFd, flags: SockFlag) -> Result<RawFd> {
fn accept4_polyfill(sockfd: RawFd, flags: SockFlag) -> Result<RawFd> {
let res = try!(Errno::result(unsafe { ffi::accept(sockfd, ptr::null_mut(), ptr::null_mut()) }));
- if flags.contains(SOCK_CLOEXEC) {
- try!(fcntl(res, F_SETFD(FD_CLOEXEC)));
+ #[cfg(any(target_os = "android",
+ target_os = "dragonfly",
+ target_os = "freebsd",
+ target_os = "linux",
+ target_os = "netbsd",
+ target_os = "openbsd"))]
+ {
+ use fcntl::{fcntl, FD_CLOEXEC, O_NONBLOCK};
+ use fcntl::FcntlArg::{F_SETFD, F_SETFL};
+
+ if flags.contains(SOCK_CLOEXEC) {
+ try!(fcntl(res, F_SETFD(FD_CLOEXEC)));
+ }
+
+ if flags.contains(SOCK_NONBLOCK) {
+ try!(fcntl(res, F_SETFL(O_NONBLOCK)));
+ }
}
- if flags.contains(SOCK_NONBLOCK) {
- try!(fcntl(res, F_SETFL(O_NONBLOCK)));
+ // Disable unused variable warning on some platforms
+ #[cfg(not(any(target_os = "android",
+ target_os = "dragonfly",
+ target_os = "freebsd",
+ target_os = "linux",
+ target_os = "netbsd",
+ target_os = "openbsd")))]
+ {
+ let _ = flags;
}
+
Ok(res)
}
diff --git a/src/sys/stat.rs b/src/sys/stat.rs
index b089d3b5..7a0b3970 100644
--- a/src/sys/stat.rs
+++ b/src/sys/stat.rs
@@ -8,38 +8,35 @@ use std::mem;
use std::os::unix::io::RawFd;
libc_bitflags!(
- pub flags SFlag: mode_t {
- S_IFIFO,
- S_IFCHR,
- S_IFDIR,
- S_IFBLK,
- S_IFREG,
- S_IFLNK,
- S_IFSOCK,
- S_IFMT,
+ pub struct SFlag: mode_t {
+ S_IFIFO;
+ S_IFCHR;
+ S_IFDIR;
+ S_IFBLK;
+ S_IFREG;
+ S_IFLNK;
+ S_IFSOCK;
+ S_IFMT;
}
);
-bitflags! {
+libc_bitflags! {
pub struct Mode: mode_t {
- const S_IRWXU = libc::S_IRWXU;
- const S_IRUSR = libc::S_IRUSR;
- const S_IWUSR = libc::S_IWUSR;
- const S_IXUSR = libc::S_IXUSR;
-
- const S_IRWXG = libc::S_IRWXG;
- const S_IRGRP = libc::S_IRGRP;
- const S_IWGRP = libc::S_IWGRP;
- const S_IXGRP = libc::S_IXGRP;
-
- const S_IRWXO = libc::S_IRWXO;
- const S_IROTH = libc::S_IROTH;
- const S_IWOTH = libc::S_IWOTH;
- const S_IXOTH = libc::S_IXOTH;
-
- const S_ISUID = libc::S_ISUID as mode_t;
- const S_ISGID = libc::S_ISGID as mode_t;
- const S_ISVTX = libc::S_ISVTX as mode_t;
+ S_IRWXU;
+ S_IRUSR;
+ S_IWUSR;
+ S_IXUSR;
+ S_IRWXG;
+ S_IRGRP;
+ S_IWGRP;
+ S_IXGRP;
+ S_IRWXO;
+ S_IROTH;
+ S_IWOTH;
+ S_IXOTH;
+ S_ISUID as mode_t;
+ S_ISGID as mode_t;
+ S_ISVTX as mode_t;
}
}
diff --git a/src/sys/termios.rs b/src/sys/termios.rs
index 8651a84d..89f18ee1 100644
--- a/src/sys/termios.rs
+++ b/src/sys/termios.rs
@@ -456,163 +456,163 @@ pub use libc::_POSIX_VDISABLE;
libc_bitflags! {
/// Flags for configuring the input mode of a terminal
- pub flags InputFlags: tcflag_t {
- IGNBRK,
- BRKINT,
- IGNPAR,
- PARMRK,
- INPCK,
- ISTRIP,
- INLCR,
- IGNCR,
- ICRNL,
- IXON,
- IXOFF,
- IXANY,
- IMAXBEL,
+ pub struct InputFlags: tcflag_t {
+ IGNBRK;
+ BRKINT;
+ IGNPAR;
+ PARMRK;
+ INPCK;
+ ISTRIP;
+ INLCR;
+ IGNCR;
+ ICRNL;
+ IXON;
+ IXOFF;
+ IXANY;
+ IMAXBEL;
#[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))]
- IUTF8,
+ IUTF8;
}
}
libc_bitflags! {
/// Flags for configuring the output mode of a terminal
- pub flags OutputFlags: tcflag_t {
- OPOST,
+ pub struct OutputFlags: tcflag_t {
+ OPOST;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "linux",
target_os = "openbsd"))]
- OLCUC,
- ONLCR,
- OCRNL as tcflag_t,
- ONOCR as tcflag_t,
- ONLRET as tcflag_t,
+ OLCUC;
+ ONLCR;
+ OCRNL as tcflag_t;
+ ONOCR as tcflag_t;
+ ONLRET as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- OFILL as tcflag_t,
+ OFILL as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- OFDEL as tcflag_t,
+ OFDEL as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- NL0 as tcflag_t,
+ NL0 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- NL1 as tcflag_t,
+ NL1 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- CR0 as tcflag_t,
+ CR0 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- CR1 as tcflag_t,
+ CR1 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- CR2 as tcflag_t,
+ CR2 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- CR3 as tcflag_t,
+ CR3 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "freebsd",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- TAB0 as tcflag_t,
+ TAB0 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- TAB1 as tcflag_t,
+ TAB1 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- TAB2 as tcflag_t,
+ TAB2 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "freebsd",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- TAB3 as tcflag_t,
+ TAB3 as tcflag_t;
#[cfg(any(target_os = "android", target_os = "linux"))]
- XTABS,
+ XTABS;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- BS0 as tcflag_t,
+ BS0 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- BS1 as tcflag_t,
+ BS1 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- VT0 as tcflag_t,
+ VT0 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- VT1 as tcflag_t,
+ VT1 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- FF0 as tcflag_t,
+ FF0 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- FF1 as tcflag_t,
+ FF1 as tcflag_t;
#[cfg(any(target_os = "freebsd",
target_os = "dragonfly",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
- OXTABS,
+ OXTABS;
#[cfg(any(target_os = "freebsd",
target_os = "dragonfly",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
- ONOEOT as tcflag_t,
+ ONOEOT as tcflag_t;
// Bitmasks for use with OutputFlags to select specific settings
// These should be moved to be a mask once https://github.com/rust-lang-nursery/bitflags/issues/110
@@ -623,140 +623,140 @@ libc_bitflags! {
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- NLDLY as tcflag_t, // FIXME: Datatype needs to be corrected in libc for mac
+ NLDLY as tcflag_t; // FIXME: Datatype needs to be corrected in libc for mac
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- CRDLY as tcflag_t,
+ CRDLY as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "freebsd",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- TABDLY as tcflag_t,
+ TABDLY as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- BSDLY as tcflag_t,
+ BSDLY as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- VTDLY as tcflag_t,
+ VTDLY as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
- FFDLY as tcflag_t,
+ FFDLY as tcflag_t;
}
}
libc_bitflags! {
/// Flags for setting the control mode of a terminal
- pub flags ControlFlags: tcflag_t {
+ pub struct ControlFlags: tcflag_t {
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
- CIGNORE,
- CS5,
- CS6,
- CS7,
- CS8,
- CSTOPB,
- CREAD,
- PARENB,
- PARODD,
- HUPCL,
- CLOCAL,
- CRTSCTS,
+ CIGNORE;
+ CS5;
+ CS6;
+ CS7;
+ CS8;
+ CSTOPB;
+ CREAD;
+ PARENB;
+ PARODD;
+ HUPCL;
+ CLOCAL;
+ CRTSCTS;
#[cfg(any(target_os = "android", target_os = "linux"))]
- CBAUD,
+ CBAUD;
#[cfg(any(target_os = "android", all(target_os = "linux", not(target_arch = "mips"))))]
- CMSPAR,
+ CMSPAR;
#[cfg(any(target_os = "android",
all(target_os = "linux",
not(any(target_arch = "powerpc", target_arch = "powerpc64")))))]
- CIBAUD,
+ CIBAUD;
#[cfg(any(target_os = "android", target_os = "linux"))]
- CBAUDEX,
+ CBAUDEX;
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
- MDMBUF,
+ MDMBUF;
#[cfg(any(target_os = "netbsd", target_os = "openbsd"))]
- CHWFLOW,
+ CHWFLOW;
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"))]
- CCTS_OFLOW,
+ CCTS_OFLOW;
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"))]
- CRTS_IFLOW,
+ CRTS_IFLOW;
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd"))]
- CDTR_IFLOW,
+ CDTR_IFLOW;
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd"))]
- CDSR_OFLOW,
+ CDSR_OFLOW;
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd"))]
- CCAR_OFLOW,
+ CCAR_OFLOW;
// Bitmasks for use with ControlFlags to select specific settings
// These should be moved to be a mask once https://github.com/rust-lang-nursery/bitflags/issues/110
// is resolved.
- CSIZE,
+ CSIZE;
}
}
libc_bitflags! {
/// Flags for setting any local modes
- pub flags LocalFlags: tcflag_t {
- ECHOKE,
- ECHOE,
- ECHOK,
- ECHO,
- ECHONL,
- ECHOPRT,
- ECHOCTL,
- ISIG,
- ICANON,
+ pub struct LocalFlags: tcflag_t {
+ ECHOKE;
+ ECHOE;
+ ECHOK;
+ ECHO;
+ ECHONL;
+ ECHOPRT;
+ ECHOCTL;
+ ISIG;
+ ICANON;
#[cfg(any(target_os = "freebsd",
target_os = "dragonfly",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
- ALTWERASE,
- IEXTEN,
- EXTPROC,
- TOSTOP,
- FLUSHO,
+ ALTWERASE;
+ IEXTEN;
+ EXTPROC;
+ TOSTOP;
+ FLUSHO;
#[cfg(any(target_os = "freebsd",
target_os = "dragonfly",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
- NOKERNINFO,
- PENDIN,
- NOFLSH,
+ NOKERNINFO;
+ PENDIN;
+ NOFLSH;
}
}
diff --git a/src/sys/utsname.rs b/src/sys/utsname.rs
index 7eeb323b..104249d8 100644
--- a/src/sys/utsname.rs
+++ b/src/sys/utsname.rs
@@ -1,62 +1,41 @@
use std::mem;
-use libc::{c_char};
+use libc::{self, c_char};
use std::ffi::CStr;
-use std::str::from_utf8_unchecked;
-
-mod ffi {
- use libc::c_int;
- use super::UtsName;
-
- extern {
- pub fn uname(buf: *mut UtsName) -> c_int;
- }
-}
-
-
-const UTSNAME_LEN: usize = 65;
+use std::str::from_utf8_unchecked;
#[repr(C)]
#[derive(Copy)]
-pub struct UtsName {
- sysname: [c_char; UTSNAME_LEN],
- nodename: [c_char; UTSNAME_LEN],
- release: [c_char; UTSNAME_LEN],
- version: [c_char; UTSNAME_LEN],
- machine: [c_char; UTSNAME_LEN],
- // ifdef _GNU_SOURCE
- #[allow(dead_code)]
- domainname: [c_char; UTSNAME_LEN]
-}
+pub struct UtsName(libc::utsname);
// workaround for `derive(Clone)` not working for fixed-length arrays
impl Clone for UtsName { fn clone(&self) -> UtsName { *self } }
impl UtsName {
pub fn sysname<'a>(&'a self) -> &'a str {
- to_str(&(&self.sysname as *const c_char ) as *const *const c_char)
+ to_str(&(&self.0.sysname as *const c_char ) as *const *const c_char)
}
pub fn nodename<'a>(&'a self) -> &'a str {
- to_str(&(&self.nodename as *const c_char ) as *const *const c_char)
+ to_str(&(&self.0.nodename as *const c_char ) as *const *const c_char)
}
pub fn release<'a>(&'a self) -> &'a str {
- to_str(&(&self.release as *const c_char ) as *const *const c_char)
+ to_str(&(&self.0.release as *const c_char ) as *const *const c_char)
}
pub fn version<'a>(&'a self) -> &'a str {
- to_str(&(&self.version as *const c_char ) as *const *const c_char)
+ to_str(&(&self.0.version as *const c_char ) as *const *const c_char)
}
pub fn machine<'a>(&'a self) -> &'a str {
- to_str(&(&self.machine as *const c_char ) as *const *const c_char)
+ to_str(&(&self.0.machine as *const c_char ) as *const *const c_char)
}
}
pub fn uname() -> UtsName {
unsafe {
let mut ret: UtsName = mem::uninitialized();
- ffi::uname(&mut ret as *mut UtsName);
+ libc::uname(&mut ret.0);
ret
}
}
diff --git a/src/sys/wait.rs b/src/sys/wait.rs
index b2ca3bd6..2ad530ce 100644
--- a/src/sys/wait.rs
+++ b/src/sys/wait.rs
@@ -15,24 +15,24 @@ mod ffi {
#[cfg(not(any(target_os = "linux",
target_os = "android")))]
libc_bitflags!(
- pub flags WaitPidFlag: c_int {
- WNOHANG,
- WUNTRACED,
+ pub struct WaitPidFlag: c_int {
+ WNOHANG;
+ WUNTRACED;
}
);
#[cfg(any(target_os = "linux",
target_os = "android"))]
libc_bitflags!(
- pub flags WaitPidFlag: c_int {
- WNOHANG,
- WUNTRACED,
- WEXITED,
- WCONTINUED,
- WNOWAIT, // Don't reap, just poll status.
- __WNOTHREAD, // Don't wait on children of other threads in this group
- __WALL, // Wait on all children, regardless of type
- __WCLONE,
+ pub struct WaitPidFlag: c_int {
+ WNOHANG;
+ WUNTRACED;
+ WEXITED;
+ WCONTINUED;
+ WNOWAIT; // Don't reap, just poll status.
+ __WNOTHREAD; // Don't wait on children of other threads in this group
+ __WALL; // Wait on all children, regardless of type
+ __WCLONE;
}
);