summaryrefslogtreecommitdiff
path: root/src/sys/statfs.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/statfs.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/statfs.rs')
-rw-r--r--src/sys/statfs.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/sys/statfs.rs b/src/sys/statfs.rs
index d4596bf3..c71b5767 100644
--- a/src/sys/statfs.rs
+++ b/src/sys/statfs.rs
@@ -15,6 +15,7 @@ pub type fsid_t = libc::__fsid_t;
pub type fsid_t = libc::fsid_t;
#[derive(Clone, Copy)]
+#[repr(transparent)]
pub struct Statfs(libc::statfs);
#[cfg(target_os = "freebsd")]
@@ -434,16 +435,17 @@ impl Debug for Statfs {
pub fn statfs<P: ?Sized + NixPath>(path: &P) -> Result<Statfs> {
unsafe {
- let mut stat: Statfs = mem::uninitialized();
- let res = path.with_nix_path(|path| libc::statfs(path.as_ptr(), &mut stat.0))?;
- Errno::result(res).map(|_| stat)
+ let mut stat = mem::MaybeUninit::<libc::statfs>::uninit();
+ let res = path.with_nix_path(|path| libc::statfs(path.as_ptr(), stat.as_mut_ptr()))?;
+ Errno::result(res).map(|_| Statfs(stat.assume_init()))
}
}
pub fn fstatfs<T: AsRawFd>(fd: &T) -> Result<Statfs> {
unsafe {
- let mut stat: Statfs = mem::uninitialized();
- Errno::result(libc::fstatfs(fd.as_raw_fd(), &mut stat.0)).map(|_| stat)
+ let mut stat = mem::MaybeUninit::<libc::statfs>::uninit();
+ Errno::result(libc::fstatfs(fd.as_raw_fd(), stat.as_mut_ptr()))
+ .map(|_| Statfs(stat.assume_init()))
}
}