summaryrefslogtreecommitdiff
path: root/src/sys/stat.rs
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2019-08-30 23:10:22 -0600
committerAlan Somers <asomers@gmail.com>2019-09-03 16:25:41 -0600
commit469032433d68841ad098f03aa2b28e81235b8be8 (patch)
treea34108f1688355ebaa6d5eed8a2eecafc5d32dfa /src/sys/stat.rs
parenta4a465d25567f163f9552b977eb4d17435251d41 (diff)
downloadnix-469032433d68841ad098f03aa2b28e81235b8be8.zip
Replace most instances of mem::uninitialized with mem::MaybeUninit
Only two instances remain: * For the deprecated sys::socket::CmsgSpace::new. We should probably just remove that method. * For sys::termios::Termios::default_uninit. This will require some more thought. Fixes #1096
Diffstat (limited to 'src/sys/stat.rs')
-rw-r--r--src/sys/stat.rs24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/sys/stat.rs b/src/sys/stat.rs
index 66c8c9dd..29582251 100644
--- a/src/sys/stat.rs
+++ b/src/sys/stat.rs
@@ -78,49 +78,49 @@ pub fn umask(mode: Mode) -> Mode {
}
pub fn stat<P: ?Sized + NixPath>(path: &P) -> Result<FileStat> {
- let mut dst = unsafe { mem::uninitialized() };
+ let mut dst = mem::MaybeUninit::uninit();
let res = path.with_nix_path(|cstr| {
unsafe {
- libc::stat(cstr.as_ptr(), &mut dst as *mut FileStat)
+ libc::stat(cstr.as_ptr(), dst.as_mut_ptr())
}
})?;
Errno::result(res)?;
- Ok(dst)
+ Ok(unsafe{dst.assume_init()})
}
pub fn lstat<P: ?Sized + NixPath>(path: &P) -> Result<FileStat> {
- let mut dst = unsafe { mem::uninitialized() };
+ let mut dst = mem::MaybeUninit::uninit();
let res = path.with_nix_path(|cstr| {
unsafe {
- libc::lstat(cstr.as_ptr(), &mut dst as *mut FileStat)
+ libc::lstat(cstr.as_ptr(), dst.as_mut_ptr())
}
})?;
Errno::result(res)?;
- Ok(dst)
+ Ok(unsafe{dst.assume_init()})
}
pub fn fstat(fd: RawFd) -> Result<FileStat> {
- let mut dst = unsafe { mem::uninitialized() };
- let res = unsafe { libc::fstat(fd, &mut dst as *mut FileStat) };
+ let mut dst = mem::MaybeUninit::uninit();
+ let res = unsafe { libc::fstat(fd, dst.as_mut_ptr()) };
Errno::result(res)?;
- Ok(dst)
+ Ok(unsafe{dst.assume_init()})
}
pub fn fstatat<P: ?Sized + NixPath>(dirfd: RawFd, pathname: &P, f: AtFlags) -> Result<FileStat> {
- let mut dst = unsafe { mem::uninitialized() };
+ let mut dst = mem::MaybeUninit::uninit();
let res = pathname.with_nix_path(|cstr| {
- unsafe { libc::fstatat(dirfd, cstr.as_ptr(), &mut dst as *mut FileStat, f.bits() as libc::c_int) }
+ unsafe { libc::fstatat(dirfd, cstr.as_ptr(), dst.as_mut_ptr(), f.bits() as libc::c_int) }
})?;
Errno::result(res)?;
- Ok(dst)
+ Ok(unsafe{dst.assume_init()})
}
/// Change the file permission bits of the file specified by a file descriptor.