summaryrefslogtreecommitdiff
path: root/src/unistd.rs
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2014-08-20 17:55:44 -0700
committerCarl Lerche <me@carllerche.com>2014-08-20 17:55:47 -0700
commitbbc24ea90eb9814db71a1297c4deb4eef91f9c2d (patch)
tree1c58cac016618e19df8d10c900303347234fcf7a /src/unistd.rs
parentd55f55674bee15bfc3c2afa63949d9037b3f5c6f (diff)
downloadnix-bbc24ea90eb9814db71a1297c4deb4eef91f9c2d.zip
Start binding Darwin
Diffstat (limited to 'src/unistd.rs')
-rw-r--r--src/unistd.rs44
1 files changed, 25 insertions, 19 deletions
diff --git a/src/unistd.rs b/src/unistd.rs
index 4b141f17..c418b1e9 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -1,13 +1,12 @@
-#![cfg(target_os = "linux")]
-
use std::ptr;
use std::c_str::{CString, ToCStr};
-use std::path::Path;
use libc::{c_char, c_void, size_t};
use fcntl::{Fd, OFlag};
-use syscall::{syscall, SysPivotRoot};
use errno::{SysResult, SysError, from_ffi};
+#[cfg(target_os = "linux")]
+pub use self::linux::*;
+
mod ffi {
use libc::{c_char, c_int};
pub use libc::{close, read, write};
@@ -94,21 +93,6 @@ pub fn execve(filename: CString, args: &[CString], env: &[CString]) -> SysResult
Ok(())
}
-pub fn pivot_root(new_root: &Path, put_old: &Path) -> SysResult<()> {
- let new_root = new_root.to_c_str();
- let put_old = put_old.to_c_str();
-
- let res = unsafe {
- syscall(SysPivotRoot, new_root.as_ptr(), put_old.as_ptr())
- };
-
- if res != 0 {
- return Err(SysError::last());
- }
-
- Ok(())
-}
-
pub fn close(fd: Fd) -> SysResult<()> {
let res = unsafe { ffi::close(fd) };
from_ffi(res)
@@ -133,3 +117,25 @@ pub fn write(fd: Fd, buf: &[u8]) -> SysResult<uint> {
return Ok(res as uint)
}
+
+#[cfg(target_os = "linux")]
+mod linux {
+ use std::path::Path;
+ use syscall::{syscall, SysPivotRoot};
+ use errno::{SysResult, SysError};
+
+ pub fn pivot_root(new_root: &Path, put_old: &Path) -> SysResult<()> {
+ let new_root = new_root.to_c_str();
+ let put_old = put_old.to_c_str();
+
+ let res = unsafe {
+ syscall(SysPivotRoot, new_root.as_ptr(), put_old.as_ptr())
+ };
+
+ if res != 0 {
+ return Err(SysError::last());
+ }
+
+ Ok(())
+ }
+}