Remove stat and lstat, which can be replaced with open and fstat
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user