Skip to content
Snippets Groups Projects
Commit 3ad7c626 authored by Paul Sajna's avatar Paul Sajna
Browse files

fsync and some tweaks

parent 9de89e03
No related branches found
No related tags found
No related merge requests found
......@@ -57,6 +57,12 @@ pub fn fchdir(fildes: c_int) -> c_int {
}
}
pub fn fsync(fildes: c_int) -> c_int {
unsafe {
syscall!(FSYNC, fildes) as c_int
}
}
#[cfg(target_arch = "x86_64")]
pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
unsafe {
......
......@@ -3,20 +3,18 @@ use syscall;
use c_str;
use types::*;
pub unsafe fn cstr_to_slice<'a>(buf: *const c_char) -> &'a [u8] {
slice::from_raw_parts(buf as *const u8, ::strlen(buf) as usize)
}
pub fn brk(addr: *const c_void) -> {
syscall::brk(addr as usize)? as c_int
pub fn chdir(path: *const c_char) -> c_int {
syscall::chdir(cstr_to_slice(path))? as c_int
}
pub fn chdir(path: *const c_char) -> c_int {
let path = unsafe { c_str(path) };
syscall::chdir(path)? as c_int
}
pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int {
let fd = syscall::open(cstr_to_slice(path));
syscall::fchown(fd, owner, group)? as c_int
syscall::fchown(fd as usize, owner as usize, group as usize)? as c_int
pub fn close(fd: c_int) -> c_int {
syscall::close(fd as usize);
......@@ -37,12 +35,20 @@ pub fn exit(status: c_int) -> ! {
}
pub fn fchown(fd: c_int, owner: uid_t, group: gid_t) -> c_int {
syscall::fchown(owner, group)? as c_int
syscall::fchown(owner as usize, group as usize)? as c_int
}
pub fn fchdir(fd: c_int) -> c_int {
let path = fpath(fd as usize, &[]).unwrap();
syscall::chdir(path)? as c_int
let result = fpath(fd as usize, &[]);
if result.is_ok() {
syscall::chdir(path)? as c_int
} else {
-1
}
}
pub fn fsync(fd: c_int) -> c_int {
syscall::fsync(fd as usize)? as c_int
}
pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
......
......@@ -156,7 +156,7 @@ pub extern "C" fn fpathconf(fildes: c_int, name: c_int) -> c_long {
#[no_mangle]
pub extern "C" fn fsync(fildes: c_int) -> c_int {
unimplemented!();
platform::fsync(fildes)
}
#[no_mangle]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment