Skip to content

Commit

Permalink
Allow cfg attributes in s! and use it for mips-special statfs structure
Browse files Browse the repository at this point in the history
  • Loading branch information
bossmc committed Oct 10, 2024
1 parent 2199836 commit 1cf4443
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 54 deletions.
25 changes: 4 additions & 21 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,11 @@ macro_rules! s {
__item! {
#[repr(C)]
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
#[derive(Copy, Clone)]
#[allow(deprecated)]
$(#[$attr])*
pub struct $i { $($field)* }
}
#[allow(deprecated)]
impl ::Copy for $i {}
#[allow(deprecated)]
impl ::Clone for $i {
fn clone(&self) -> $i { *self }
}
);
}

Expand All @@ -106,13 +101,10 @@ macro_rules! s_paren {
)*) => ($(
__item! {
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
#[derive(Copy, Clone)]
$(#[$attr])*
pub struct $i ( $($field)* );
}
impl ::Copy for $i {}
impl ::Clone for $i {
fn clone(&self) -> $i { *self }
}
)*);
}

Expand All @@ -131,27 +123,18 @@ macro_rules! s_no_extra_traits {
__item! {
#[repr(C)]
$(#[$attr])*
#[derive(Copy, Clone)]
pub union $i { $($field)* }
}

impl ::Copy for $i {}
impl ::Clone for $i {
fn clone(&self) -> $i { *self }
}
);

(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
__item! {
#[repr(C)]
$(#[$attr])*
#[derive(Copy, Clone)]
pub struct $i { $($field)* }
}
#[allow(deprecated)]
impl ::Copy for $i {}
#[allow(deprecated)]
impl ::Clone for $i {
fn clone(&self) -> $i { *self }
}
);
}

Expand Down
64 changes: 31 additions & 33 deletions src/unix/linux_like/linux/musl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,41 +453,39 @@ s! {
//pub tcpi_rcv_ooopack: u32,
//pub tcpi_snd_wnd: u32,
}
}

cfg_if! {
if #[cfg(not(target_arch = "mips"))] {
s! {
pub struct statfs {
pub f_type: ::c_ulong,
pub f_bsize: ::c_ulong,
pub f_blocks: ::fsblkcnt_t,
pub f_bfree: ::fsblkcnt_t,
pub f_bavail: ::fsblkcnt_t,
pub f_files: ::fsfilcnt_t,
pub f_ffree: ::fsfilcnt_t,
pub f_fsid: ::fsid_t,
pub f_namelen: ::c_ulong,
pub f_frsize: ::c_ulong,
pub f_flags: ::c_ulong,
pub f_spare: [::c_ulong; 4],
}
// MIPS implementation is special (see mips arch folders)
#[cfg(not(target_arch = "mips"))]
pub struct statfs {
pub f_type: ::c_ulong,
pub f_bsize: ::c_ulong,
pub f_blocks: ::fsblkcnt_t,
pub f_bfree: ::fsblkcnt_t,
pub f_bavail: ::fsblkcnt_t,
pub f_files: ::fsfilcnt_t,
pub f_ffree: ::fsfilcnt_t,
pub f_fsid: ::fsid_t,
pub f_namelen: ::c_ulong,
pub f_frsize: ::c_ulong,
pub f_flags: ::c_ulong,
pub f_spare: [::c_ulong; 4],
}

pub struct statfs64 {
pub f_type: ::c_ulong,
pub f_bsize: ::c_ulong,
pub f_blocks: ::fsblkcnt64_t,
pub f_bfree: ::fsblkcnt64_t,
pub f_bavail: ::fsblkcnt64_t,
pub f_files: ::fsfilcnt64_t,
pub f_ffree: ::fsfilcnt64_t,
pub f_fsid: ::fsid_t,
pub f_namelen: ::c_ulong,
pub f_frsize: ::c_ulong,
pub f_flags: ::c_ulong,
pub f_spare: [::c_ulong; 4],
}
}
// MIPS implementation is special (see mips arch folders)
#[cfg(not(target_arch = "mips"))]
pub struct statfs64 {
pub f_type: ::c_ulong,
pub f_bsize: ::c_ulong,
pub f_blocks: ::fsblkcnt64_t,
pub f_bfree: ::fsblkcnt64_t,
pub f_bavail: ::fsblkcnt64_t,
pub f_files: ::fsfilcnt64_t,
pub f_ffree: ::fsfilcnt64_t,
pub f_fsid: ::fsid_t,
pub f_namelen: ::c_ulong,
pub f_frsize: ::c_ulong,
pub f_flags: ::c_ulong,
pub f_spare: [::c_ulong; 4],
}
}

Expand Down

0 comments on commit 1cf4443

Please sign in to comment.