Fix linux build

This commit is contained in:
Jeremy Soller
2018-03-06 20:44:21 -07:00
parent b768e44678
commit cf03233e66
2 changed files with 18 additions and 20 deletions
+6 -4
View File
@@ -7,16 +7,18 @@
#[macro_use]
extern crate sc;
#[cfg(all(not(feature = "no_std"), target_os = "redox"))]
#[macro_use]
extern crate syscall;
pub use sys::*;
#[cfg(all(not(feature = "no_std"), target_os = "linux"))]
#[path = "linux/mod.rs"]
mod sys;
#[cfg(all(not(feature="no_std"), target_os = "redox"))]
#[macro_use]
extern crate syscall;
#[path="redox/mod.rs"]
#[cfg(all(not(feature = "no_std"), target_os = "redox"))]
#[path = "redox/mod.rs"]
mod sys;
pub mod types;
+12 -16
View File
@@ -4,9 +4,7 @@ use c_str;
use types::*;
pub fn brk(addr: *const c_void) -> c_int {
unsafe {
syscall::brk(addr as usize).unwrap_or(0-1) as c_int
}
unsafe { syscall::brk(addr as usize).unwrap_or(0 - 1) as c_int }
}
pub fn chdir(path: *const c_char) -> c_int {
@@ -17,7 +15,7 @@ pub fn chdir(path: *const c_char) -> c_int {
pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int {
let path = unsafe { c_str(path) };
let fd = syscall::open(path, 0x0001).unwrap();
syscall::fchown(fd as usize, owner as u32, group as u32).unwrap_or(0-1) as c_int
syscall::fchown(fd as usize, owner as u32, group as u32).unwrap_or(0 - 1) as c_int
}
pub fn close(fd: c_int) -> c_int {
@@ -26,11 +24,11 @@ pub fn close(fd: c_int) -> c_int {
}
pub fn dup(fd: c_int) -> c_int {
syscall::dup(fd as usize, &[]).unwrap_or(0-1) as c_int
syscall::dup(fd as usize, &[]).unwrap_or(0 - 1) as c_int
}
pub fn dup2(fd1: c_int, fd2: c_int) -> c_int {
syscall::dup2(fd1 as usize, fd2 as usize, &[]).unwrap_or(0-1) as c_int
syscall::dup2(fd1 as usize, fd2 as usize, &[]).unwrap_or(0 - 1) as c_int
}
pub fn exit(status: c_int) -> ! {
@@ -39,35 +37,35 @@ pub fn exit(status: c_int) -> ! {
}
pub fn fchown(fd: c_int, owner: uid_t, group: gid_t) -> c_int {
syscall::fchown(fd as usize, owner as u32, group as u32).unwrap_or(0-1) as c_int
syscall::fchown(fd as usize, owner as u32, group as u32).unwrap_or(0 - 1) as c_int
}
pub fn fchdir(fd: c_int) -> c_int {
let path: &mut [u8] = &mut[0; 4096];
let path: &mut [u8] = &mut [0; 4096];
let result = syscall::fpath(fd as usize, path);
if result.is_ok() {
syscall::chdir(path).unwrap_or(0-1) as c_int
syscall::chdir(path).unwrap_or(0 - 1) as c_int
} else {
-1
}
}
pub fn fsync(fd: c_int) -> c_int {
syscall::fsync(fd as usize).unwrap_or(0-1) as c_int
syscall::fsync(fd as usize).unwrap_or(0 - 1) as c_int
}
pub fn ftruncate(fd: c_int, len: off_t) -> c_int {
syscall::ftruncate(fd as usize, len as usize).unwrap_or(0-1) as c_int
syscall::ftruncate(fd as usize, len as usize).unwrap_or(0 - 1) as c_int
}
pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char {
// XXX: do something with size maybe
let rbuf: &mut [u8] = &mut[0; 4096];
let rbuf: &mut [u8] = &mut [0; 4096];
syscall::getcwd(rbuf);
unsafe {
let buf = *rbuf.as_ptr() as *mut c_char;
}
buf
buf
}
pub fn getegid() -> gid_t {
@@ -101,9 +99,7 @@ pub fn getuid() -> uid_t {
pub fn link(path1: *const c_char, path2: *const c_char) -> c_int {
let path1 = unsafe { c_str(path1) };
let path2 = unsafe { c_str(path2) };
unsafe {
syscall::link(path1.as_ptr(), path2.as_ptr()).unwrap_or(0-1) as c_int
}
unsafe { syscall::link(path1.as_ptr(), path2.as_ptr()).unwrap_or(0 - 1) as c_int }
}
pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {