From ecbbf1a8176130ca845b23c3e9dfe37d45da3c13 Mon Sep 17 00:00:00 2001 From: Skyler Hawthorne Date: Tue, 5 May 2015 15:26:45 -0700 Subject: Add lstat --- src/sys/stat.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/sys/stat.rs') 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(path: &P) -> Result { Ok(dst) } +pub fn lstat(path: &P) -> Result { + 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 { let mut dst = unsafe { mem::uninitialized() }; let res = unsafe { ffi::fstat(fd, &mut dst as *mut FileStat) }; -- cgit v1.2.3