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

minor fixes

parent 304473b6
No related branches found
No related tags found
1 merge request!110Partial implementation of sys/stat.h
...@@ -35,7 +35,11 @@ pub fn chmod(path: *const c_char, mode: mode_t) -> c_int { ...@@ -35,7 +35,11 @@ pub fn chmod(path: *const c_char, mode: mode_t) -> c_int {
let path = unsafe { c_str(path) }; let path = unsafe { c_str(path) };
match syscall::open(path, O_WRONLY) { match syscall::open(path, O_WRONLY) {
Err(err) => e(Err(err)) as c_int, Err(err) => e(Err(err)) as c_int,
Ok(fd) => e(syscall::fchmod(fd as usize, mode)) as c_int, Ok(fd) => {
let res = syscall::fchmod(fd as usize, mode);
let _ = syscall::close(fd);
e(res) as c_int
}
} }
} }
...@@ -43,7 +47,11 @@ pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { ...@@ -43,7 +47,11 @@ pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int {
let path = unsafe { c_str(path) }; let path = unsafe { c_str(path) };
match syscall::open(path, O_WRONLY) { match syscall::open(path, O_WRONLY) {
Err(err) => e(Err(err)) as c_int, Err(err) => e(Err(err)) as c_int,
Ok(fd) => e(syscall::fchown(fd as usize, owner as u32, group as u32)) as c_int, Ok(fd) => {
let res = syscall::fchown(fd as usize, owner as u32, group as u32);
let _ = syscall::close(fd);
e(res) as c_int
}
} }
} }
...@@ -60,7 +68,7 @@ pub fn dup2(fd1: c_int, fd2: c_int) -> c_int { ...@@ -60,7 +68,7 @@ pub fn dup2(fd1: c_int, fd2: c_int) -> c_int {
} }
pub fn exit(status: c_int) -> ! { pub fn exit(status: c_int) -> ! {
syscall::exit(status as usize); let _ = syscall::exit(status as usize);
loop {} loop {}
} }
...@@ -171,7 +179,11 @@ pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int { ...@@ -171,7 +179,11 @@ pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int {
let path = unsafe { c_str(path) }; let path = unsafe { c_str(path) };
match syscall::open(path, O_RDONLY | O_NOFOLLOW) { match syscall::open(path, O_RDONLY | O_NOFOLLOW) {
Err(err) => e(Err(err)) as c_int, Err(err) => e(Err(err)) as c_int,
Ok(fd) => fstat(fd as i32, buf), Ok(fd) => {
let res = fstat(fd as i32, buf);
let _ = syscall::close(fd);
res
}
} }
} }
...@@ -180,7 +192,7 @@ pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int { ...@@ -180,7 +192,7 @@ pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int {
let path = unsafe { c_str(path) }; let path = unsafe { c_str(path) };
match syscall::open(path, flags) { match syscall::open(path, flags) {
Ok(fd) => { Ok(fd) => {
syscall::close(fd); let _ = syscall::close(fd);
0 0
} }
Err(err) => e(Err(err)) as c_int, Err(err) => e(Err(err)) as c_int,
...@@ -247,7 +259,11 @@ pub fn stat(path: *const c_char, buf: *mut stat) -> c_int { ...@@ -247,7 +259,11 @@ pub fn stat(path: *const c_char, buf: *mut stat) -> c_int {
let path = unsafe { c_str(path) }; let path = unsafe { c_str(path) };
match syscall::open(path, O_RDONLY) { match syscall::open(path, O_RDONLY) {
Err(err) => e(Err(err)) as c_int, Err(err) => e(Err(err)) as c_int,
Ok(fd) => fstat(fd as i32, buf), Ok(fd) => {
let res = fstat(fd as i32, buf);
let _ = syscall::close(fd);
res
}
} }
} }
......
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