summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXavier L'Heureux <xavier.lheureux@icloud.com>2019-07-16 15:02:54 -0400
committerXavier L'Heureux <dev.xlheureux@gmail.com>2020-05-17 21:05:45 -0400
commite94c139a47055d3492d6ccccfce4acbcba9d7391 (patch)
tree7419cc1c1461cda63e4e2a735fd75e4a48677f81 /src
parent0259f9d51718b90118bbd1d792c88781d0aa98f7 (diff)
downloadnix-e94c139a47055d3492d6ccccfce4acbcba9d7391.zip
Remove more unsupported functions and make it possible to run tests
Diffstat (limited to 'src')
-rw-r--r--src/dir.rs23
-rw-r--r--src/fcntl.rs163
-rw-r--r--src/sys/signal.rs22
-rw-r--r--src/sys/stat.rs1
-rw-r--r--src/unistd.rs4
5 files changed, 131 insertions, 82 deletions
diff --git a/src/dir.rs b/src/dir.rs
index 42731a4e..9648fd43 100644
--- a/src/dir.rs
+++ b/src/dir.rs
@@ -1,17 +1,25 @@
+#[cfg(not(target_os = "redox"))]
use {Error, NixPath, Result};
+#[cfg(not(target_os = "redox"))]
use errno::Errno;
+#[cfg(not(target_os = "redox"))]
use fcntl::{self, OFlag};
use libc;
-use std::os::unix::io::{IntoRawFd, RawFd};
#[cfg(not(target_os = "redox"))]
-use std::os::unix::io::AsRawFd;
-use std::{ffi, ptr};
+use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
+#[cfg(not(target_os = "redox"))]
+use std::ptr;
+use std::ffi;
+#[cfg(not(target_os = "redox"))]
use sys;
#[cfg(target_os = "linux")]
use libc::{dirent64 as dirent, readdir64_r as readdir_r};
-#[cfg(not(target_os = "linux"))]
+#[cfg(target_os = "redox")]
+use libc::dirent;
+
+#[cfg(not(any(target_os = "linux", target_os = "redox")))]
use libc::{dirent, readdir_r};
/// An open directory.
@@ -28,10 +36,12 @@ use libc::{dirent, readdir_r};
/// * returns entries' names as a `CStr` (no allocation or conversion beyond whatever libc
/// does).
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
+#[cfg(not(target_os = "redox"))]
pub struct Dir(
ptr::NonNull<libc::DIR>
);
+#[cfg(not(target_os = "redox"))]
impl Dir {
/// Opens the given path as with `fcntl::open`.
pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag,
@@ -77,6 +87,7 @@ impl Dir {
// call `readdir` simultaneously from multiple threads.
//
// `Dir` is safe to pass from one thread to another, as it's not reference-counted.
+#[cfg(not(target_os = "redox"))]
unsafe impl Send for Dir {}
#[cfg(not(target_os = "redox"))]
@@ -86,6 +97,7 @@ impl AsRawFd for Dir {
}
}
+#[cfg(not(target_os = "redox"))]
impl Drop for Dir {
fn drop(&mut self) {
unsafe { libc::closedir(self.0.as_ptr()) };
@@ -93,8 +105,10 @@ impl Drop for Dir {
}
#[derive(Debug, Eq, Hash, PartialEq)]
+#[cfg(not(target_os = "redox"))]
pub struct Iter<'d>(&'d mut Dir);
+#[cfg(not(target_os = "redox"))]
impl<'d> Iterator for Iter<'d> {
type Item = Result<Entry>;
@@ -121,6 +135,7 @@ impl<'d> Iterator for Iter<'d> {
}
}
+#[cfg(not(target_os = "redox"))]
impl<'d> Drop for Iter<'d> {
fn drop(&mut self) {
unsafe { libc::rewinddir((self.0).0.as_ptr()) }
diff --git a/src/fcntl.rs b/src/fcntl.rs
index 661b5ded..6b554c23 100644
--- a/src/fcntl.rs
+++ b/src/fcntl.rs
@@ -1,29 +1,31 @@
-use {Result, NixPath};
use errno::Errno;
-use libc::{self, c_int, c_uint, c_char, size_t, ssize_t};
-use sys::stat::Mode;
+use libc::{self, c_char, c_int, c_uint, size_t, ssize_t};
+use std::ffi::OsString;
#[cfg(not(target_os = "redox"))]
use std::os::raw;
-use std::os::unix::io::RawFd;
-use std::ffi::OsString;
use std::os::unix::ffi::OsStringExt;
+use std::os::unix::io::RawFd;
+use sys::stat::Mode;
+use {NixPath, Result};
#[cfg(any(target_os = "android", target_os = "linux"))]
use std::ptr; // For splice and copy_file_range
#[cfg(any(target_os = "android", target_os = "linux"))]
-use sys::uio::IoVec; // For vmsplice
-
-#[cfg(any(target_os = "linux",
- target_os = "android",
- target_os = "emscripten",
- target_os = "fuchsia",
- any(target_os = "wasi", target_env = "wasi"),
- target_env = "uclibc",
- target_env = "freebsd"))]
+use sys::uio::IoVec; // For vmsplice
+
+#[cfg(any(
+ target_os = "linux",
+ target_os = "android",
+ target_os = "emscripten",
+ target_os = "fuchsia",
+ any(target_os = "wasi", target_env = "wasi"),
+ target_env = "uclibc",
+ target_env = "freebsd"
+))]
pub use self::posix_fadvise::*;
#[cfg(not(target_os = "redox"))]
-libc_bitflags!{
+libc_bitflags! {
pub struct AtFlags: c_int {
AT_REMOVEDIR;
AT_SYMLINK_FOLLOW;
@@ -168,7 +170,13 @@ pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag, mode: Mode) -> Result<R
Errno::result(fd)
}
-pub fn openat<P: ?Sized + NixPath>(dirfd: RawFd, path: &P, oflag: OFlag, mode: Mode) -> Result<RawFd> {
+#[cfg(not(target_os = "redox"))]
+pub fn openat<P: ?Sized + NixPath>(
+ dirfd: RawFd,
+ path: &P,
+ oflag: OFlag,
+ mode: Mode,
+) -> Result<RawFd> {
let fd = path.with_nix_path(|cstr| {
let modebits = c_uint::from(mode.bits());
unsafe { libc::openat(dirfd, cstr.as_ptr(), oflag.bits(), modebits) }
@@ -176,13 +184,21 @@ pub fn openat<P: ?Sized + NixPath>(dirfd: RawFd, path: &P, oflag: OFlag, mode: M
Errno::result(fd)
}
-pub fn renameat<P1: ?Sized + NixPath, P2: ?Sized + NixPath>(old_dirfd: Option<RawFd>, old_path: &P1,
- new_dirfd: Option<RawFd>, new_path: &P2)
- -> Result<()> {
+#[cfg(not(target_os = "redox"))]
+pub fn renameat<P1: ?Sized + NixPath, P2: ?Sized + NixPath>(
+ old_dirfd: Option<RawFd>,
+ old_path: &P1,
+ new_dirfd: Option<RawFd>,
+ new_path: &P2,
+) -> Result<()> {
let res = old_path.with_nix_path(|old_cstr| {
new_path.with_nix_path(|new_cstr| unsafe {
- libc::renameat(at_rawfd(old_dirfd), old_cstr.as_ptr(),
- at_rawfd(new_dirfd), new_cstr.as_ptr())
+ libc::renameat(
+ at_rawfd(old_dirfd),
+ old_cstr.as_ptr(),
+ at_rawfd(new_dirfd),
+ new_cstr.as_ptr(),
+ )
})
})??;
Errno::result(res).map(drop)
@@ -194,25 +210,32 @@ fn wrap_readlink_result(mut v: Vec<u8>, len: ssize_t) -> Result<OsString> {
Ok(OsString::from_vec(v.to_vec()))
}
-fn readlink_maybe_at<P: ?Sized + NixPath>(dirfd: Option<RawFd>, path: &P,
- v: &mut Vec<u8>)
- -> Result<libc::ssize_t> {
- path.with_nix_path(|cstr| {
- unsafe {
- match dirfd {
- Some(dirfd) => libc::readlinkat(dirfd, cstr.as_ptr(),
- v.as_mut_ptr() as *mut c_char,
- v.capacity() as size_t),
- None => libc::readlink(cstr.as_ptr(),
- v.as_mut_ptr() as *mut c_char,
- v.capacity() as size_t),
- }
+fn readlink_maybe_at<P: ?Sized + NixPath>(
+ dirfd: Option<RawFd>,
+ path: &P,
+ v: &mut Vec<u8>,
+) -> Result<libc::ssize_t> {
+ path.with_nix_path(|cstr| unsafe {
+ match dirfd {
+ #[cfg(target_os = "redox")]
+ Some(_) => unreachable!(),
+ #[cfg(not(target_os = "redox"))]
+ Some(dirfd) => libc::readlinkat(
+ dirfd,
+ cstr.as_ptr(),
+ v.as_mut_ptr() as *mut c_char,
+ v.capacity() as size_t,
+ ),
+ None => libc::readlink(
+ cstr.as_ptr(),
+ v.as_mut_ptr() as *mut c_char,
+ v.capacity() as size_t,
+ ),
}
})
}
-fn inner_readlink<P: ?Sized + NixPath>(dirfd: Option<RawFd>, path: &P)
- -> Result<OsString> {
+fn inner_readlink<P: ?Sized + NixPath>(dirfd: Option<RawFd>, path: &P) -> Result<OsString> {
let mut v = Vec::with_capacity(libc::PATH_MAX as usize);
// simple case: result is strictly less than `PATH_MAX`
let res = readlink_maybe_at(dirfd, path, &mut v)?;
@@ -224,7 +247,8 @@ fn inner_readlink<P: ?Sized + NixPath>(dirfd: Option<RawFd>, path: &P)
// Uh oh, the result is too long...
// Let's try to ask lstat how many bytes to allocate.
let reported_size = super::sys::stat::lstat(path)
- .and_then(|x| Ok(x.st_size)).unwrap_or(0);
+ .and_then(|x| Ok(x.st_size))
+ .unwrap_or(0);
let mut try_size = if reported_size > 0 {
// Note: even if `lstat`'s apparently valid answer turns out to be
// wrong, we will still read the full symlink no matter what.
@@ -241,14 +265,13 @@ fn inner_readlink<P: ?Sized + NixPath>(dirfd: Option<RawFd>, path: &P)
debug_assert!(len >= 0);
if (len as usize) < v.capacity() {
break wrap_readlink_result(v, res);
- }
- else {
+ } else {
// Ugh! Still not big enough!
match try_size.checked_shl(1) {
Some(next_size) => try_size = next_size,
// It's absurd that this would happen, but handle it sanely
// anyway.
- None => break Err(super::Error::Sys(Errno::ENAMETOOLONG))
+ None => break Err(super::Error::Sys(Errno::ENAMETOOLONG)),
}
}
}
@@ -258,9 +281,8 @@ pub fn readlink<P: ?Sized + NixPath>(path: &P) -> Result<OsString> {
inner_readlink(None, path)
}
-
-pub fn readlinkat<P: ?Sized + NixPath>(dirfd: RawFd, path: &P)
- -> Result<OsString> {
+#[cfg(not(target_os = "redox"))]
+pub fn readlinkat<P: ?Sized + NixPath>(dirfd: RawFd, path: &P) -> Result<OsString> {
inner_readlink(Some(dirfd), path)
}
@@ -324,7 +346,6 @@ pub enum FcntlArg<'a> {
F_GETPIPE_SZ,
#[cfg(any(target_os = "linux", target_os = "android"))]
F_SETPIPE_SZ(c_int),
-
// TODO: Rest of flags
}
@@ -488,9 +509,7 @@ pub fn splice(
.map(|offset| offset as *mut libc::loff_t)
.unwrap_or(ptr::null_mut());
- let ret = unsafe {
- libc::splice(fd_in, off_in, fd_out, off_out, len, flags.bits())
- };
+ let ret = unsafe { libc::splice(fd_in, off_in, fd_out, off_out, len, flags.bits()) };
Errno::result(ret).map(|r| r as usize)
}
@@ -503,7 +522,12 @@ pub fn tee(fd_in: RawFd, fd_out: RawFd, len: usize, flags: SpliceFFlags) -> Resu
#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn vmsplice(fd: RawFd, iov: &[IoVec<&[u8]>], flags: SpliceFFlags) -> Result<usize> {
let ret = unsafe {
- libc::vmsplice(fd, iov.as_ptr() as *const libc::iovec, iov.len(), flags.bits())
+ libc::vmsplice(
+ fd,
+ iov.as_ptr() as *const libc::iovec,
+ iov.len(),
+ flags.bits(),
+ )
};
Errno::result(ret).map(|r| r as usize)
}
@@ -544,23 +568,30 @@ libc_bitflags!(
/// Allows the caller to directly manipulate the allocated disk space for the
/// file referred to by fd.
#[cfg(any(target_os = "linux"))]
-pub fn fallocate(fd: RawFd, mode: FallocateFlags, offset: libc::off_t, len: libc::off_t) -> Result<()> {
+pub fn fallocate(
+ fd: RawFd,
+ mode: FallocateFlags,
+ offset: libc::off_t,
+ len: libc::off_t,
+) -> Result<()> {
let res = unsafe { libc::fallocate(fd, mode.bits(), offset, len) };
Errno::result(res).map(drop)
}
-#[cfg(any(target_os = "linux",
- target_os = "android",
- target_os = "emscripten",
- target_os = "fuchsia",
- any(target_os = "wasi", target_env = "wasi"),
- target_env = "uclibc",
- target_env = "freebsd"))]
+#[cfg(any(
+ target_os = "linux",
+ target_os = "android",
+ target_os = "emscripten",
+ target_os = "fuchsia",
+ any(target_os = "wasi", target_env = "wasi"),
+ target_env = "uclibc",
+ target_env = "freebsd"
+))]
mod posix_fadvise {
- use Result;
- use libc;
use errno::Errno;
+ use libc;
use std::os::unix::io::RawFd;
+ use Result;
libc_enum! {
#[repr(i32)]
@@ -574,10 +605,12 @@ mod posix_fadvise {
}
}
- pub fn posix_fadvise(fd: RawFd,
- offset: libc::off_t,
- len: libc::off_t,
- advice: PosixFadviseAdvice) -> Result<libc::c_int> {
+ pub fn posix_fadvise(
+ fd: RawFd,
+ offset: libc::off_t,
+ len: libc::off_t,
+ advice: PosixFadviseAdvice,
+ ) -> Result<libc::c_int> {
let res = unsafe { libc::posix_fadvise(fd, offset, len, advice as libc::c_int) };
Errno::result(res)
}
@@ -591,11 +624,7 @@ mod posix_fadvise {
any(target_os = "wasi", target_env = "wasi"),
target_os = "freebsd"
))]
-pub fn posix_fallocate(
- fd: RawFd,
- offset: libc::off_t,
- len: libc::off_t
-) -> Result<()> {
+pub fn posix_fallocate(fd: RawFd, offset: libc::off_t, len: libc::off_t) -> Result<()> {
let res = unsafe { libc::posix_fallocate(fd, offset, len) };
match Errno::result(res) {
Err(err) => Err(err),
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index ad5cc031..b49a9f53 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -464,6 +464,7 @@ impl SigSet {
/// Suspends execution of the calling thread until one of the signals in the
/// signal mask becomes pending, and returns the accepted signal.
+ #[cfg(not(target_os = "redox"))]
pub fn wait(&self) -> Result<Signal> {
let mut signum = mem::MaybeUninit::uninit();
let res = unsafe { libc::sigwait(&self.sigset as *const libc::sigset_t, signum.as_mut_ptr()) };
@@ -890,6 +891,7 @@ mod sigevent {
#[cfg(test)]
mod tests {
+ #[cfg(not(target_os = "redox"))]
use std::thread;
use super::*;
@@ -945,6 +947,7 @@ mod tests {
}
#[test]
+ #[cfg(not(target_os = "redox"))]
fn test_thread_signal_set_mask() {
thread::spawn(|| {
let prev_mask = SigSet::thread_get_mask()
@@ -965,6 +968,7 @@ mod tests {
}
#[test]
+ #[cfg(not(target_os = "redox"))]
fn test_thread_signal_block() {
thread::spawn(|| {
let mut mask = SigSet::empty();
@@ -977,6 +981,7 @@ mod tests {
}
#[test]
+ #[cfg(not(target_os = "redox"))]
fn test_thread_signal_unblock() {
thread::spawn(|| {
let mut mask = SigSet::empty();
@@ -989,6 +994,7 @@ mod tests {
}
#[test]
+ #[cfg(not(target_os = "redox"))]
fn test_thread_signal_swap() {
thread::spawn(|| {
let mut mask = SigSet::empty();
@@ -1011,23 +1017,14 @@ mod tests {
}
#[test]
+ #[cfg(not(target_os = "redox"))]
fn test_sigaction() {
use libc;
thread::spawn(|| {
extern fn test_sigaction_handler(_: libc::c_int) {}
- #[cfg(not(target_os = "redox"))]
extern fn test_sigaction_action(_: libc::c_int,
_: *mut libc::siginfo_t, _: *mut libc::c_void) {}
- #[cfg(not(target_os = "redox"))]
- fn test_sigaction_sigaction(flags: SaFlags, mask: SigSet) {
- let handler_act = SigHandler::SigAction(test_sigaction_action);
- let action_act = SigAction::new(handler_act, flags, mask);
- assert_eq!(action_act.handler(), handler_act);
- }
- #[cfg(target_os = "redox")]
- fn test_sigaction_sigaction() {}
-
let handler_sig = SigHandler::Handler(test_sigaction_handler);
let flags = SaFlags::SA_ONSTACK | SaFlags::SA_RESTART |
@@ -1046,7 +1043,9 @@ mod tests {
assert!(mask.contains(SIGUSR1));
assert!(!mask.contains(SIGUSR2));
- test_sigaction_sigaction(flags, mask);
+ let handler_act = SigHandler::SigAction(test_sigaction_action);
+ let action_act = SigAction::new(handler_act, flags, mask);
+ assert_eq!(action_act.handler(), handler_act);
let action_dfl = SigAction::new(SigHandler::SigDfl, flags, mask);
assert_eq!(action_dfl.handler(), SigHandler::SigDfl);
@@ -1057,6 +1056,7 @@ mod tests {
}
#[test]
+ #[cfg(not(target_os = "redox"))]
fn test_sigwait() {
thread::spawn(|| {
let mut mask = SigSet::empty();
diff --git a/src/sys/stat.rs b/src/sys/stat.rs
index 5d426844..f8fae4ee 100644
--- a/src/sys/stat.rs
+++ b/src/sys/stat.rs
@@ -289,6 +289,7 @@ pub fn utimensat<P: ?Sized + NixPath>(
Errno::result(res).map(drop)
}
+#[cfg(not(target_os = "redox"))]
pub fn mkdirat<P: ?Sized + NixPath>(fd: RawFd, path: &P, mode: Mode) -> Result<()> {
let res = path.with_nix_path(|cstr| {
unsafe { libc::mkdirat(fd, cstr.as_ptr(), mode.bits() as mode_t) }
diff --git a/src/unistd.rs b/src/unistd.rs
index a663e7cd..7ee0a14e 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -291,6 +291,7 @@ pub fn setsid() -> Result<Pid> {
/// Obtain the process group ID of the process that is the session leader of the process specified
/// by pid. If pid is zero, it specifies the calling process.
#[inline]
+#[cfg(not(target_os = "redox"))]
pub fn getsid(pid: Option<Pid>) -> Result<Pid> {
let res = unsafe { libc::getsid(pid.unwrap_or(Pid(0)).into()) };
Errno::result(res).map(Pid)
@@ -1149,6 +1150,7 @@ fn pipe2_setflags(fd1: RawFd, fd2: RawFd, flags: OFlag) -> Result<()> {
///
/// See also
/// [truncate(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/truncate.html)
+#[cfg(not(target_os = "redox"))]
pub fn truncate<P: ?Sized + NixPath>(path: &P, len: off_t) -> Result<()> {
let res = path.with_nix_path(|cstr| {
unsafe {
@@ -1263,6 +1265,7 @@ pub enum UnlinkatFlags {
///
/// # References
/// See also [unlinkat(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/unlinkat.html)
+#[cfg(not(target_os = "redox"))]
pub fn unlinkat<P: ?Sized + NixPath>(
dirfd: Option<RawFd>,
path: &P,
@@ -1657,6 +1660,7 @@ pub fn initgroups(user: &CStr, group: Gid) -> Result<()> {
///
/// See also [pause(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pause.html).
#[inline]
+#[cfg(not(target_os = "redox"))]
pub fn pause() {
unsafe { libc::pause() };
}