diff options
author | Skyler Hawthorne <skylerhawthorne@gmail.com> | 2015-05-05 15:26:45 -0700 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2015-05-08 14:11:44 -0700 |
commit | ecbbf1a8176130ca845b23c3e9dfe37d45da3c13 (patch) | |
tree | 61e47f190a2bb64f3d20e41bb823f6219fa6ff36 /src/sys | |
parent | d01c032b1c1fd5bf8cd26275ffece653af30426f (diff) | |
download | nix-ecbbf1a8176130ca845b23c3e9dfe37d45da3c13.zip |
Add lstat
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/stat.rs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/sys/stat.rs b/src/sys/stat.rs index d98d20ec..cafb36d9 100644 --- a/src/sys/stat.rs +++ b/src/sys/stat.rs @@ -1,7 +1,7 @@ pub use libc::dev_t; pub use libc::stat as FileStat; -use {Error, Result, NixPath, AsExtStr,from_ffi}; +use {Error, Result, NixPath, AsExtStr, from_ffi}; use errno::Errno; use fcntl::Fd; use libc::mode_t; @@ -10,7 +10,7 @@ use std::mem; mod ffi { use libc::{c_char, c_int, mode_t, dev_t}; - pub use libc::{stat, fstat}; + pub use libc::{stat, fstat, lstat}; extern { pub fn mknod(pathname: *const c_char, mode: mode_t, dev: dev_t) -> c_int; @@ -94,6 +94,21 @@ pub fn stat<P: ?Sized + NixPath>(path: &P) -> Result<FileStat> { Ok(dst) } +pub fn lstat<P: ?Sized + NixPath>(path: &P) -> Result<FileStat> { + let mut dst = unsafe { mem::uninitialized() }; + let res = try!(path.with_nix_path(|osstr| { + unsafe { + ffi::lstat(osstr.as_ext_str(), &mut dst as *mut FileStat) + } + })); + + if res < 0 { + return Err(Error::Sys(Errno::last())); + } + + Ok(dst) +} + pub fn fstat(fd: Fd) -> Result<FileStat> { let mut dst = unsafe { mem::uninitialized() }; let res = unsafe { ffi::fstat(fd, &mut dst as *mut FileStat) }; |