mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 04:27:45 +00:00
Merge pull request #3199 from jfinkels/df-safe-statfs
df: use safe wrapper function for statfs() func.
This commit is contained in:
commit
95765dcd2c
1 changed files with 4 additions and 21 deletions
|
@ -9,18 +9,14 @@
|
||||||
mod table;
|
mod table;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use uucore::fsext::statfs_fn;
|
use uucore::fsext::statfs;
|
||||||
use uucore::fsext::{read_fs_list, FsUsage, MountInfo};
|
use uucore::fsext::{read_fs_list, FsUsage, MountInfo};
|
||||||
use uucore::{error::UResult, format_usage};
|
use uucore::{error::UResult, format_usage};
|
||||||
|
|
||||||
use clap::{crate_version, App, AppSettings, Arg, ArgMatches};
|
use clap::{crate_version, App, AppSettings, Arg, ArgMatches};
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
#[cfg(unix)]
|
|
||||||
use std::ffi::CString;
|
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
#[cfg(unix)]
|
|
||||||
use std::mem;
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -183,23 +179,10 @@ impl Filesystem {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
unsafe {
|
let usage = FsUsage::new(statfs(_stat_path).ok()?);
|
||||||
let path = CString::new(_stat_path).unwrap();
|
|
||||||
let mut statvfs = mem::zeroed();
|
|
||||||
if statfs_fn(path.as_ptr(), &mut statvfs) < 0 {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(Self {
|
|
||||||
mount_info,
|
|
||||||
usage: FsUsage::new(statvfs),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
Some(Self {
|
let usage = FsUsage::new(Path::new(&_stat_path));
|
||||||
mount_info,
|
Some(Self { mount_info, usage })
|
||||||
usage: FsUsage::new(Path::new(&_stat_path)),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue