]> git.lizzy.rs Git - rust.git/commitdiff
Switch to using syscall crate directly - without import
authorJeremy Soller <jackpot51@gmail.com>
Tue, 29 Nov 2016 01:07:19 +0000 (18:07 -0700)
committerJeremy Soller <jackpot51@gmail.com>
Tue, 29 Nov 2016 01:07:19 +0000 (18:07 -0700)
15 files changed:
src/libstd/sys/redox/condvar.rs
src/libstd/sys/redox/ext/fs.rs
src/libstd/sys/redox/ext/mod.rs
src/libstd/sys/redox/ext/process.rs
src/libstd/sys/redox/fd.rs
src/libstd/sys/redox/fs.rs
src/libstd/sys/redox/mod.rs
src/libstd/sys/redox/mutex.rs
src/libstd/sys/redox/net/mod.rs
src/libstd/sys/redox/os.rs
src/libstd/sys/redox/pipe.rs
src/libstd/sys/redox/process.rs
src/libstd/sys/redox/stdio.rs
src/libstd/sys/redox/thread.rs
src/libstd/sys/redox/time.rs

index f6c8fec545b97777ee36ef47366aeccdba619699..7e26162efbc8e54678e5e0500cfac154922739fe 100644 (file)
@@ -3,9 +3,8 @@
 use ptr;
 use time::Duration;
 
-use super::mutex::{mutex_lock, mutex_unlock, Mutex};
-
-use libc::{futex, FUTEX_WAIT, FUTEX_WAKE, FUTEX_REQUEUE};
+use sys::mutex::{mutex_lock, mutex_unlock, Mutex};
+use sys::syscall::{futex, FUTEX_WAIT, FUTEX_WAKE, FUTEX_REQUEUE};
 
 pub struct Condvar {
     lock: UnsafeCell<*mut i32>,
index 2914fafa94c88f4e678b89a4701d29ab4cc6fa63..d292b43872439d579ce09447c0a0fe0634da5eb9 100644 (file)
@@ -216,7 +216,6 @@ fn ctime_nsec(&self) -> i64 {
     }
 }
 
-/* TODO
 /// Add special unix types (block/char device, fifo and socket)
 #[stable(feature = "file_type_ext", since = "1.5.0")]
 pub trait FileTypeExt {
@@ -236,12 +235,11 @@ pub trait FileTypeExt {
 
 #[stable(feature = "file_type_ext", since = "1.5.0")]
 impl FileTypeExt for fs::FileType {
-    fn is_block_device(&self) -> bool { self.as_inner().is(libc::S_IFBLK) }
-    fn is_char_device(&self) -> bool { self.as_inner().is(libc::S_IFCHR) }
-    fn is_fifo(&self) -> bool { self.as_inner().is(libc::S_IFIFO) }
-    fn is_socket(&self) -> bool { self.as_inner().is(libc::S_IFSOCK) }
+    fn is_block_device(&self) -> bool { false /*TODO*/ }
+    fn is_char_device(&self) -> bool { false /*TODO*/ }
+    fn is_fifo(&self) -> bool { false /*TODO*/ }
+    fn is_socket(&self) -> bool { false /*TODO*/ }
 }
-*/
 
 /// Creates a new symbolic link on the filesystem.
 ///
index 7ba166e89320fecd1e4c0cac86c785e74e623e52..02edfa84aa090e18d431973e26ce9235d1d42abf 100644 (file)
@@ -44,7 +44,7 @@ pub mod prelude {
     #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")]
     pub use super::ffi::{OsStrExt, OsStringExt};
     #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")]
-    pub use super::fs::{PermissionsExt, OpenOptionsExt, MetadataExt};
+    pub use super::fs::{FileTypeExt, PermissionsExt, OpenOptionsExt, MetadataExt};
     #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")]
     pub use super::process::{CommandExt, ExitStatusExt};
 }
index f8e6b2cf4709d358d58bbfeab993d00d41410b46..3a7c59d4e6d09d32e1aefbb5331fc60f8589eee8 100644 (file)
@@ -86,12 +86,12 @@ fn before_exec<F>(&mut self, f: F) -> &mut process::Command
 #[stable(feature = "rust1", since = "1.0.0")]
 impl CommandExt for process::Command {
     fn uid(&mut self, id: u32) -> &mut process::Command {
-        self.as_inner_mut().uid(id as usize);
+        self.as_inner_mut().uid(id);
         self
     }
 
     fn gid(&mut self, id: u32) -> &mut process::Command {
-        self.as_inner_mut().gid(id as usize);
+        self.as_inner_mut().gid(id);
         self
     }
 
index b716965860e1dc914c69972a347dc2db012d6bbf..4c8e62d1863b6ed60d18bfb73c7b32c2e5a2e800 100644 (file)
@@ -11,9 +11,8 @@
 #![unstable(reason = "not public", issue = "0", feature = "fd")]
 
 use io::{self, Read};
-use libc;
 use mem;
-use sys::cvt;
+use sys::{cvt, syscall};
 use sys_common::AsInner;
 use sys_common::io::read_to_end_uninitialized;
 
@@ -36,7 +35,7 @@ pub fn into_raw(self) -> usize {
     }
 
     pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
-        cvt(libc::read(self.fd, buf))
+        cvt(syscall::read(self.fd, buf))
     }
 
     pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> {
@@ -45,33 +44,33 @@ pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> {
     }
 
     pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
-        cvt(libc::write(self.fd, buf))
+        cvt(syscall::write(self.fd, buf))
     }
 
     pub fn duplicate(&self) -> io::Result<FileDesc> {
-        let new_fd = cvt(libc::dup(self.fd, &[]))?;
+        let new_fd = cvt(syscall::dup(self.fd, &[]))?;
         Ok(FileDesc::new(new_fd))
     }
 
     pub fn nonblocking(&self) -> io::Result<bool> {
-        let flags = cvt(libc::fcntl(self.fd, libc::F_GETFL, 0))?;
-        Ok(flags & libc::O_NONBLOCK == libc::O_NONBLOCK)
+        let flags = cvt(syscall::fcntl(self.fd, syscall::F_GETFL, 0))?;
+        Ok(flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK)
     }
 
     pub fn set_cloexec(&self) -> io::Result<()> {
-        let mut flags = cvt(libc::fcntl(self.fd, libc::F_GETFL, 0))?;
-        flags |= libc::O_CLOEXEC;
-        cvt(libc::fcntl(self.fd, libc::F_SETFL, flags)).and(Ok(()))
+        let mut flags = cvt(syscall::fcntl(self.fd, syscall::F_GETFL, 0))?;
+        flags |= syscall::O_CLOEXEC;
+        cvt(syscall::fcntl(self.fd, syscall::F_SETFL, flags)).and(Ok(()))
     }
 
     pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
