Skip to content

Commit 50c1ec1

Browse files
authored
refactor: cfg for stat/statfs (#2219)
1 parent 0c8da48 commit 50c1ec1

File tree

2 files changed

+14
-37
lines changed

2 files changed

+14
-37
lines changed

src/sys/stat.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#[cfg(any(apple_targets, target_os = "openbsd"))]
22
pub use libc::c_uint;
3-
#[cfg(any(
4-
target_os = "netbsd",
5-
target_os = "freebsd",
6-
target_os = "dragonfly"
7-
))]
3+
#[cfg(any(target_os = "netbsd", freebsdlike))]
84
pub use libc::c_ulong;
95
pub use libc::stat as FileStat;
106
pub use libc::{dev_t, mode_t};
@@ -67,11 +63,7 @@ libc_bitflags! {
6763

6864
#[cfg(any(apple_targets, target_os = "openbsd"))]
6965
pub type type_of_file_flag = c_uint;
70-
#[cfg(any(
71-
target_os = "netbsd",
72-
target_os = "freebsd",
73-
target_os = "dragonfly"
74-
))]
66+
#[cfg(any(freebsdlike, target_os = "netbsd"))]
7567
pub type type_of_file_flag = c_ulong;
7668

7769
#[cfg(bsd)]

src/sys/statfs.rs

+12-27
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Get filesystem statistics, non-portably
22
//!
33
//! See [`statvfs`](crate::sys::statvfs) for a portable alternative.
4-
#[cfg(not(any(target_os = "linux", target_os = "android")))]
4+
#[cfg(not(linux_android))]
55
use std::ffi::CStr;
66
use std::fmt::{self, Debug};
77
use std::mem;
@@ -12,8 +12,7 @@ use cfg_if::cfg_if;
1212
#[cfg(all(
1313
feature = "mount",
1414
any(
15-
target_os = "dragonfly",
16-
target_os = "freebsd",
15+
freebsdlike,
1716
target_os = "macos",
1817
target_os = "netbsd",
1918
target_os = "openbsd"
@@ -32,7 +31,7 @@ pub type fsid_t = libc::__fsid_t;
3231
pub type fsid_t = libc::fsid_t;
3332

3433
cfg_if! {
35-
if #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] {
34+
if #[cfg(any(linux_android, target_os = "fuchsia"))] {
3635
type type_of_statfs = libc::statfs64;
3736
const LIBC_FSTATFS: unsafe extern fn
3837
(fd: libc::c_int, buf: *mut type_of_statfs) -> libc::c_int
@@ -288,10 +287,7 @@ pub const XENFS_SUPER_MAGIC: FsType =
288287
#[cfg(linux_android)]
289288
#[allow(missing_docs)]
290289
pub const NSFS_MAGIC: FsType = FsType(libc::NSFS_MAGIC as fs_type_t);
291-
#[cfg(all(
292-
any(target_os = "linux", target_os = "android"),
293-
not(target_env = "musl")
294-
))]
290+
#[cfg(all(linux_android, not(target_env = "musl")))]
295291
#[allow(missing_docs)]
296292
pub const XFS_SUPER_MAGIC: FsType = FsType(libc::XFS_SUPER_MAGIC as fs_type_t);
297293

@@ -307,7 +303,7 @@ impl Statfs {
307303
}
308304

309305
/// Magic code defining system type
310-
#[cfg(not(any(target_os = "linux", target_os = "android")))]
306+
#[cfg(not(linux_android))]
311307
pub fn filesystem_type_name(&self) -> &str {
312308
let c_str = unsafe { CStr::from_ptr(self.0.f_fstypename.as_ptr()) };
313309
c_str.to_str().unwrap()
@@ -434,8 +430,7 @@ impl Statfs {
434430
#[cfg(all(
435431
feature = "mount",
436432
any(
437-
target_os = "dragonfly",
438-
target_os = "freebsd",
433+
freebsdlike,
439434
target_os = "macos",
440435
target_os = "netbsd",
441436
target_os = "openbsd"
@@ -500,11 +495,10 @@ impl Statfs {
500495
/// Total data blocks in filesystem
501496
#[cfg(any(
502497
apple_targets,
503-
target_os = "android",
498+
linux_android,
504499
target_os = "freebsd",
505500
target_os = "fuchsia",
506501
target_os = "openbsd",
507-
target_os = "linux",
508502
))]
509503
pub fn blocks(&self) -> u64 {
510504
self.0.f_blocks
@@ -525,11 +519,10 @@ impl Statfs {
525519
/// Free blocks in filesystem
526520
#[cfg(any(
527521
apple_targets,
528-
target_os = "android",
522+
linux_android,
529523
target_os = "freebsd",
530524
target_os = "fuchsia",
531525
target_os = "openbsd",
532-
target_os = "linux",
533526
))]
534527
pub fn blocks_free(&self) -> u64 {
535528
self.0.f_bfree
@@ -548,12 +541,7 @@ impl Statfs {
548541
}
549542

550543
/// Free blocks available to unprivileged user
551-
#[cfg(any(
552-
apple_targets,
553-
target_os = "android",
554-
target_os = "fuchsia",
555-
target_os = "linux",
556-
))]
544+
#[cfg(any(apple_targets, linux_android, target_os = "fuchsia"))]
557545
pub fn blocks_available(&self) -> u64 {
558546
self.0.f_bavail
559547
}
@@ -579,11 +567,10 @@ impl Statfs {
579567
/// Total file nodes in filesystem
580568
#[cfg(any(
581569
apple_targets,
582-
target_os = "android",
570+
linux_android,
583571
target_os = "freebsd",
584572
target_os = "fuchsia",
585573
target_os = "openbsd",
586-
target_os = "linux",
587574
))]
588575
pub fn files(&self) -> u64 {
589576
self.0.f_files
@@ -604,10 +591,9 @@ impl Statfs {
604591
/// Free file nodes in filesystem
605592
#[cfg(any(
606593
apple_targets,
607-
target_os = "android",
594+
linux_android,
608595
target_os = "fuchsia",
609596
target_os = "openbsd",
610-
target_os = "linux",
611597
))]
612598
pub fn files_free(&self) -> u64 {
613599
self.0.f_ffree
@@ -651,8 +637,7 @@ impl Debug for Statfs {
651637
#[cfg(all(
652638
feature = "mount",
653639
any(
654-
target_os = "dragonfly",
655-
target_os = "freebsd",
640+
freebsdlike,
656641
target_os = "macos",
657642
target_os = "netbsd",
658643
target_os = "openbsd"

0 commit comments

Comments
 (0)