Skip to content

Commit

Permalink
Move unix platforms into the same folder to move the unix files into …
Browse files Browse the repository at this point in the history
…it as well
  • Loading branch information
GuillaumeGomez committed Sep 14, 2023
1 parent ffd95c1 commit ced536d
Show file tree
Hide file tree
Showing 47 changed files with 64 additions and 63 deletions.
46 changes: 9 additions & 37 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,24 @@ cfg_if::cfg_if! {

#[cfg(test)]
pub(crate) const MIN_USERS: usize = 0;
} else if #[cfg(any(target_os = "macos", target_os = "ios"))] {
mod apple;
use apple as sys;
pub(crate) mod users;
mod network_helper_nix;
use network_helper_nix as network_helper;
} else if #[cfg(any(
target_os = "macos", target_os = "ios",
target_os = "linux", target_os = "android",
target_os = "freebsd"))]
{
mod unix;
use unix::sys as sys;
use unix::{network_helper, users};
mod network;

pub(crate) use libc::__error as libc_errno;

#[cfg(test)]
pub(crate) const MIN_USERS: usize = 1;
} else if #[cfg(windows)] {
mod windows;
use windows as sys;
mod network_helper_win;
use network_helper_win as network_helper;
mod network;

#[cfg(test)]
pub(crate) const MIN_USERS: usize = 1;
} else if #[cfg(any(target_os = "linux", target_os = "android"))] {
mod linux;
use linux as sys;
pub(crate) mod users;
mod network_helper_nix;
use network_helper_nix as network_helper;
use window::network_helper;
mod network;

#[cfg(target_os = "linux")]
pub(crate) use libc::__errno_location as libc_errno;
#[cfg(target_os = "android")]
pub(crate) use libc::__errno as libc_errno;

#[cfg(test)]
pub(crate) const MIN_USERS: usize = 1;
} else if #[cfg(target_os = "freebsd")] {
mod freebsd;
use freebsd as sys;
pub(crate) mod users;
mod network_helper_nix;
use network_helper_nix as network_helper;
mod network;

pub(crate) use libc::__error as libc_errno;