-        let mut flags = cvt(libc::fcntl(self.fd, libc::F_GETFL, 0))?;
+        let mut flags = cvt(syscall::fcntl(self.fd, syscall::F_GETFL, 0))?;
         if nonblocking {
-            flags |= libc::O_NONBLOCK;
+            flags |= syscall::O_NONBLOCK;
         } else {
-            flags &= !libc::O_NONBLOCK;
+            flags &= !syscall::O_NONBLOCK;
         }
-        cvt(libc::fcntl(self.fd, libc::F_SETFL, flags)).and(Ok(()))
+        cvt(syscall::fcntl(self.fd, syscall::F_SETFL, flags)).and(Ok(()))
     }
 }
 
@@ -96,6 +95,6 @@ fn drop(&mut self) {
         // the file descriptor was closed or not, and if we retried (for
         // something like EINTR), we might close another valid file descriptor
         // (opened after we closed ours.
-        let _ = libc::close(self.fd);
+        let _ = syscall::close(self.fd);
     }
 }
index 12aa17becd8609e159978daf6f09598a037f732e..80aec2e978dd01f01258998b5c74c4c77cebd6fc 100644 (file)
 use ffi::{OsString, OsStr};
 use fmt;
 use io::{self, Error, ErrorKind, SeekFrom};
-use libc::{self, c_int, mode_t};
 use path::{Path, PathBuf};
 use sync::Arc;
 use sys::fd::FileDesc;
 use sys::time::SystemTime;
-use sys::cvt;
+use sys::{cvt, syscall};
 use sys_common::{AsInner, FromInner};
 
