Remove stat and lstat, which can be replaced with open and fstat

This commit is contained in:
Jeremy Soller
2018-08-25 10:13:58 -06:00
parent 34f5f57213
commit ff32c8cbbd
11 changed files with 35 additions and 51 deletions
-8
View File
@@ -233,10 +233,6 @@ impl Pal for Sys {
e(unsafe { syscall!(LSEEK, fildes, offset, whence) }) as off_t
}
fn lstat(file: *const c_char, buf: *mut stat) -> c_int {
e(unsafe { syscall!(NEWFSTATAT, AT_FDCWD, file, buf, AT_SYMLINK_NOFOLLOW) }) as c_int
}
fn mkdir(path: *const c_char, mode: mode_t) -> c_int {
e(unsafe { syscall!(MKDIRAT, AT_FDCWD, path, mode) }) as c_int
}
@@ -310,10 +306,6 @@ impl Pal for Sys {
e(unsafe { syscall!(SETREUID, ruid, euid) }) as c_int
}
fn stat(file: *const c_char, buf: *mut stat) -> c_int {
e(unsafe { syscall!(NEWFSTATAT, AT_FDCWD, file, buf, 0) }) as c_int
}
fn tcgetattr(fd: c_int, out: *mut termios) -> c_int {
Self::ioctl(fd, TCGETS, out as *mut c_void)
}
-8
View File
@@ -164,10 +164,6 @@ pub trait Pal {
Self::no_pal("lseek") as off_t
}
fn lstat(file: *const c_char, buf: *mut stat) -> c_int {
Self::no_pal("lstat")
}
fn mkdir(path: *const c_char, mode: mode_t) -> c_int {
Self::no_pal("mkdir")
}
@@ -241,10 +237,6 @@ pub trait Pal {
Self::no_pal("setreuid")
}
fn stat(file: *const c_char, buf: *mut stat) -> c_int {
Self::no_pal("stat")
}
fn tcgetattr(fd: c_int, out: *mut termios) -> c_int {
Self::no_pal("tcgetattr")
}
-24
View File
@@ -454,18 +454,6 @@ impl Pal for Sys {
)) as off_t
}
fn lstat(path: *const c_char, buf: *mut stat) -> c_int {
let path = unsafe { c_str(path) };
match syscall::open(path, O_STAT | O_NOFOLLOW) {
Err(err) => e(Err(err)) as c_int,
Ok(fd) => {
let res = Self::fstat(fd as i32, buf);
let _ = syscall::close(fd);
res
}
}
}
fn mkdir(path: *const c_char, mode: mode_t) -> c_int {
let flags = O_CREAT | O_EXCL | O_CLOEXEC | O_DIRECTORY | mode as usize & 0o777;
let path = unsafe { c_str(path) };
@@ -700,18 +688,6 @@ impl Pal for Sys {
e(syscall::setreuid(ruid as usize, euid as usize)) as c_int
}
fn stat(path: *const c_char, buf: *mut stat) -> c_int {
let path = unsafe { c_str(path) };
match syscall::open(path, O_STAT) {
Err(err) => e(Err(err)) as c_int,
Ok(fd) => {
let res = Self::fstat(fd as i32, buf);
let _ = syscall::close(fd);
res
}
}
}
fn tcgetattr(fd: c_int, out: *mut termios) -> c_int {
let dup = e(syscall::dup(fd as usize, b"termios"));
if dup == !0 {