#[cfg(test)]
pub(crate) const MIN_USERS: usize = 1;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ macro_rules! declare_signals {
#[cfg(all(unix, not(feature = "unknown-ci")))]
macro_rules! retry_eintr {
(set_to_0 => $($t:tt)+) => {{
let errno = crate::libc_errno();
let errno = crate::unix::libc_errno();
if !errno.is_null() {
*errno = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::ComponentExt;

#[doc = include_str!("../../../md_doc/component.md")]
#[doc = include_str!("../../../../md_doc/component.md")]
pub struct Component {}

impl ComponentExt for Component {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::path::Path;

use crate::{DiskUsage, Gid, Pid, ProcessExt, ProcessStatus, Signal, Uid};

#[doc = include_str!("../../../md_doc/process.md")]
#[doc = include_str!("../../../../md_doc/process.md")]
pub struct Process;

impl ProcessExt for Process {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/apple/cpu.rs → src/unix/apple/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Drop for CpuData {
}
}

#[doc = include_str!("../../md_doc/cpu.md")]
#[doc = include_str!("../../../md_doc/cpu.md")]
pub struct Cpu {
name: String,
cpu_usage: f32,
Expand Down
2 changes: 1 addition & 1 deletion src/apple/disk.rs → src/unix/apple/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::os::unix::ffi::OsStrExt;
use std::path::{Path, PathBuf};
use std::ptr;

#[doc = include_str!("../../md_doc/disk.md")]
#[doc = include_str!("../../../md_doc/disk.md")]
pub struct Disk {
pub(crate) type_: DiskKind,
pub(crate) name: OsString,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use core_foundation_sys::string::{
kCFStringEncodingUTF8, CFStringCreateWithBytes, CFStringGetCStringPtr,
};

use crate::apple::inner::ffi::{
use crate::sys::inner::ffi::{
kHIDPage_AppleVendor, kHIDUsage_AppleVendor_TemperatureSensor, kIOHIDEventTypeTemperature,
matching, IOHIDEventFieldBase, IOHIDEventGetFloatValue, IOHIDEventSystemClientCopyServices,
IOHIDEventSystemClientCreate, IOHIDEventSystemClientSetMatching, IOHIDServiceClientCopyEvent,
Expand Down Expand Up @@ -109,7 +109,7 @@ impl Components {
unsafe impl Send for Components {}
unsafe impl Sync for Components {}

#[doc = include_str!("../../../../md_doc/component.md")]
#[doc = include_str!("../../../../../md_doc/component.md")]
pub struct Component {
service: CFReleaser<__IOHIDServiceClient>,
temperature: f32,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Components {
}
}

#[doc = include_str!("../../../../md_doc/component.md")]
#[doc = include_str!("../../../../../md_doc/component.md")]
pub struct Component {
temperature: f32,
max: f32,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{DiskUsage, Gid, Pid, ProcessExt, ProcessRefreshKind, ProcessStatus,
use crate::sys::process::ThreadStatus;
use crate::sys::system::Wrap;

#[doc = include_str!("../../../md_doc/process.md")]
#[doc = include_str!("../../../../md_doc/process.md")]
pub struct Process {
pub(crate) name: String,
pub(crate) cmd: Vec<String>,
Expand Down Expand Up @@ -316,7 +316,7 @@ fn check_if_pid_is_alive(pid: Pid, check_if_alive: bool) -> bool {
return true;
}
// `kill` failed but it might not be because the process is dead.
let errno = crate::libc_errno();
let errno = crate::unix::libc_errno();
// If errno is equal to ESCHR, it means the process is dead.
!errno.is_null() && *errno != libc::ESRCH
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/apple/network.rs → src/unix/apple/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl NetworksExt for Networks {
}
}

#[doc = include_str!("../../md_doc/network_data.md")]
#[doc = include_str!("../../../md_doc/network_data.md")]
#[derive(PartialEq, Eq)]
pub struct NetworkData {
current_in: u64,
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/apple/system.rs → src/unix/apple/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ declare_signals! {
_ => None,
}

#[doc = include_str!("../../md_doc/system.md")]
#[doc = include_str!("../../../md_doc/system.md")]
pub struct System {
process_list: HashMap<Pid, Process>,
mem_total: u64,
Expand Down Expand Up @@ -327,7 +327,7 @@ impl SystemExt for System {
}

fn refresh_users_list(&mut self) {
self.users = crate::apple::users::get_users_list();
self.users = crate::sys::users::get_users_list();
}

// COMMON PART
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/freebsd/component.rs → src/unix/freebsd/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use super::utils::get_sys_value_by_name;
use crate::ComponentExt;

#[doc = include_str!("../../md_doc/component.md")]
#[doc = include_str!("../../../md_doc/component.md")]
pub struct Component {
id: Vec<u8>,
label: String,
Expand Down
2 changes: 1 addition & 1 deletion src/freebsd/cpu.rs → src/unix/freebsd/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl CpusWrapper {
}
}

#[doc = include_str!("../../md_doc/cpu.md")]
#[doc = include_str!("../../../md_doc/cpu.md")]
pub struct Cpu {
pub(crate) cpu_usage: f32,
name: String,
Expand Down
2 changes: 1 addition & 1 deletion src/freebsd/disk.rs → src/unix/freebsd/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::path::{Path, PathBuf};

use super::utils::c_buf_to_str;

#[doc = include_str!("../../md_doc/disk.md")]
#[doc = include_str!("../../../md_doc/disk.md")]
pub struct Disk {
name: OsString,
c_mount_point: Vec<libc::c_char>,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/freebsd/network.rs → src/unix/freebsd/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl Networks {
}
}

#[doc = include_str!("../../md_doc/network_data.md")]
#[doc = include_str!("../../../md_doc/network_data.md")]
pub struct NetworkData {
/// Total number of bytes received over interface.
ifi_ibytes: u64,
Expand Down
2 changes: 1 addition & 1 deletion src/freebsd/process.rs → src/unix/freebsd/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl fmt::Display for ProcessStatus {
}
}

#[doc = include_str!("../../md_doc/process.md")]
#[doc = include_str!("../../../md_doc/process.md")]
pub struct Process {
pub(crate) name: String,
pub(crate) cmd: Vec<String>,
Expand Down
2 changes: 1 addition & 1 deletion src/freebsd/system.rs → src/unix/freebsd/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ declare_signals! {
_ => None,
}

#[doc = include_str!("../../md_doc/system.md")]
#[doc = include_str!("../../../md_doc/system.md")]
pub struct System {
process_list: HashMap<Pid, Process>,
mem_total: u64,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/linux/component.rs → src/unix/linux/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::fs::{read_dir, File};
use std::io::Read;
use std::path::{Path, PathBuf};

#[doc = include_str!("../../md_doc/component.md")]
#[doc = include_str!("../../../md_doc/component.md")]
#[derive(Default)]
pub struct Component {
/// Optional associated device of a `Component`.
Expand Down
2 changes: 1 addition & 1 deletion src/linux/cpu.rs → src/unix/linux/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl CpuValues {
}
}

#[doc = include_str!("../../md_doc/cpu.md")]
#[doc = include_str!("../../../md_doc/cpu.md")]
pub struct Cpu {
old_values: CpuValues,
new_values: CpuValues,
Expand Down
2 changes: 1 addition & 1 deletion src/linux/disk.rs → src/unix/linux/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ macro_rules! cast {
};
}

#[doc = include_str!("../../md_doc/disk.md")]
#[doc = include_str!("../../../md_doc/disk.md")]
#[derive(PartialEq, Eq)]
pub struct Disk {
type_: DiskKind,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/linux/network.rs → src/unix/linux/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl NetworksExt for Networks {
}
}

#[doc = include_str!("../../md_doc/network_data.md")]
#[doc = include_str!("../../../md_doc/network_data.md")]
pub struct NetworkData {
/// Total number of bytes received over interface.
rx_bytes: u64,
Expand Down
2 changes: 1 addition & 1 deletion src/linux/process.rs → src/unix/linux/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl fmt::Display for ProcessStatus {
}
}

#[doc = include_str!("../../md_doc/process.md")]
#[doc = include_str!("../../../md_doc/process.md")]
pub struct Process {
pub(crate) name: String,
pub(crate) cmd: Vec<String>,
Expand Down
2 changes: 1 addition & 1 deletion src/linux/system.rs → src/unix/linux/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ declare_signals! {
Signal::Sys => libc::SIGSYS,
}

#[doc = include_str!("../../md_doc/system.md")]
#[doc = include_str!("../../../md_doc/system.md")]
pub struct System {
process_list: Process,
mem_total: u64,
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Take a look at the license at the top of the repository in the LICENSE file.

cfg_if::cfg_if! {
if #[cfg(any(target_os = "macos", target_os = "ios"))] {
pub(crate) mod apple;
pub(crate) use apple as sys;

pub(crate) use libc::__error as libc_errno;
} else if #[cfg(any(target_os = "linux", target_os = "android"))] {
pub(crate) mod linux;
pub(crate) use linux as sys;

#[cfg(target_os = "linux")]
pub(crate) use libc::__errno_location as libc_errno;
#[cfg(target_os = "android")]
pub(crate) use libc::__errno as libc_errno;
} else if #[cfg(target_os = "freebsd")] {
pub(crate) mod freebsd;
pub(crate) use freebsd as sys;

pub(crate) use libc::__error as libc_errno;
} else {
compile_error!("Invalid cfg!");
}
}

pub(crate) mod network_helper;
pub(crate) mod users;
File renamed without changes.
2 changes: 1 addition & 1 deletion src/users.rs → src/unix/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use libc::{getgrgid_r, getgrouplist};
use std::fs::File;
use std::io::Read;

#[doc = include_str!("../md_doc/user.md")]
#[doc = include_str!("../../md_doc/user.md")]
pub struct User {
pub(crate) uid: Uid,
pub(crate) gid: Gid,
Expand Down
1 change: 1 addition & 0 deletions src/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod component;
mod cpu;
mod disk;
mod network;
pub(crate) mod network_helper;
mod process;
mod sid;
mod system;
Expand Down
File renamed without changes.

0 comments on commit ced536d

Please sign in to comment.