Skip to content

Commit

Permalink
Reorganize some newlib definitions into a "generic" module
Browse files Browse the repository at this point in the history
  • Loading branch information
AzureMarker committed Mar 14, 2022
1 parent b61fe73 commit 0c92066
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 52 deletions.
2 changes: 2 additions & 0 deletions src/unix/newlib/aarch64/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub use crate::unix::newlib::generic::{sigset_t, stat};

pub type clock_t = ::c_long;
pub type c_char = u8;
pub type wchar_t = u32;
Expand Down
2 changes: 2 additions & 0 deletions src/unix/newlib/arm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub use crate::unix::newlib::generic::{sigset_t, stat};

pub type clock_t = ::c_long;
pub type c_char = u8;
pub type wchar_t = u32;
Expand Down
2 changes: 2 additions & 0 deletions src/unix/newlib/espidf/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub use crate::unix::newlib::generic::{sigset_t, stat};

pub type clock_t = ::c_ulong;
pub type c_char = i8;
pub type wchar_t = u32;
Expand Down
27 changes: 27 additions & 0 deletions src/unix/newlib/generic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! Common types used by most newlib platforms
s! {
pub struct sigset_t {
__val: [::c_ulong; 16],
}

pub struct stat {
pub st_dev: ::dev_t,
pub st_ino: ::ino_t,
pub st_mode: ::mode_t,
pub st_nlink: ::nlink_t,
pub st_uid: ::uid_t,
pub st_gid: ::gid_t,
pub st_rdev: ::dev_t,
pub st_size: ::off_t,
pub st_atime: ::time_t,
pub st_spare1: ::c_long,
pub st_mtime: ::time_t,
pub st_spare2: ::c_long,
pub st_ctime: ::time_t,
pub st_spare3: ::c_long,
pub st_blksize: ::blksize_t,
pub st_blocks: ::blkcnt_t,
pub st_spare4: [::c_long; 2usize],
}
}
19 changes: 18 additions & 1 deletion src/unix/newlib/horizon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub type clock_t = c_ulong;
pub type daddr_t = c_long;
pub type caddr_t = *mut c_char;
pub type sbintime_t = ::c_longlong;
pub type sigset_t = ::c_ulong;

// External implementations are needed to use networking and threading.
s! {
pub struct sockaddr {
pub sa_family: ::sa_family_t,
Expand Down Expand Up @@ -55,6 +55,23 @@ s! {
pub struct sched_param {
pub sched_priority: ::c_int,
}

pub struct stat {
pub st_dev: ::dev_t,
pub st_ino: ::ino_t,
pub st_mode: ::mode_t,
pub st_nlink: ::nlink_t,
pub st_uid: ::uid_t,
pub st_gid: ::gid_t,
pub st_rdev: ::dev_t,
pub st_size: ::off_t,
pub st_atim: ::timespec,
pub st_mtim: ::timespec,
pub st_ctim: ::timespec,
pub st_blksize: ::blksize_t,
pub st_blocks: ::blkcnt_t,
pub st_spare4: [::c_long; 2usize],
}
}

pub const SIGEV_NONE: ::c_int = 1;
Expand Down
53 changes: 2 additions & 51 deletions src/unix/newlib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,57 +229,6 @@ s! {
}
}

cfg_if! {
if #[cfg(target_os = "horizon")] {
pub type sigset_t = ::c_ulong;

s! {
pub struct stat {
pub st_dev: ::dev_t,
pub st_ino: ::ino_t,
pub st_mode: ::mode_t,
pub st_nlink: ::nlink_t,
pub st_uid: ::uid_t,
pub st_gid: ::gid_t,
pub st_rdev: dev_t,
pub st_size: off_t,
pub st_atim: ::timespec,
pub st_mtim: ::timespec,
pub st_ctim: ::timespec,
pub st_blksize: blksize_t,
pub st_blocks: blkcnt_t,
pub st_spare4: [::c_long; 2usize],
}
}
} else {
s! {
pub struct sigset_t {
__val: [::c_ulong; 16],
}

pub struct stat {
pub st_dev: ::dev_t,
pub st_ino: ::ino_t,
pub st_mode: ::mode_t,
pub st_nlink: ::nlink_t,
pub st_uid: ::uid_t,
pub st_gid: ::gid_t,
pub st_rdev: dev_t,
pub st_size: off_t,
pub st_atime: time_t,
pub st_spare1: ::c_long,
pub st_mtime: time_t,
pub st_spare2: ::c_long,
pub st_ctime: time_t,
pub st_spare3: ::c_long,
pub st_blksize: blksize_t,
pub st_blocks: blkcnt_t,
pub st_spare4: [::c_long; 2usize],
}
}
}
}

// unverified constants
align_const! {
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
Expand Down Expand Up @@ -774,6 +723,8 @@ extern "C" {
pub fn uname(buf: *mut ::utsname) -> ::c_int;
}

mod generic;

cfg_if! {
if #[cfg(target_os = "espidf")] {
mod espidf;
Expand Down
2 changes: 2 additions & 0 deletions src/unix/newlib/powerpc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub use crate::unix::newlib::generic::{sigset_t, stat};

pub type clock_t = ::c_ulong;
pub type c_char = u8;
pub type wchar_t = ::c_int;
Expand Down

0 comments on commit 0c92066

Please sign in to comment.