-use libc::{stat, fstat, fsync, ftruncate, lseek, open};
-
 pub struct File(FileDesc);
 
 #[derive(Clone)]
 pub struct FileAttr {
-    stat: stat,
+    stat: syscall::Stat,
 }
 
 pub struct ReadDir {
@@ -57,53 +54,53 @@ pub struct OpenOptions {
     create_new: bool,
     // system-specific
     custom_flags: i32,
-    mode: mode_t,
+    mode: u16,
 }
 
 #[derive(Clone, PartialEq, Eq, Debug)]
-pub struct FilePermissions { mode: mode_t }
+pub struct FilePermissions { mode: u16 }
 
 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
-pub struct FileType { mode: mode_t }
+pub struct FileType { mode: u16 }
 
-pub struct DirBuilder { mode: mode_t }
+pub struct DirBuilder { mode: u16 }
 
 impl FileAttr {
     pub fn size(&self) -> u64 { self.stat.st_size as u64 }
     pub fn perm(&self) -> FilePermissions {
-        FilePermissions { mode: (self.stat.st_mode as mode_t) & 0o777 }
+        FilePermissions { mode: (self.stat.st_mode as u16) & 0o777 }
     }
 
     pub fn file_type(&self) -> FileType {
-        FileType { mode: self.stat.st_mode as mode_t }
+        FileType { mode: self.stat.st_mode as u16 }
     }
 }
 
 impl FileAttr {
     pub fn modified(&self) -> io::Result<SystemTime> {
-        Ok(SystemTime::from(libc::timespec {
-            tv_sec: self.stat.st_mtime as libc::time_t,
+        Ok(SystemTime::from(syscall::TimeSpec {
+            tv_sec: self.stat.st_mtime as i64,
             tv_nsec: self.stat.st_mtime_nsec as i32,
         }))
     }
 
     pub fn accessed(&self) -> io::Result<SystemTime> {
-        Ok(SystemTime::from(libc::timespec {
-            tv_sec: self.stat.st_atime as libc::time_t,
+        Ok(SystemTime::from(syscall::TimeSpec {
+            tv_sec: self.stat.st_atime as i64,
             tv_nsec: self.stat.st_atime_nsec as i32,
         }))
     }
 
     pub fn created(&self) -> io::Result<SystemTime> {
-        Ok(SystemTime::from(libc::timespec {
-            tv_sec: self.stat.st_ctime as libc::time_t,
+        Ok(SystemTime::from(syscall::TimeSpec {
+            tv_sec: self.stat.st_ctime as i64,
             tv_nsec: self.stat.st_ctime_nsec as i32,
         }))
     }
 }
 
-impl AsInner<stat> for FileAttr {
-    fn as_inner(&self) -> &stat { &self.stat }
+impl AsInner<syscall::Stat> for FileAttr {
+    fn as_inner(&self) -> &syscall::Stat { &self.stat }
 }
 
 impl FilePermissions {
@@ -119,16 +116,16 @@ pub fn mode(&self) -> u32 { self.mode as u32 }
 }
 
 impl FileType {
-    pub fn is_dir(&self) -> bool { self.is(libc::MODE_DIR) }
-    pub fn is_file(&self) -> bool { self.is(libc::MODE_FILE) }
+    pub fn is_dir(&self) -> bool { self.is(syscall::MODE_DIR) }
+    pub fn is_file(&self) -> bool { self.is(syscall::MODE_FILE) }
     pub fn is_symlink(&self) -> bool { false }
 
-    pub fn is(&self, mode: mode_t) -> bool { self.mode & (libc::MODE_DIR | libc::MODE_FILE) == mode }
+    pub fn is(&self, mode: u16) -> bool { self.mode & (syscall::MODE_DIR | syscall::MODE_FILE) == mode }
 }
 
 impl FromInner<u32> for FilePermissions {
     fn from_inner(mode: u32) -> FilePermissions {
-        FilePermissions { mode: mode as mode_t }
+        FilePermissions { mode: mode as u16 }
     }
 }
 
@@ -215,60 +212,60 @@ pub fn new() -> OpenOptions {
     pub fn create_new(&mut self, create_new: bool) { self.create_new = create_new; }
 
     pub fn custom_flags(&mut self, flags: i32) { self.custom_flags = flags; }
-    pub fn mode(&mut self, mode: u32) { self.mode = mode as mode_t; }
+    pub fn mode(&mut self, mode: u32) { self.mode = mode as u16; }
 
-    fn get_access_mode(&self) -> io::Result<c_int> {
+    fn get_access_mode(&self) -> io::Result<usize> {
         match (self.read, self.write, self.append) {
-            (true,  false, false) => Ok(libc::O_RDONLY as c_int),
-            (false, true,  false) => Ok(libc::O_WRONLY as c_int),
-            (true,  true,  false) => Ok(libc::O_RDWR as c_int),
-            (false, _,     true)  => Ok(libc::O_WRONLY as c_int | libc::O_APPEND as c_int),
-            (true,  _,     true)  => Ok(libc::O_RDWR as c_int | libc::O_APPEND as c_int),
-            (false, false, false) => Err(Error::from_raw_os_error(libc::EINVAL)),
+            (true,  false, false) => Ok(syscall::O_RDONLY),
+            (false, true,  false) => Ok(syscall::O_WRONLY),
+            (true,  true,  false) => Ok(syscall::O_RDWR),
+            (false, _,     true)  => Ok(syscall::O_WRONLY | syscall::O_APPEND),
+            (true,  _,     true)  => Ok(syscall::O_RDWR | syscall::O_APPEND),
+            (false, false, false) => Err(Error::from_raw_os_error(syscall::EINVAL)),
         }
     }
 
-    fn get_creation_mode(&self) -> io::Result<c_int> {
+    fn get_creation_mode(&self) -> io::Result<usize> {
         match (self.write, self.append) {
             (true, false) => {}
             (false, false) =>
                 if self.truncate || self.create || self.create_new {
-                    return Err(Error::from_raw_os_error(libc::EINVAL));
+                    return Err(Error::from_raw_os_error(syscall::EINVAL));
                 },
             (_, true) =>
                 if self.truncate && !self.create_new {
-                    return Err(Error::from_raw_os_error(libc::EINVAL));
+                    return Err(Error::from_raw_os_error(syscall::EINVAL));
                 },
         }
 
         Ok(match (self.create, self.truncate, self.create_new) {
                 (false, false, false) => 0,
-                (true,  false, false) => libc::O_CREAT as c_int,
-                (false, true,  false) => libc::O_TRUNC as c_int,
-                (true,  true,  false) => libc::O_CREAT as c_int | libc::O_TRUNC as c_int,
-                (_,      _,    true)  => libc::O_CREAT as c_int | libc::O_EXCL as c_int,
+                (true,  false, false) => syscall::O_CREAT,
+                (false, true,  false) => syscall::O_TRUNC,
+                (true,  true,  false) => syscall::O_CREAT | syscall::O_TRUNC,
+                (_,      _,    true)  => syscall::O_CREAT | syscall::O_EXCL,
            })
     }
 }
 
 impl File {
     pub fn open(path: &Path, opts: &OpenOptions) -> io::Result<File> {
-        let flags = libc::O_CLOEXEC |
+        let flags = syscall::O_CLOEXEC |
                     opts.get_access_mode()? as usize |
                     opts.get_creation_mode()? as usize |
-                    (opts.custom_flags as usize & !libc::O_ACCMODE);
-        let fd = cvt(open(path.to_str().unwrap(), flags | opts.mode as usize))?;
+                    (opts.custom_flags as usize & !syscall::O_ACCMODE);
+        let fd = cvt(syscall::open(path.to_str().unwrap(), flags | opts.mode as usize))?;
         Ok(File(FileDesc::new(fd)))
     }
 
     pub fn file_attr(&self) -> io::Result<FileAttr> {
-        let mut stat: stat = stat::default();
-        cvt(fstat(self.0.raw(), &mut stat))?;
+        let mut stat = syscall::Stat::default();
+        cvt(syscall::fstat(self.0.raw(), &mut stat))?;
         Ok(FileAttr { stat: stat })
     }
 
     pub fn fsync(&self) -> io::Result<()> {
-        cvt(fsync(self.0.raw()))?;
+        cvt(syscall::fsync(self.0.raw()))?;
         Ok(())
     }
 
@@ -277,7 +274,7 @@ pub fn datasync(&self) -> io::Result<()> {
     }
 
     pub fn truncate(&self, size: u64) -> io::Result<()> {
-        cvt(ftruncate(self.0.raw(), size as usize))?;
+        cvt(syscall::ftruncate(self.0.raw(), size as usize))?;
         Ok(())
     }
 
@@ -299,11 +296,11 @@ pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> {
         let (whence, pos) = match pos {
             // Casting to `i64` is fine, too large values will end up as
             // negative which will cause an error in `lseek64`.
-            SeekFrom::Start(off) => (libc::SEEK_SET, off as i64),
-            SeekFrom::End(off) => (libc::SEEK_END, off),
-            SeekFrom::Current(off) => (libc::SEEK_CUR, off),
+            SeekFrom::Start(off) => (syscall::SEEK_SET, off as i64),
+            SeekFrom::End(off) => (syscall::SEEK_END, off),
+            SeekFrom::Current(off) => (syscall::SEEK_CUR, off),
         };
-        let n = cvt(lseek(self.0.raw(), pos as isize, whence))?;
+        let n = cvt(syscall::lseek(self.0.raw(), pos as isize, whence))?;
         Ok(n as u64)
     }
 
@@ -312,7 +309,7 @@ pub fn duplicate(&self) -> io::Result<File> {
     }
 
     pub fn dup(&self, buf: &[u8]) -> io::Result<File> {
-        let fd = cvt(libc::dup(*self.fd().as_inner() as usize, buf))?;
+        let fd = cvt(syscall::dup(*self.fd().as_inner() as usize, buf))?;
         Ok(File(FileDesc::new(fd)))
     }
 
@@ -322,7 +319,7 @@ pub fn set_permissions(&self, perm: FilePermissions) -> io::Result<()> {
 
     pub fn path(&self) -> io::Result<PathBuf> {
         let mut buf: [u8; 4096] = [0; 4096];
-        match libc::fpath(*self.fd().as_inner() as usize, &mut buf) {
+        match syscall::fpath(*self.fd().as_inner() as usize, &mut buf) {
             Ok(count) => Ok(PathBuf::from(unsafe { String::from_utf8_unchecked(Vec::from(&buf[0..count])) })),
             Err(err) => Err(Error::from_raw_os_error(err.errno)),
         }
@@ -339,13 +336,13 @@ pub fn new() -> DirBuilder {
     }
 
     pub fn mkdir(&self, p: &Path) -> io::Result<()> {
-        let fd = cvt(libc::open(p.to_str().unwrap(), libc::O_CREAT | libc::O_DIRECTORY | libc::O_EXCL | (self.mode as usize & 0o777)))?;
-        let _ = libc::close(fd);
+        let fd = cvt(syscall::open(p.to_str().unwrap(), syscall::O_CREAT | syscall::O_DIRECTORY | syscall::O_EXCL | (self.mode as usize & 0o777)))?;
+        let _ = syscall::close(fd);
         Ok(())
     }
 
     pub fn set_mode(&mut self, mode: u32) {
-        self.mode = mode as mode_t;
+        self.mode = mode as u16;
     }
 }
 
@@ -374,7 +371,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 pub fn readdir(p: &Path) -> io::Result<ReadDir> {
     let root = Arc::new(p.to_path_buf());
 
-    let fd = cvt(open(p.to_str().unwrap(), libc::O_CLOEXEC | libc::O_RDONLY | libc::O_DIRECTORY))?;
+    let fd = cvt(syscall::open(p.to_str().unwrap(), syscall::O_CLOEXEC | syscall::O_RDONLY | syscall::O_DIRECTORY))?;
     let file = FileDesc::new(fd);
     let mut data = Vec::new();
     file.read_to_end(&mut data)?;
@@ -383,7 +380,7 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> {
 }
 
 pub fn unlink(p: &Path) -> io::Result<()> {
-    cvt(libc::unlink(p.to_str().unwrap()))?;
+    cvt(syscall::unlink(p.to_str().unwrap()))?;
     Ok(())
 }
 
@@ -393,12 +390,12 @@ pub fn rename(_old: &Path, _new: &Path) -> io::Result<()> {
 }
 
 pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> {
-    cvt(libc::chmod(p.to_str().unwrap(), perm.mode as usize))?;
+    cvt(syscall::chmod(p.to_str().unwrap(), perm.mode as usize))?;
     Ok(())
 }
 
 pub fn rmdir(p: &Path) -> io::Result<()> {
-    cvt(libc::rmdir(p.to_str().unwrap()))?;
+    cvt(syscall::rmdir(p.to_str().unwrap()))?;
     Ok(())
 }
 
@@ -438,13 +435,9 @@ pub fn link(_src: &Path, _dst: &Path) -> io::Result<()> {
 }
 
 pub fn stat(p: &Path) -> io::Result<FileAttr> {
-    let mut stat: stat = stat::default();
-
-    let fd = cvt(open(p.to_str().unwrap(), libc::O_CLOEXEC | libc::O_STAT))?;
-    cvt(fstat(fd, &mut stat))?;
-    let _ = libc::close(fd);
-
-    Ok(FileAttr { stat: stat })
+    let fd = cvt(syscall::open(p.to_str().unwrap(), syscall::O_CLOEXEC | syscall::O_STAT))?;
+    let file = File(FileDesc::new(fd));
+    file.file_attr()
 }
 
 pub fn lstat(p: &Path) -> io::Result<FileAttr> {
@@ -452,7 +445,7 @@ pub fn lstat(p: &Path) -> io::Result<FileAttr> {
 }
 
 pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {
-    let fd = cvt(open(p.to_str().unwrap(), libc::O_CLOEXEC | libc::O_STAT))?;
+    let fd = cvt(syscall::open(p.to_str().unwrap(), syscall::O_CLOEXEC | syscall::O_STAT))?;
     let file = File(FileDesc::new(fd));
     file.path()
 }
index 3f3d8f2c4f41b101499e2ff860970d9342e76b28..07ead22b7a892e44735ab563c228a15e71ede458 100644 (file)
@@ -1,7 +1,8 @@
 #![allow(dead_code, missing_docs, bad_style)]
 
+pub extern crate syscall;
+
 use io::{self, ErrorKind};
-use libc;
 
 pub mod args;
 pub mod backtrace;
@@ -42,40 +43,40 @@ fn oom_handler() -> ! {
         use intrinsics;
         let msg = "fatal runtime error: out of memory\n";
         unsafe {
-            let _ = libc::write(libc::STDERR_FILENO, msg.as_bytes());
+            let _ = syscall::write(2, msg.as_bytes());
             intrinsics::abort();
         }
     }
 }
 
 pub fn decode_error_kind(errno: i32) -> ErrorKind {
-    match errno as libc::c_int {
-        libc::ECONNREFUSED => ErrorKind::ConnectionRefused,
-        libc::ECONNRESET => ErrorKind::ConnectionReset,
-        libc::EPERM | libc::EACCES => ErrorKind::PermissionDenied,
-        libc::EPIPE => ErrorKind::BrokenPipe,
-        libc::ENOTCONN => ErrorKind::NotConnected,
-        libc::ECONNABORTED => ErrorKind::ConnectionAborted,
-        libc::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
-        libc::EADDRINUSE => ErrorKind::AddrInUse,
-        libc::ENOENT => ErrorKind::NotFound,
-        libc::EINTR => ErrorKind::Interrupted,
-        libc::EINVAL => ErrorKind::InvalidInput,
-        libc::ETIMEDOUT => ErrorKind::TimedOut,
-        libc::EEXIST => ErrorKind::AlreadyExists,
+    match errno {
+        syscall::ECONNREFUSED => ErrorKind::ConnectionRefused,
+        syscall::ECONNRESET => ErrorKind::ConnectionReset,
+        syscall::EPERM | syscall::EACCES => ErrorKind::PermissionDenied,
+        syscall::EPIPE => ErrorKind::BrokenPipe,
+        syscall::ENOTCONN => ErrorKind::NotConnected,
+        syscall::ECONNABORTED => ErrorKind::ConnectionAborted,
+        syscall::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
+        syscall::EADDRINUSE => ErrorKind::AddrInUse,
+        syscall::ENOENT => ErrorKind::NotFound,
+        syscall::EINTR => ErrorKind::Interrupted,
+        syscall::EINVAL => ErrorKind::InvalidInput,
+        syscall::ETIMEDOUT => ErrorKind::TimedOut,
+        syscall::EEXIST => ErrorKind::AlreadyExists,
 
         // These two constants can have the same value on some systems,
         // but different values on others, so we can't use a match
         // clause
-        x if x == libc::EAGAIN || x == libc::EWOULDBLOCK =>
+        x if x == syscall::EAGAIN || x == syscall::EWOULDBLOCK =>
             ErrorKind::WouldBlock,
 
         _ => ErrorKind::Other,
     }
 }
 
-pub fn cvt(result: Result<usize, libc::Error>) -> io::Result<usize> {
-    result.map_err(|err| io::Error::from_raw_os_error(err.errno as i32))
+pub fn cvt(result: Result<usize, syscall::Error>) -> io::Result<usize> {
+    result.map_err(|err| io::Error::from_raw_os_error(err.errno))
 }
 
 /// On Redox, use an illegal instruction to abort
index 4c2b0de8bd94ba45a6ee5be5a75e690745726d1d..42424da858fbc844b2ba41bbd6ed81597616068e 100644 (file)
@@ -2,7 +2,7 @@
 use intrinsics::{atomic_cxchg, atomic_xchg};
 use ptr;
 
-use libc::{futex, getpid, FUTEX_WAIT, FUTEX_WAKE};
+use sys::syscall::{futex, getpid, FUTEX_WAIT, FUTEX_WAKE};
 
 pub unsafe fn mutex_try_lock(m: *mut i32) -> bool {
     atomic_cxchg(m, 0, 1).0 == 0
index 1c8fde546efb444705f4c368c15141e5271a48dd..92c7d72887bf07a177b4d4eebb27409ba239fc9d 100644 (file)
@@ -4,7 +4,7 @@
 use net::{Ipv4Addr, SocketAddr, SocketAddrV4};
 use str::FromStr;
 use string::{String, ToString};
-use libc::EINVAL;
+use sys::syscall::EINVAL;
 use time;
 use vec::{IntoIter, Vec};
 
index e007e33258f617f5e43b11848932100e5828eaa6..9ebbae4199b78d9bf75e5fc672e343faa5a68d69 100644 (file)
@@ -19,7 +19,6 @@
 use fmt;
 use io::{self, Read, Write};
 use iter;
-use libc::{self, c_int, c_char, c_void};
 use marker::PhantomData;
 use mem;
 use memchr;
@@ -28,8 +27,7 @@
 use slice;
 use str;
 use sys_common::mutex::Mutex;
-use sys::cvt;
-use sys::fd;
+use sys::{cvt, fd, syscall};
 use vec;
 
 const TMPBUF_SZ: usize = 128;
@@ -42,7 +40,7 @@ pub fn errno() -> i32 {
 
 /// Gets a detailed string description for the given error number.
 pub fn error_string(errno: i32) -> String {
-    if let Some(string) = libc::STR_ERROR.get(errno as usize) {
+    if let Some(string) = syscall::STR_ERROR.get(errno as usize) {
         string.to_string()
     } else {
         "unknown error".to_string()
@@ -51,12 +49,12 @@ pub fn error_string(errno: i32) -> String {
 
 pub fn getcwd() -> io::Result<PathBuf> {
     let mut buf = [0; 4096];
-    let count = cvt(libc::getcwd(&mut buf))?;
+    let count = cvt(syscall::getcwd(&mut buf))?;
     Ok(PathBuf::from(OsString::from_vec(buf[.. count].to_vec())))
 }
 
 pub fn chdir(p: &path::Path) -> io::Result<()> {
-    cvt(libc::chdir(p.to_str().unwrap())).and(Ok(()))
+    cvt(syscall::chdir(p.to_str().unwrap())).and(Ok(()))
 }
 
 pub struct SplitPaths<'a> {
@@ -200,6 +198,6 @@ pub fn home_dir() -> Option<PathBuf> {
 }
 
 pub fn exit(code: i32) -> ! {
-    let _ = libc::exit(code as usize);
+    let _ = syscall::exit(code as usize);
     unreachable!();
 }
index fff4a10f913d2dfac22177e72b971ccb70c1c43d..7f192bef495a960424f8e9e50140cd2118ce2bc7 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 use io;
-use libc;
+use sys::syscall;
 use sys::fd::FileDesc;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -21,7 +21,7 @@
 pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
     let mut fds = [0; 2];
 
-    libc::pipe2(&mut fds, libc::O_CLOEXEC).map_err(|err| io::Error::from_raw_os_error(err.errno))?;
+    syscall::pipe2(&mut fds, syscall::O_CLOEXEC).map_err(|err| io::Error::from_raw_os_error(err.errno))?;
 
     Ok((AnonPipe(FileDesc::new(fds[0])), AnonPipe(FileDesc::new(fds[1]))))
 }
index 269aa6bedac0fc5d3ea562cab20ec4e930016ef1..3c0d96913285dbab8c1dff6803e5a89b7cb37451 100644 (file)
 use ffi::OsStr;
 use fmt;
 use io::{self, Error, ErrorKind};
-use libc::{self, pid_t, gid_t, uid_t};
 use path::Path;
 use sys::fd::FileDesc;
 use sys::fs::{File, OpenOptions};
 use sys::pipe::{self, AnonPipe};
-use sys::cvt;
+use sys::{cvt, syscall};
 
 ////////////////////////////////////////////////////////////////////////////////
 // Command
@@ -47,8 +46,8 @@ pub struct Command {
     env: HashMap<String, String>,
 
     cwd: Option<String>,
-    uid: Option<uid_t>,
-    gid: Option<gid_t>,
+    uid: Option<u32>,
+    gid: Option<u32>,
     saw_nul: bool,
     closures: Vec<Box<FnMut() -> io::Result<()> + Send + Sync>>,
     stdin: Option<Stdio>,
@@ -121,10 +120,10 @@ pub fn env_clear(&mut self) {
     pub fn cwd(&mut self, dir: &OsStr) {
         self.cwd = Some(dir.to_str().unwrap().to_owned());
     }
-    pub fn uid(&mut self, id: uid_t) {
+    pub fn uid(&mut self, id: u32) {
         self.uid = Some(id);
     }
-    pub fn gid(&mut self, id: gid_t) {
+    pub fn gid(&mut self, id: u32) {
         self.gid = Some(id);
     }
 
@@ -156,11 +155,11 @@ pub fn spawn(&mut self, default: Stdio, needs_stdin: bool)
          let (input, output) = pipe::anon_pipe()?;
 
          let pid = unsafe {
-             match cvt(libc::clone(0))? {
+             match cvt(syscall::clone(0))? {
                  0 => {
                      drop(input);
                      let err = self.do_exec(theirs);
-                     let errno = err.raw_os_error().unwrap_or(libc::EINVAL) as u32;
+                     let errno = err.raw_os_error().unwrap_or(syscall::EINVAL) as u32;
                      let bytes = [
                          (errno >> 24) as u8,
                          (errno >> 16) as u8,
@@ -173,7 +172,7 @@ pub fn spawn(&mut self, default: Stdio, needs_stdin: bool)
                      // we want to be sure we *don't* run at_exit destructors as
                      // we're being torn down regardless
                      assert!(output.write(&bytes).is_ok());
-                     let _ = libc::exit(1);
+                     let _ = syscall::exit(1);
                      panic!("failed to exit");
                  }
                  n => n,
@@ -261,7 +260,7 @@ pub fn exec(&mut self, default: Stdio) -> io::Error {
     // this file descriptor by dropping the FileDesc (which contains an
     // allocation). Instead we just close it manually. This will never
     // have the drop glue anyway because this code never returns (the
-    // child will either exec() or invoke libc::exit)
+    // child will either exec() or invoke syscall::exit)
     unsafe fn do_exec(&mut self, stdio: ChildPipes) -> io::Error {
         macro_rules! t {
             ($e:expr) => (match $e {
@@ -271,29 +270,29 @@ macro_rules! t {
         }
 
         if let Some(fd) = stdio.stderr.fd() {
-            let _ = libc::close(libc::STDERR_FILENO);
-            t!(cvt(libc::dup(fd, &[])));
-            let _ = libc::close(fd);
+            let _ = syscall::close(2);
+            t!(cvt(syscall::dup(fd, &[])));
+            let _ = syscall::close(fd);
         }
         if let Some(fd) = stdio.stdout.fd() {
-            let _ = libc::close(libc::STDOUT_FILENO);
-            t!(cvt(libc::dup(fd, &[])));
-            let _ = libc::close(fd);
+            let _ = syscall::close(1);
+            t!(cvt(syscall::dup(fd, &[])));
+            let _ = syscall::close(fd);
         }
         if let Some(fd) = stdio.stdin.fd() {
-            let _ = libc::close(libc::STDIN_FILENO);
-            t!(cvt(libc::dup(fd, &[])));
-            let _ = libc::close(fd);
+            let _ = syscall::close(0);
+            t!(cvt(syscall::dup(fd, &[])));
+            let _ = syscall::close(fd);
         }
 
         if let Some(g) = self.gid {
-            t!(cvt(libc::setregid(g, g)));
+            t!(cvt(syscall::setregid(g as usize, g as usize)));
         }
         if let Some(u) = self.uid {
-            t!(cvt(libc::setreuid(u, u)));
+            t!(cvt(syscall::setreuid(u as usize, u as usize)));
         }
         if let Some(ref cwd) = self.cwd {
-            t!(cvt(libc::chdir(cwd)));
+            t!(cvt(syscall::chdir(cwd)));
         }
 
         for callback in self.closures.iter_mut() {
@@ -324,7 +323,7 @@ macro_rules! t {
             path_env
         };
 
-        if let Err(err) = libc::exec(&program, &args) {
+        if let Err(err) = syscall::execve(&program, &args) {
             io::Error::from_raw_os_error(err.errno as i32)
         } else {
             panic!("return from exec without err");
@@ -370,7 +369,7 @@ fn to_child_stdio(&self, readable: bool)
             // stderr. No matter which we dup first, the second will get
             // overwritten prematurely.
             Stdio::Fd(ref fd) => {
-                if fd.raw() <= libc::STDERR_FILENO {
+                if fd.raw() <= 2 {
                     Ok((ChildStdio::Owned(fd.duplicate()?), None))
                 } else {
                     Ok((ChildStdio::Explicit(fd.raw()), None))
@@ -471,7 +470,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 
 /// The unique id of the process (this should never be negative).
 pub struct Process {
-    pid: pid_t,
+    pid: usize,
     status: Option<ExitStatus>,
 }
 
@@ -488,7 +487,7 @@ pub fn kill(&mut self) -> io::Result<()> {
             Err(Error::new(ErrorKind::InvalidInput,
                            "invalid argument: can't kill an exited process"))
         } else {
-            cvt(libc::kill(self.pid, libc::SIGKILL))?;
+            cvt(syscall::kill(self.pid, syscall::SIGKILL))?;
             Ok(())
         }
     }
@@ -498,7 +497,7 @@ pub fn wait(&mut self) -> io::Result<ExitStatus> {
             return Ok(status)
         }
         let mut status = 0;
-        cvt(libc::waitpid(self.pid, &mut status, 0))?;
+        cvt(syscall::waitpid(self.pid, &mut status, 0))?;
         self.status = Some(ExitStatus(status as i32));
         Ok(ExitStatus(status as i32))
     }
index 50062186903366fca5249a66635c8af719887fb0..1fe7e33a35ecd7b667627b0d80f4ec0d8b368cac 100644 (file)
@@ -9,8 +9,7 @@
 // except according to those terms.
 
 use io;
-use libc;
-use sys::cvt;
+use sys::{cvt, syscall};
 use sys::fd::FileDesc;
 
 pub struct Stdin(());
@@ -21,14 +20,14 @@ impl Stdin {
     pub fn new() -> io::Result<Stdin> { Ok(Stdin(())) }
 
     pub fn read(&self, data: &mut [u8]) -> io::Result<usize> {
-        let fd = FileDesc::new(libc::STDIN_FILENO);
+        let fd = FileDesc::new(0);
         let ret = fd.read(data);
         fd.into_raw();
         ret
     }
 
     pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> {
-        let fd = FileDesc::new(libc::STDIN_FILENO);
+        let fd = FileDesc::new(0);
         let ret = fd.read_to_end(buf);
         fd.into_raw();
         ret
@@ -39,14 +38,14 @@ impl Stdout {
     pub fn new() -> io::Result<Stdout> { Ok(Stdout(())) }
 
     pub fn write(&self, data: &[u8]) -> io::Result<usize> {
-        let fd = FileDesc::new(libc::STDOUT_FILENO);
+        let fd = FileDesc::new(1);
         let ret = fd.write(data);
         fd.into_raw();
         ret
     }
 
     pub fn flush(&self) -> io::Result<()> {
-        cvt(libc::fsync(libc::STDOUT_FILENO)).and(Ok(()))
+        cvt(syscall::fsync(1)).and(Ok(()))
     }
 }
 
@@ -54,14 +53,14 @@ impl Stderr {
     pub fn new() -> io::Result<Stderr> { Ok(Stderr(())) }
 
     pub fn write(&self, data: &[u8]) -> io::Result<usize> {
-        let fd = FileDesc::new(libc::STDERR_FILENO);
+        let fd = FileDesc::new(2);
         let ret = fd.write(data);
         fd.into_raw();
         ret
     }
 
     pub fn flush(&self) -> io::Result<()> {
-        cvt(libc::fsync(libc::STDERR_FILENO)).and(Ok(()))
+        cvt(syscall::fsync(2)).and(Ok(()))
     }
 }
 
@@ -74,9 +73,9 @@ fn write(&mut self, data: &[u8]) -> io::Result<usize> {
     }
 
     fn flush(&mut self) -> io::Result<()> {
-        cvt(libc::fsync(libc::STDERR_FILENO)).and(Ok(()))
+        cvt(syscall::fsync(2)).and(Ok(()))
     }
 }
 
-pub const EBADF_ERR: i32 = ::libc::EBADF;
+pub const EBADF_ERR: i32 = ::sys::syscall::EBADF;
 pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE;
index 46bc6346a6a80563f1a52c1c1a35c487d671f0b3..0e7b27d396107b97e5a2db33fdf8b9e764d23ee2 100644 (file)
@@ -9,17 +9,15 @@
 // except according to those terms.
 
 use alloc::boxed::FnBox;
-use cmp;
 use ffi::CStr;
 use io;
-use libc;
 use mem;
 use sys_common::thread::start_thread;
-use sys::cvt;
+use sys::{cvt, syscall};
 use time::Duration;
 
 pub struct Thread {
-    id: libc::pid_t,
+    id: usize,
 }
 
 // Some platforms may have pthread_t as a pointer in which case we still want
@@ -31,10 +29,10 @@ impl Thread {
     pub unsafe fn new<'a>(_stack: usize, p: Box<FnBox() + 'a>) -> io::Result<Thread> {
         let p = box p;
 
-        let id = cvt(libc::clone(libc::CLONE_VM | libc::CLONE_FS | libc::CLONE_FILES))?;
+        let id = cvt(syscall::clone(syscall::CLONE_VM | syscall::CLONE_FS | syscall::CLONE_FILES))?;
         if id == 0 {
             start_thread(&*p as *const _ as *mut _);
-            let _ = libc::exit(0);
+            let _ = syscall::exit(0);
             panic!("thread failed to exit");
         } else {
             mem::forget(p);
@@ -43,7 +41,7 @@ pub unsafe fn new<'a>(_stack: usize, p: Box<FnBox() + 'a>) -> io::Result<Thread>
     }
 
     pub fn yield_now() {
-        let ret = unsafe { libc::sched_yield() };
+        let ret = syscall::sched_yield().expect("failed to sched_yield");
         debug_assert_eq!(ret, 0);
     }
 
@@ -58,13 +56,13 @@ pub fn sleep(dur: Duration) {
         // If we're awoken with a signal then the return value will be -1 and
         // nanosleep will fill in `ts` with the remaining time.
         while secs > 0 || nsecs > 0 {
-            let req = libc::timespec {
-                tv_sec: cmp::min(libc::time_t::max_value() as u64, secs) as libc::time_t,
+            let req = syscall::TimeSpec {
+                tv_sec: secs as i64,
                 tv_nsec: nsecs,
             };
             secs -= req.tv_sec as u64;
-            let mut rem = libc::timespec::default();
-            if libc::nanosleep(&req, &mut rem).is_err() {
+            let mut rem = syscall::TimeSpec::default();
+            if syscall::nanosleep(&req, &mut rem).is_err() {
                 secs += rem.tv_sec as u64;
                 nsecs = rem.tv_nsec;
             } else {
@@ -75,12 +73,12 @@ pub fn sleep(dur: Duration) {
 
     pub fn join(self) {
         let mut status = 0;
-        libc::waitpid(self.id, &mut status, 0).unwrap();
+        syscall::waitpid(self.id, &mut status, 0).unwrap();
     }
 
-    pub fn id(&self) -> libc::pid_t { self.id }
+    pub fn id(&self) -> usize { self.id }
 
-    pub fn into_id(self) -> libc::pid_t {
+    pub fn into_id(self) -> usize {
         let id = self.id;
         mem::forget(self);
         id
index 4e1a82bcc9a092cf293617889a3d3758c3b894ef..8f05e3bcfe716a45455319295509eccf36aef862 100644 (file)
 
 use cmp::Ordering;
 use fmt;
-use libc;
-use sys::cvt;
+use sys::{cvt, syscall};
 use time::Duration;
 
 const NSEC_PER_SEC: u64 = 1_000_000_000;
 
 #[derive(Copy, Clone)]
 struct Timespec {
-    t: libc::timespec,
+    t: syscall::TimeSpec,
 }
 
 impl Timespec {
@@ -53,8 +52,8 @@ fn add_duration(&self, other: &Duration) -> Timespec {
                                                duration to time");
         }
         Timespec {
-            t: libc::timespec {
-                tv_sec: secs as libc::time_t,
+            t: syscall::TimeSpec {
+                tv_sec: secs as i64,
                 tv_nsec: nsec as i32,
             },
         }
@@ -73,8 +72,8 @@ fn sub_duration(&self, other: &Duration) -> Timespec {
                                                duration from time");
         }
         Timespec {
-            t: libc::timespec {
-                tv_sec: secs as libc::time_t,
+            t: syscall::TimeSpec {
+                tv_sec: secs as i64,
                 tv_nsec: nsec as i32,
             },
         }
@@ -115,7 +114,7 @@ pub struct SystemTime {
 
 pub const UNIX_EPOCH: SystemTime = SystemTime {
     t: Timespec {
-        t: libc::timespec {
+        t: syscall::TimeSpec {
             tv_sec: 0,
             tv_nsec: 0,
         },
@@ -124,7 +123,7 @@ pub struct SystemTime {
 
 impl Instant {
     pub fn now() -> Instant {
-        Instant { t: now(libc::CLOCK_MONOTONIC) }
+        Instant { t: now(syscall::CLOCK_MONOTONIC) }
     }
 
     pub fn sub_instant(&self, other: &Instant) -> Duration {
@@ -153,7 +152,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 
 impl SystemTime {
     pub fn now() -> SystemTime {
-        SystemTime { t: now(libc::CLOCK_REALTIME) }
+        SystemTime { t: now(syscall::CLOCK_REALTIME) }
     }
 
     pub fn sub_time(&self, other: &SystemTime)
@@ -170,8 +169,8 @@ pub fn sub_duration(&self, other: &Duration) -> SystemTime {
     }
 }
 
-impl From<libc::timespec> for SystemTime {
-    fn from(t: libc::timespec) -> SystemTime {
+impl From<syscall::TimeSpec> for SystemTime {
+    fn from(t: syscall::TimeSpec) -> SystemTime {
         SystemTime { t: Timespec { t: t } }
     }
 }
@@ -189,11 +188,11 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 
 fn now(clock: clock_t) -> Timespec {
     let mut t = Timespec {
-        t: libc::timespec {
+        t: syscall::TimeSpec {
             tv_sec: 0,
             tv_nsec: 0,
         }
     };
-    cvt(libc::clock_gettime(clock, &mut t.t)).unwrap();
+    cvt(syscall::clock_gettime(clock, &mut t.t)).unwrap();
     t
 }