Skip to content

Commit aead757

Browse files
committed
reuse mknod/umask/fstat/lstat from libc
1 parent d0628e1 commit aead757

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

src/sys/stat.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@ use libc::{self, mode_t};
77
use std::mem;
88
use std::os::unix::io::RawFd;
99

10-
mod ffi {
11-
use libc::{c_char, c_int, mode_t, dev_t};
12-
pub use libc::{stat, fstat, lstat};
13-
14-
extern {
15-
pub fn mknod(pathname: *const c_char, mode: mode_t, dev: dev_t) -> c_int;
16-
pub fn umask(mask: mode_t) -> mode_t;
17-
}
18-
}
19-
2010
libc_bitflags!(
2111
pub flags SFlag: mode_t {
2212
S_IFIFO,
@@ -56,7 +46,7 @@ bitflags! {
5646
pub fn mknod<P: ?Sized + NixPath>(path: &P, kind: SFlag, perm: Mode, dev: dev_t) -> Result<()> {
5747
let res = try!(path.with_nix_path(|cstr| {
5848
unsafe {
59-
ffi::mknod(cstr.as_ptr(), kind.bits | perm.bits() as mode_t, dev)
49+
libc::mknod(cstr.as_ptr(), kind.bits | perm.bits() as mode_t, dev)
6050
}
6151
}));
6252

@@ -84,15 +74,15 @@ pub fn makedev(major: u64, minor: u64) -> dev_t {
8474
}
8575

8676
pub fn umask(mode: Mode) -> Mode {
87-
let prev = unsafe { ffi::umask(mode.bits() as mode_t) };
77+
let prev = unsafe { libc::umask(mode.bits() as mode_t) };
8878
Mode::from_bits(prev).expect("[BUG] umask returned invalid Mode")
8979
}
9080

9181
pub fn stat<P: ?Sized + NixPath>(path: &P) -> Result<FileStat> {
9282
let mut dst = unsafe { mem::uninitialized() };
9383
let res = try!(path.with_nix_path(|cstr| {
9484
unsafe {
95-
ffi::stat(cstr.as_ptr(), &mut dst as *mut FileStat)
85+
libc::stat(cstr.as_ptr(), &mut dst as *mut FileStat)
9686
}
9787
}));
9888

@@ -105,7 +95,7 @@ pub fn lstat<P: ?Sized + NixPath>(path: &P) -> Result<FileStat> {
10595
let mut dst = unsafe { mem::uninitialized() };
10696
let res = try!(path.with_nix_path(|cstr| {
10797
unsafe {
108-
ffi::lstat(cstr.as_ptr(), &mut dst as *mut FileStat)
98+
libc::lstat(cstr.as_ptr(), &mut dst as *mut FileStat)
10999
}
110100
}));
111101

@@ -116,7 +106,7 @@ pub fn lstat<P: ?Sized + NixPath>(path: &P) -> Result<FileStat> {
116106

117107
pub fn fstat(fd: RawFd) -> Result<FileStat> {
118108
let mut dst = unsafe { mem::uninitialized() };
119-
let res = unsafe { ffi::fstat(fd, &mut dst as *mut FileStat) };
109+
let res = unsafe { libc::fstat(fd, &mut dst as *mut FileStat) };
120110

121111
try!(Errno::result(res));
122112

0 commit comments

Comments
 (0)