From 50a42e20f4d958b1f2826f875bd7b929c36b0715 Mon Sep 17 00:00:00 2001 From: Alex Crichton <alex@alexcrichton.com> Date: Tue, 15 Sep 2015 14:27:15 -0700 Subject: [PATCH] Major organization revamp Everything is a tree! --- src/lib.rs | 35 +- src/linuxlike/android.rs | 69 ---- src/linuxlike/b32/android.rs | 40 -- src/linuxlike/b32/mips.rs | 36 -- src/linuxlike/b32/mod.rs | 45 -- src/linuxlike/linux/mod.rs | 175 -------- src/unix/android.rs | 25 -- src/{ => unix/bsd}/apple/b32.rs | 0 src/{ => unix/bsd}/apple/b64.rs | 2 +- src/{ => unix/bsd}/apple/mod.rs | 84 +--- src/{ => unix/bsd}/freebsdlike/dragonfly.rs | 0 src/{ => unix/bsd}/freebsdlike/freebsd.rs | 0 src/{ => unix/bsd}/freebsdlike/mod.rs | 90 +--- src/{ => unix/bsd}/freebsdlike/x86.rs | 2 +- src/{ => unix/bsd}/freebsdlike/x86_64.rs | 0 src/unix/bsd/mod.rs | 69 ++++ .../bsd/openbsdlike/mod.rs} | 0 src/unix/mod.rs | 387 ++++++++++++------ src/unix/notbsd/android.rs | 162 ++++++++ src/{linuxlike => unix/notbsd}/linux/mips.rs | 65 +++ src/unix/notbsd/linux/mod.rs | 188 +++++++++ .../notbsd/linux/notmips/b32.rs} | 33 +- .../notbsd/linux/notmips}/b64/aarch64.rs | 0 .../notbsd/linux/notmips}/b64/mod.rs | 0 .../notbsd/linux/notmips}/b64/x86_64.rs | 0 .../notbsd/linux/notmips/mod.rs} | 12 + src/{linuxlike => unix/notbsd}/mod.rs | 102 +---- src/unix/other/bsdlike.rs | 22 - src/unix/other/mod.rs | 83 ---- src/unix/other/notbsd.rs | 14 - 30 files changed, 819 insertions(+), 921 deletions(-) delete mode 100644 src/linuxlike/android.rs delete mode 100644 src/linuxlike/b32/android.rs delete mode 100644 src/linuxlike/b32/mips.rs delete mode 100644 src/linuxlike/b32/mod.rs delete mode 100644 src/linuxlike/linux/mod.rs delete mode 100644 src/unix/android.rs rename src/{ => unix/bsd}/apple/b32.rs (100%) rename src/{ => unix/bsd}/apple/b64.rs (91%) rename src/{ => unix/bsd}/apple/mod.rs (91%) rename src/{ => unix/bsd}/freebsdlike/dragonfly.rs (100%) rename src/{ => unix/bsd}/freebsdlike/freebsd.rs (100%) rename src/{ => unix/bsd}/freebsdlike/mod.rs (88%) rename src/{ => unix/bsd}/freebsdlike/x86.rs (98%) rename src/{ => unix/bsd}/freebsdlike/x86_64.rs (100%) create mode 100644 src/unix/bsd/mod.rs rename src/{openbsdlike.rs => unix/bsd/openbsdlike/mod.rs} (100%) create mode 100644 src/unix/notbsd/android.rs rename src/{linuxlike => unix/notbsd}/linux/mips.rs (73%) create mode 100644 src/unix/notbsd/linux/mod.rs rename src/{linuxlike/b32/other.rs => unix/notbsd/linux/notmips/b32.rs} (52%) rename src/{linuxlike => unix/notbsd/linux/notmips}/b64/aarch64.rs (100%) rename src/{linuxlike => unix/notbsd/linux/notmips}/b64/mod.rs (100%) rename src/{linuxlike => unix/notbsd/linux/notmips}/b64/x86_64.rs (100%) rename src/{linuxlike/linux/other.rs => unix/notbsd/linux/notmips/mod.rs} (94%) rename src/{linuxlike => unix/notbsd}/mod.rs (83%) delete mode 100644 src/unix/other/bsdlike.rs delete mode 100644 src/unix/other/mod.rs delete mode 100644 src/unix/other/notbsd.rs diff --git a/src/lib.rs b/src/lib.rs index 8677ad91..b3319475 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,31 +32,6 @@ pub enum fpos_t {} pub enum DIR {} pub enum dirent {} -cfg_if! { - if #[cfg(any(target_os = "macos", target_os = "ios"))] { - mod apple; - pub use apple::*; - } else if #[cfg(any(target_os = "openbsd", target_os = "netbsd", - target_os = "dragonfly"))] { - mod openbsdlike; - pub use openbsdlike::*; - } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] { - mod freebsdlike; - pub use freebsdlike::*; - } else if #[cfg(any(target_os = "android", target_os = "linux"))] { - mod linuxlike; - pub use linuxlike::*; - } else if #[cfg(windows)] { - mod windows; - pub use windows::*; - } else { - // ... - } -} - -#[cfg(unix)] mod unix; -#[cfg(unix)] pub use unix::*; - extern { pub fn isalnum(c: c_int) -> c_int; pub fn isalpha(c: c_int) -> c_int; @@ -173,3 +148,13 @@ extern { pub fn rand() -> c_int; pub fn srand(seed: c_uint); } + +cfg_if! { + if #[cfg(windows)] { + mod windows; + pub use windows::*; + } else { + mod unix; + pub use unix::*; + } +} diff --git a/src/linuxlike/android.rs b/src/linuxlike/android.rs deleted file mode 100644 index e8b7caa3..00000000 --- a/src/linuxlike/android.rs +++ /dev/null @@ -1,69 +0,0 @@ -//! Android-specific definitions for linux-like values - -pub const BUFSIZ: ::c_uint = 1024; -pub const FILENAME_MAX: ::c_uint = 1024; -pub const FOPEN_MAX: ::c_uint = 20; -pub const L_tmpnam: ::c_uint = 1024; -pub const TMP_MAX: ::c_uint = 308915776; -pub const _PC_NAME_MAX: ::c_int = 4; - -pub const _SC_ARG_MAX: ::c_int = 0; -pub const _SC_BC_BASE_MAX: ::c_int = 1; -pub const _SC_BC_DIM_MAX: ::c_int = 2; -pub const _SC_BC_SCALE_MAX: ::c_int = 3; -pub const _SC_BC_STRING_MAX: ::c_int = 4; -pub const _SC_CHILD_MAX: ::c_int = 5; -pub const _SC_CLK_TCK: ::c_int = 6; -pub const _SC_COLL_WEIGHTS_MAX: ::c_int = 7; -pub const _SC_EXPR_NEST_MAX: ::c_int = 8; -pub const _SC_LINE_MAX: ::c_int = 9; -pub const _SC_NGROUPS_MAX: ::c_int = 10; -pub const _SC_OPEN_MAX: ::c_int = 11; -pub const _SC_2_C_BIND: ::c_int = 13; -pub const _SC_2_C_DEV: ::c_int = 14; -pub const _SC_2_C_VERSION: ::c_int = 15; -pub const _SC_2_CHAR_TERM: ::c_int = 16; -pub const _SC_2_FORT_DEV: ::c_int = 17; -pub const _SC_2_FORT_RUN: ::c_int = 18; -pub const _SC_2_LOCALEDEF: ::c_int = 19; -pub const _SC_2_SW_DEV: ::c_int = 20; -pub const _SC_2_UPE: ::c_int = 21; -pub const _SC_2_VERSION: ::c_int = 22; -pub const _SC_JOB_CONTROL: ::c_int = 23; -pub const _SC_SAVED_IDS: ::c_int = 24; -pub const _SC_VERSION: ::c_int = 25; -pub const _SC_RE_DUP_MAX: ::c_int = 26; -pub const _SC_STREAM_MAX: ::c_int = 27; -pub const _SC_TZNAME_MAX: ::c_int = 28; -pub const _SC_XOPEN_CRYPT: ::c_int = 29; -pub const _SC_XOPEN_ENH_I18N: ::c_int = 30; -pub const _SC_XOPEN_SHM: ::c_int = 31; -pub const _SC_XOPEN_VERSION: ::c_int = 32; -pub const _SC_XOPEN_XCU_VERSION: ::c_int = 33; -pub const _SC_XOPEN_REALTIME: ::c_int = 34; -pub const _SC_XOPEN_REALTIME_THREADS: ::c_int = 35; -pub const _SC_XOPEN_LEGACY: ::c_int = 36; -pub const _SC_ATEXIT_MAX: ::c_int = 37; -pub const _SC_IOV_MAX: ::c_int = 38; -pub const _SC_PAGESIZE: ::c_int = 39; -pub const _SC_XOPEN_UNIX: ::c_int = 41; -pub const _SC_MQ_PRIO_MAX: ::c_int = 51; -pub const _SC_GETGR_R_SIZE_MAX: ::c_int = 71; -pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 72; -pub const _SC_LOGIN_NAME_MAX: ::c_int = 73; -pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: ::c_int = 74; -pub const _SC_THREAD_KEYS_MAX: ::c_int = 75; -pub const _SC_THREAD_STACK_MIN: ::c_int = 76; -pub const _SC_THREAD_THREADS_MAX: ::c_int = 77; -pub const _SC_TTY_NAME_MAX: ::c_int = 78; -pub const _SC_THREADS: ::c_int = 79; -pub const _SC_THREAD_ATTR_STACKADDR: ::c_int = 80; -pub const _SC_THREAD_ATTR_STACKSIZE: ::c_int = 81; -pub const _SC_THREAD_PRIORITY_SCHEDULING: ::c_int = 82; -pub const _SC_THREAD_PRIO_INHERIT: ::c_int = 83; -pub const _SC_THREAD_PRIO_PROTECT: ::c_int = 84; -pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 85; - -pub const PTHREAD_STACK_MIN: ::size_t = 8192; - -pub const O_SYNC: ::c_int = 0x1000; diff --git a/src/linuxlike/b32/android.rs b/src/linuxlike/b32/android.rs deleted file mode 100644 index 290b3a00..00000000 --- a/src/linuxlike/b32/android.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! Android specific definitions for 32-bit linux-like values - -pub type blkcnt_t = u32; -pub type blksize_t = u32; -pub type dev_t = u32; -pub type mode_t = u16; -pub type nlink_t = u16; - -s! { - pub struct stat { - pub st_dev: ::c_ulonglong, - __pad0: [::c_uchar; 4], - __st_ino: ::ino_t, - pub st_mode: ::c_uint, - pub st_nlink: ::c_uint, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::c_ulonglong, - __pad3: [::c_uchar; 4], - pub st_size: ::c_longlong, - pub st_blksize: blksize_t, - pub st_blocks: ::c_ulonglong, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_ulong, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_ulong, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_ulong, - pub st_ino: ::c_ulonglong, - } - - pub struct pthread_attr_t { - pub flags: ::uint32_t, - pub stack_base: *mut ::c_void, - pub stack_size: ::size_t, - pub guard_size: ::size_t, - pub sched_policy: ::int32_t, - pub sched_priority: ::int32_t, - } -} diff --git a/src/linuxlike/b32/mips.rs b/src/linuxlike/b32/mips.rs deleted file mode 100644 index b20504e9..00000000 --- a/src/linuxlike/b32/mips.rs +++ /dev/null @@ -1,36 +0,0 @@ -//! MIPS specific definitions for 32-bit linux-like values - -pub type blkcnt_t = i32; -pub type blksize_t = i32; -pub type dev_t = u64; -pub type mode_t = u32; -pub type nlink_t = u32; - -s! { - pub struct stat { - pub st_dev: ::c_ulong, - pub st_pad1: [::c_long; 3], - 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: ::c_ulong, - pub st_pad2: [::c_long; 2], - pub st_size: ::off_t, - pub st_pad3: ::c_long, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_pad5: [::c_long; 14], - } - - pub struct pthread_attr_t { - __size: [u32; 9] - } -} diff --git a/src/linuxlike/b32/mod.rs b/src/linuxlike/b32/mod.rs deleted file mode 100644 index 02f1c217..00000000 --- a/src/linuxlike/b32/mod.rs +++ /dev/null @@ -1,45 +0,0 @@ -//! 32-bit specific definitions for linux-like values - -pub type c_char = i8; -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_long = i32; -pub type c_ulong = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type size_t = u32; -pub type ptrdiff_t = i32; -pub type clock_t = i32; -pub type time_t = i32; -pub type suseconds_t = i32; -pub type wchar_t = i32; -pub type c_longlong = i64; -pub type c_ulonglong = u64; -pub type intptr_t = i32; -pub type uintptr_t = u32; -pub type intmax_t = i64; -pub type uintmax_t = u64; -pub type off_t = i32; -pub type ino_t = u32; -pub type pid_t = i32; -pub type uid_t = u32; -pub type gid_t = u32; -pub type useconds_t = u32; -pub type ssize_t = i32; - -cfg_if! { - if #[cfg(target_os = "android")] { - mod android; - pub use self::android::*; - } else if #[cfg(any(target_arch = "mips", target_arch = "mipsel"))] { - mod mips; - pub use self::mips::*; - } else { - mod other; - pub use self::other::*; - } -} diff --git a/src/linuxlike/linux/mod.rs b/src/linuxlike/linux/mod.rs deleted file mode 100644 index 7d508aeb..00000000 --- a/src/linuxlike/linux/mod.rs +++ /dev/null @@ -1,175 +0,0 @@ -//! Linux-specific definitions for linux-like values - -s! { - pub struct glob_t { - pub gl_pathc: ::size_t, - pub gl_pathv: *mut *mut ::c_char, - pub gl_offs: ::size_t, - pub gl_flags: ::c_int, - - __unused1: *mut ::c_void, - __unused2: *mut ::c_void, - __unused3: *mut ::c_void, - __unused4: *mut ::c_void, - __unused5: *mut ::c_void, - } - - pub struct ifaddrs { - pub ifa_next: *mut ::ifaddrs, - pub ifa_name: *mut ::c_char, - pub ifa_flags: ::c_uint, - pub ifa_addr: *mut ::sockaddr, - pub ifa_netmask: *mut ::sockaddr, - pub ifa_ifu: *mut ::sockaddr, // FIXME This should be a union - pub ifa_data: *mut ::c_void - } -} - -pub const BUFSIZ: ::c_uint = 8192; -pub const FILENAME_MAX: ::c_uint = 4096; -pub const FOPEN_MAX: ::c_uint = 16; -pub const L_tmpnam: ::c_uint = 20; -pub const TMP_MAX: ::c_uint = 238328; -pub const _PC_NAME_MAX: ::c_int = 3; - -pub const _SC_ARG_MAX: ::c_int = 0; -pub const _SC_CHILD_MAX: ::c_int = 1; -pub const _SC_CLK_TCK: ::c_int = 2; -pub const _SC_NGROUPS_MAX: ::c_int = 3; -pub const _SC_OPEN_MAX: ::c_int = 4; -pub const _SC_STREAM_MAX: ::c_int = 5; -pub const _SC_TZNAME_MAX: ::c_int = 6; -pub const _SC_JOB_CONTROL: ::c_int = 7; -pub const _SC_SAVED_IDS: ::c_int = 8; -pub const _SC_REALTIME_SIGNALS: ::c_int = 9; -pub const _SC_PRIORITY_SCHEDULING: ::c_int = 10; -pub const _SC_TIMERS: ::c_int = 11; -pub const _SC_ASYNCHRONOUS_IO: ::c_int = 12; -pub const _SC_PRIORITIZED_IO: ::c_int = 13; -pub const _SC_SYNCHRONIZED_IO: ::c_int = 14; -pub const _SC_FSYNC: ::c_int = 15; -pub const _SC_MAPPED_FILES: ::c_int = 16; -pub const _SC_MEMLOCK: ::c_int = 17; -pub const _SC_MEMLOCK_RANGE: ::c_int = 18; -pub const _SC_MEMORY_PROTECTION: ::c_int = 19; -pub const _SC_MESSAGE_PASSING: ::c_int = 20; -pub const _SC_SEMAPHORES: ::c_int = 21; -pub const _SC_SHARED_MEMORY_OBJECTS: ::c_int = 22; -pub const _SC_AIO_LISTIO_MAX: ::c_int = 23; -pub const _SC_AIO_MAX: ::c_int = 24; -pub const _SC_AIO_PRIO_DELTA_MAX: ::c_int = 25; -pub const _SC_DELAYTIMER_MAX: ::c_int = 26; -pub const _SC_MQ_OPEN_MAX: ::c_int = 27; -pub const _SC_MQ_PRIO_MAX: ::c_int = 28; -pub const _SC_VERSION: ::c_int = 29; -pub const _SC_PAGESIZE: ::c_int = 30; -pub const _SC_RTSIG_MAX: ::c_int = 31; -pub const _SC_SEM_NSEMS_MAX: ::c_int = 32; -pub const _SC_SEM_VALUE_MAX: ::c_int = 33; -pub const _SC_SIGQUEUE_MAX: ::c_int = 34; -pub const _SC_TIMER_MAX: ::c_int = 35; -pub const _SC_BC_BASE_MAX: ::c_int = 36; -pub const _SC_BC_DIM_MAX: ::c_int = 37; -pub const _SC_BC_SCALE_MAX: ::c_int = 38; -pub const _SC_BC_STRING_MAX: ::c_int = 39; -pub const _SC_COLL_WEIGHTS_MAX: ::c_int = 40; -pub const _SC_EXPR_NEST_MAX: ::c_int = 42; -pub const _SC_LINE_MAX: ::c_int = 43; -pub const _SC_RE_DUP_MAX: ::c_int = 44; -pub const _SC_2_VERSION: ::c_int = 46; -pub const _SC_2_C_BIND: ::c_int = 47; -pub const _SC_2_C_DEV: ::c_int = 48; -pub const _SC_2_FORT_DEV: ::c_int = 49; -pub const _SC_2_FORT_RUN: ::c_int = 50; -pub const _SC_2_SW_DEV: ::c_int = 51; -pub const _SC_2_LOCALEDEF: ::c_int = 52; -pub const _SC_IOV_MAX: ::c_int = 60; -pub const _SC_THREADS: ::c_int = 67; -pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 68; -pub const _SC_GETGR_R_SIZE_MAX: ::c_int = 69; -pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 70; -pub const _SC_LOGIN_NAME_MAX: ::c_int = 71; -pub const _SC_TTY_NAME_MAX: ::c_int = 72; -pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: ::c_int = 73; -pub const _SC_THREAD_KEYS_MAX: ::c_int = 74; -pub const _SC_THREAD_STACK_MIN: ::c_int = 75; -pub const _SC_THREAD_THREADS_MAX: ::c_int = 76; -pub const _SC_THREAD_ATTR_STACKADDR: ::c_int = 77; -pub const _SC_THREAD_ATTR_STACKSIZE: ::c_int = 78; -pub const _SC_THREAD_PRIORITY_SCHEDULING: ::c_int = 79; -pub const _SC_THREAD_PRIO_INHERIT: ::c_int = 80; -pub const _SC_THREAD_PRIO_PROTECT: ::c_int = 81; -pub const _SC_NPROCESSORS_ONLN: ::c_int = 84; -pub const _SC_ATEXIT_MAX: ::c_int = 87; -pub const _SC_XOPEN_VERSION: ::c_int = 89; -pub const _SC_XOPEN_XCU_VERSION: ::c_int = 90; -pub const _SC_XOPEN_UNIX: ::c_int = 91; -pub const _SC_XOPEN_CRYPT: ::c_int = 92; -pub const _SC_XOPEN_ENH_I18N: ::c_int = 93; -pub const _SC_XOPEN_SHM: ::c_int = 94; -pub const _SC_2_CHAR_TERM: ::c_int = 95; -pub const _SC_2_C_VERSION: ::c_int = 96; -pub const _SC_2_UPE: ::c_int = 97; -pub const _SC_XBS5_ILP32_OFF32: ::c_int = 125; -pub const _SC_XBS5_ILP32_OFFBIG: ::c_int = 126; -pub const _SC_XBS5_LPBIG_OFFBIG: ::c_int = 128; -pub const _SC_XOPEN_LEGACY: ::c_int = 129; -pub const _SC_XOPEN_REALTIME: ::c_int = 130; -pub const _SC_XOPEN_REALTIME_THREADS: ::c_int = 131; - -pub const RLIM_SAVED_MAX: ::rlim_t = ::RLIM_INFINITY; -pub const RLIM_SAVED_CUR: ::rlim_t = ::RLIM_INFINITY; - -#[cfg(not(target_env = "musl"))] -pub const RUSAGE_THREAD: ::c_int = 1; - -pub const GLOB_ERR: ::c_int = 1 << 0; -pub const GLOB_MARK: ::c_int = 1 << 1; -pub const GLOB_NOSORT: ::c_int = 1 << 2; -pub const GLOB_DOOFFS: ::c_int = 1 << 3; -pub const GLOB_NOCHECK: ::c_int = 1 << 4; -pub const GLOB_APPEND: ::c_int = 1 << 5; -pub const GLOB_NOESCAPE: ::c_int = 1 << 6; - -pub const GLOB_NOSPACE: ::c_int = 1; -pub const GLOB_ABORTED: ::c_int = 2; -pub const GLOB_NOMATCH: ::c_int = 3; - -pub const POSIX_MADV_NORMAL: ::c_int = 0; -pub const POSIX_MADV_RANDOM: ::c_int = 1; -pub const POSIX_MADV_SEQUENTIAL: ::c_int = 2; -pub const POSIX_MADV_WILLNEED: ::c_int = 3; -pub const POSIX_MADV_DONTNEED: ::c_int = 4; - -pub const S_IEXEC: ::mode_t = 64; -pub const S_IWRITE: ::mode_t = 128; -pub const S_IREAD: ::mode_t = 256; - -pub const F_LOCK: ::c_int = 1; -pub const F_TEST: ::c_int = 3; -pub const F_TLOCK: ::c_int = 2; -pub const F_ULOCK: ::c_int = 0; - -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -pub const MAP_32BIT: ::c_int = 0x0040; - -pub const TCP_MD5SIG: ::c_int = 14; - -cfg_if! { - if #[cfg(any(target_arch = "arm", target_arch = "x86", - target_arch = "x86_64"))] { - pub const PTHREAD_STACK_MIN: ::size_t = 16384; - } else { - pub const PTHREAD_STACK_MIN: ::size_t = 131072; - } -} - -cfg_if! { - if #[cfg(any(target_arch = "mips", target_arch = "mipsel"))] { - mod mips; - pub use self::mips::*; - } else { - mod other; - pub use self::other::*; - } -} diff --git a/src/unix/android.rs b/src/unix/android.rs deleted file mode 100644 index 41e69718..00000000 --- a/src/unix/android.rs +++ /dev/null @@ -1,25 +0,0 @@ -//! Android versions of standard Unix functions - -extern { - pub fn madvise(addr: *const ::c_void, len: ::size_t, advice: ::c_int) - -> ::c_int; - pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; - pub fn putenv(string: *const ::c_char) -> ::c_int; - pub fn readlink(path: *const ::c_char, - buf: *mut ::c_char, - bufsz: ::size_t) - -> ::c_int; - pub fn msync(addr: *const ::c_void, len: ::size_t, - flags: ::c_int) -> ::c_int; - pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int) - -> ::c_int; - pub fn sysconf(name: ::c_int) -> ::c_int; - pub fn usleep(secs: ::c_ulong) -> ::c_int; - pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t, - flags: ::c_uint, addr: *const ::sockaddr, - addrlen: *mut ::socklen_t) -> ::ssize_t; - pub fn send(socket: ::c_int, buf: *const ::c_void, len: ::size_t, - flags: ::c_uint) -> ::ssize_t; - pub fn recv(socket: ::c_int, buf: *mut ::c_void, len: ::size_t, - flags: ::c_uint) -> ::ssize_t; -} diff --git a/src/apple/b32.rs b/src/unix/bsd/apple/b32.rs similarity index 100% rename from src/apple/b32.rs rename to src/unix/bsd/apple/b32.rs diff --git a/src/apple/b64.rs b/src/unix/bsd/apple/b64.rs similarity index 91% rename from src/apple/b64.rs rename to src/unix/bsd/apple/b64.rs index 65e1b9fc..1a79be30 100644 --- a/src/apple/b64.rs +++ b/src/unix/bsd/apple/b64.rs @@ -9,7 +9,7 @@ pub type uintptr_t = u64; s! { pub struct pthread_attr_t { - __sig: ::c_long, + __sig: c_long, __opaque: [::c_char; 56] } } diff --git a/src/apple/mod.rs b/src/unix/bsd/apple/mod.rs similarity index 91% rename from src/apple/mod.rs rename to src/unix/bsd/apple/mod.rs index ba43d988..97e42786 100644 --- a/src/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -61,46 +61,6 @@ s! { __unused8: *mut ::c_void, } - pub struct timeval { - pub tv_sec: time_t, - pub tv_usec: suseconds_t, - } - - pub struct timespec { - pub tv_sec: time_t, - pub tv_nsec: c_long, - } - - pub struct rlimit { - pub rlim_cur: rlim_t, - pub rlim_max: rlim_t, - } - - pub struct rusage { - pub ru_utime: timeval, - pub ru_stime: timeval, - pub ru_maxrss: c_long, - pub ru_ixrss: c_long, - pub ru_idrss: c_long, - pub ru_isrss: c_long, - pub ru_minflt: c_long, - pub ru_majflt: c_long, - pub ru_nswap: c_long, - pub ru_inblock: c_long, - pub ru_oublock: c_long, - pub ru_msgsnd: c_long, - pub ru_msgrcv: c_long, - pub ru_nsignals: c_long, - pub ru_nvcsw: c_long, - pub ru_nivcsw: c_long - } - - pub struct sockaddr { - pub sa_len: u8, - pub sa_family: sa_family_t, - pub sa_data: [u8; 14], - } - pub struct sockaddr_storage { pub ss_len: u8, pub ss_family: sa_family_t, @@ -109,42 +69,6 @@ s! { __ss_pad2: [u8; 112], } - pub struct sockaddr_in { - pub sin_len: u8, - pub sin_family: sa_family_t, - pub sin_port: in_port_t, - pub sin_addr: in_addr, - pub sin_zero: [u8; 8], - } - - pub struct in_addr { - pub s_addr: in_addr_t, - } - - pub struct sockaddr_in6 { - pub sin6_len: u8, - pub sin6_family: sa_family_t, - pub sin6_port: in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: in6_addr, - pub sin6_scope_id: u32, - } - - pub struct in6_addr { - pub s6_addr: [u16; 8], - __align: [u32; 0], - } - - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - - pub struct ipv6_mreq { - pub ipv6mr_multiaddr: in6_addr, - pub ipv6mr_interface: c_uint, - } - pub struct addrinfo { pub ai_flags: c_int, pub ai_family: c_int, @@ -156,12 +80,6 @@ s! { pub ai_next: *mut addrinfo, } - pub struct sockaddr_un { - pub sun_len: u8, - pub sun_family: sa_family_t, - pub sun_path: [c_char; 104] - } - pub struct ifaddrs { pub ifa_next: *mut ifaddrs, pub ifa_name: *mut c_char, @@ -685,7 +603,7 @@ pub const _SC_PASS_MAX: c_int = 131; extern { pub fn _NSGetExecutablePath(buf: *mut c_char, - bufsize: *mut ::uint32_t) -> c_int; + bufsize: *mut uint32_t) -> c_int; } cfg_if! { diff --git a/src/freebsdlike/dragonfly.rs b/src/unix/bsd/freebsdlike/dragonfly.rs similarity index 100% rename from src/freebsdlike/dragonfly.rs rename to src/unix/bsd/freebsdlike/dragonfly.rs diff --git a/src/freebsdlike/freebsd.rs b/src/unix/bsd/freebsdlike/freebsd.rs similarity index 100% rename from src/freebsdlike/freebsd.rs rename to src/unix/bsd/freebsdlike/freebsd.rs diff --git a/src/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs similarity index 88% rename from src/freebsdlike/mod.rs rename to src/unix/bsd/freebsdlike/mod.rs index 8db9316c..4c582c45 100644 --- a/src/freebsdlike/mod.rs +++ b/src/unix/bsd/freebsdlike/mod.rs @@ -25,46 +25,6 @@ s! { __unused8: *mut ::c_void, } - pub struct timeval { - pub tv_sec: ::time_t, - pub tv_usec: ::suseconds_t, - } - - pub struct timespec { - pub tv_sec: ::time_t, - pub tv_nsec: ::c_long, - } - - pub struct rlimit { - pub rlim_cur: ::rlim_t, - pub rlim_max: ::rlim_t, - } - - pub struct rusage { - pub ru_utime: timeval, - pub ru_stime: timeval, - pub ru_maxrss: ::c_long, - pub ru_ixrss: ::c_long, - pub ru_idrss: ::c_long, - pub ru_isrss: ::c_long, - pub ru_minflt: ::c_long, - pub ru_majflt: ::c_long, - pub ru_nswap: ::c_long, - pub ru_inblock: ::c_long, - pub ru_oublock: ::c_long, - pub ru_msgsnd: ::c_long, - pub ru_msgrcv: ::c_long, - pub ru_nsignals: ::c_long, - pub ru_nvcsw: ::c_long, - pub ru_nivcsw: ::c_long - } - - pub struct sockaddr { - pub sa_len: u8, - pub sa_family: sa_family_t, - pub sa_data: [u8; 14], - } - pub struct sockaddr_storage { pub ss_len: u8, pub ss_family: sa_family_t, @@ -73,42 +33,6 @@ s! { __ss_pad2: [u8; 112], } - pub struct sockaddr_in { - pub sin_len: u8, - pub sin_family: sa_family_t, - pub sin_port: in_port_t, - pub sin_addr: in_addr, - pub sin_zero: [u8; 8], - } - - pub struct in_addr { - pub s_addr: in_addr_t, - } - - pub struct sockaddr_in6 { - pub sin6_len: u8, - pub sin6_family: sa_family_t, - pub sin6_port: in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: in6_addr, - pub sin6_scope_id: u32, - } - - pub struct in6_addr { - pub s6_addr: [u16; 8], - __align: [u32; 0], - } - - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - - pub struct ipv6_mreq { - pub ipv6mr_multiaddr: in6_addr, - pub ipv6mr_interface: c_uint, - } - pub struct addrinfo { pub ai_flags: ::c_int, pub ai_family: ::c_int, @@ -116,23 +40,17 @@ s! { pub ai_protocol: ::c_int, pub ai_addrlen: socklen_t, pub ai_canonname: *mut c_char, - pub ai_addr: *mut sockaddr, + pub ai_addr: *mut ::sockaddr, pub ai_next: *mut addrinfo, } - pub struct sockaddr_un { - pub sun_len: u8, - pub sun_family: sa_family_t, - pub sun_path: [c_char; 104] - } - pub struct ifaddrs { pub ifa_next: *mut ifaddrs, pub ifa_name: *mut c_char, pub ifa_flags: c_uint, - pub ifa_addr: *mut sockaddr, - pub ifa_netmask: *mut sockaddr, - pub ifa_dstaddr: *mut sockaddr, + pub ifa_addr: *mut ::sockaddr, + pub ifa_netmask: *mut ::sockaddr, + pub ifa_dstaddr: *mut ::sockaddr, pub ifa_data: *mut ::c_void } } diff --git a/src/freebsdlike/x86.rs b/src/unix/bsd/freebsdlike/x86.rs similarity index 98% rename from src/freebsdlike/x86.rs rename to src/unix/bsd/freebsdlike/x86.rs index 47ab9491..5a80c0d4 100644 --- a/src/freebsdlike/x86.rs +++ b/src/unix/bsd/freebsdlike/x86.rs @@ -59,6 +59,6 @@ s! { pub st_lspare: ::int32_t, pub st_birthtime: ::time_t, pub st_birthtime_nsec: ::c_long, - __unused: ::[u8; 8], + __unused: [u8; 8], } } diff --git a/src/freebsdlike/x86_64.rs b/src/unix/bsd/freebsdlike/x86_64.rs similarity index 100% rename from src/freebsdlike/x86_64.rs rename to src/unix/bsd/freebsdlike/x86_64.rs diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs new file mode 100644 index 00000000..783298c1 --- /dev/null +++ b/src/unix/bsd/mod.rs @@ -0,0 +1,69 @@ +s! { + pub struct sockaddr { + pub sa_len: u8, + pub sa_family: sa_family_t, + pub sa_data: [u8; 14], + } + + pub struct sockaddr_in { + pub sin_len: u8, + pub sin_family: sa_family_t, + pub sin_port: ::in_port_t, + pub sin_addr: ::in_addr, + pub sin_zero: [u8; 8], + } + + pub struct sockaddr_in6 { + pub sin6_len: u8, + pub sin6_family: sa_family_t, + pub sin6_port: ::in_port_t, + pub sin6_flowinfo: u32, + pub sin6_addr: ::in6_addr, + pub sin6_scope_id: u32, + } + + pub struct sockaddr_un { + pub sun_len: u8, + pub sun_family: sa_family_t, + pub sun_path: [c_char; 104] + } +} + +extern { + pub fn shm_open(name: *const c_char, oflag: c_int, ...) -> c_int; + pub fn sysctl(name: *mut c_int, + namelen: c_uint, + oldp: *mut ::c_void, + oldlenp: *mut size_t, + newp: *mut ::c_void, + newlen: size_t) + -> c_int; + pub fn mincore(addr: *const ::c_void, len: size_t, + vec: *mut c_char) -> c_int; + pub fn sysctlbyname(name: *const c_char, + oldp: *mut ::c_void, + oldlenp: *mut size_t, + newp: *mut ::c_void, + newlen: size_t) + -> c_int; + pub fn sysctlnametomib(name: *const c_char, + mibp: *mut c_int, + sizep: *mut size_t) + -> c_int; +} + +cfg_if! { + if #[cfg(any(target_os = "macos", target_os = "ios"))] { + mod apple; + pub use self::apple::*; + } else if #[cfg(any(target_os = "openbsd", target_os = "netbsd", + target_os = "dragonfly"))] { + mod openbsdlike; + pub use self::openbsdlike::*; + } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] { + mod freebsdlike; + pub use self::freebsdlike::*; + } else { + // ... + } +} diff --git a/src/openbsdlike.rs b/src/unix/bsd/openbsdlike/mod.rs similarity index 100% rename from src/openbsdlike.rs rename to src/unix/bsd/openbsdlike/mod.rs diff --git a/src/unix/mod.rs b/src/unix/mod.rs index ed984524..524b9be9 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -5,246 +5,373 @@ s! { pub struct utimbuf { - pub actime: ::time_t, - pub modtime: ::time_t, + pub actime: time_t, + pub modtime: time_t, + } + + pub struct timeval { + pub tv_sec: time_t, + pub tv_usec: suseconds_t, + } + + pub struct timespec { + pub tv_sec: time_t, + pub tv_nsec: c_long, + } + + pub struct rlimit { + pub rlim_cur: rlim_t, + pub rlim_max: rlim_t, + } + + pub struct rusage { + pub ru_utime: timeval, + pub ru_stime: timeval, + pub ru_maxrss: c_long, + pub ru_ixrss: c_long, + pub ru_idrss: c_long, + pub ru_isrss: c_long, + pub ru_minflt: c_long, + pub ru_majflt: c_long, + pub ru_nswap: c_long, + pub ru_inblock: c_long, + pub ru_oublock: c_long, + pub ru_msgsnd: c_long, + pub ru_msgrcv: c_long, + pub ru_nsignals: c_long, + pub ru_nvcsw: c_long, + pub ru_nivcsw: c_long + } + + pub struct in_addr { + pub s_addr: in_addr_t, + } + + pub struct in6_addr { + pub s6_addr: [u16; 8], + __align: [u32; 0], + } + + pub struct ip_mreq { + pub imr_multiaddr: in_addr, + pub imr_interface: in_addr, + } + + pub struct ipv6_mreq { + pub ipv6mr_multiaddr: in6_addr, + pub ipv6mr_interface: c_uint, } } extern { - pub fn socket(domain: ::c_int, ty: ::c_int, protocol: ::c_int) -> ::c_int; + pub fn socket(domain: c_int, ty: c_int, protocol: c_int) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "connect$UNIX2003")] - pub fn connect(socket: ::c_int, address: *const ::sockaddr, - len: ::socklen_t) -> ::c_int; + pub fn connect(socket: c_int, address: *const sockaddr, + len: socklen_t) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "bind$UNIX2003")] - pub fn bind(socket: ::c_int, address: *const ::sockaddr, - address_len: ::socklen_t) -> ::c_int; + pub fn bind(socket: c_int, address: *const sockaddr, + address_len: socklen_t) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "listen$UNIX2003")] - pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int; + pub fn listen(socket: c_int, backlog: c_int) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "accept$UNIX2003")] - pub fn accept(socket: ::c_int, address: *mut ::sockaddr, - address_len: *mut ::socklen_t) -> ::c_int; + pub fn accept(socket: c_int, address: *mut sockaddr, + address_len: *mut socklen_t) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "getpeername$UNIX2003")] - pub fn getpeername(socket: ::c_int, address: *mut ::sockaddr, - address_len: *mut ::socklen_t) -> ::c_int; + pub fn getpeername(socket: c_int, address: *mut sockaddr, + address_len: *mut socklen_t) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "getsockname$UNIX2003")] - pub fn getsockname(socket: ::c_int, address: *mut ::sockaddr, - address_len: *mut ::socklen_t) -> ::c_int; - pub fn setsockopt(socket: ::c_int, level: ::c_int, name: ::c_int, + pub fn getsockname(socket: c_int, address: *mut sockaddr, + address_len: *mut socklen_t) -> c_int; + pub fn setsockopt(socket: c_int, level: c_int, name: c_int, value: *const ::c_void, - option_len: ::socklen_t) -> ::c_int; + option_len: socklen_t) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "sendto$UNIX2003")] - pub fn sendto(socket: ::c_int, buf: *const ::c_void, len: ::size_t, - flags: ::c_int, addr: *const ::sockaddr, - addrlen: ::socklen_t) -> ::ssize_t; - pub fn shutdown(socket: ::c_int, how: ::c_int) -> ::c_int; + pub fn sendto(socket: c_int, buf: *const ::c_void, len: size_t, + flags: c_int, addr: *const sockaddr, + addrlen: socklen_t) -> ssize_t; + pub fn shutdown(socket: c_int, how: c_int) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "chmod$UNIX2003")] - pub fn chmod(path: *const ::c_char, mode: ::mode_t) -> ::c_int; + pub fn chmod(path: *const c_char, mode: mode_t) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "fchmod$UNIX2003")] - pub fn fchmod(fd: ::c_int, mode: ::mode_t) -> ::c_int; + pub fn fchmod(fd: c_int, mode: mode_t) -> c_int; #[cfg_attr(target_os = "macos", link_name = "fstat$INODE64")] - pub fn fstat(fildes: ::c_int, buf: *mut ::stat) -> ::c_int; + pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int; - pub fn mkdir(path: *const ::c_char, mode: ::mode_t) -> ::c_int; + pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int; #[cfg_attr(target_os = "macos", link_name = "stat$INODE64")] - pub fn stat(path: *const ::c_char, buf: *mut ::stat) -> ::c_int; + pub fn stat(path: *const c_char, buf: *mut stat) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "popen$UNIX2003")] - pub fn popen(command: *const ::c_char, - mode: *const ::c_char) -> *mut ::FILE; - pub fn pclose(stream: *mut ::FILE) -> ::c_int; + pub fn popen(command: *const c_char, + mode: *const c_char) -> *mut ::FILE; + pub fn pclose(stream: *mut ::FILE) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "fdopen$UNIX2003")] - pub fn fdopen(fd: ::c_int, mode: *const ::c_char) -> *mut ::FILE; - pub fn fileno(stream: *mut ::FILE) -> ::c_int; + pub fn fdopen(fd: c_int, mode: *const c_char) -> *mut ::FILE; + pub fn fileno(stream: *mut ::FILE) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "open$UNIX2003")] - pub fn open(path: *const ::c_char, oflag: ::c_int, ...) -> ::c_int; + pub fn open(path: *const c_char, oflag: c_int, ...) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "creat$UNIX2003")] - pub fn creat(path: *const ::c_char, mode: ::mode_t) -> ::c_int; + pub fn creat(path: *const c_char, mode: mode_t) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "fcntl$UNIX2003")] - pub fn fcntl(fd: ::c_int, cmd: ::c_int, ...) -> ::c_int; + pub fn fcntl(fd: c_int, cmd: c_int, ...) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), link_name = "opendir$INODE64")] #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "opendir$INODE64$UNIX2003")] - pub fn opendir(dirname: *const ::c_char) -> *mut ::DIR; + pub fn opendir(dirname: *const c_char) -> *mut ::DIR; #[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")] pub fn readdir_r(dirp: *mut ::DIR, entry: *mut ::dirent, - result: *mut *mut ::dirent) -> ::c_int; + result: *mut *mut ::dirent) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "closedir$UNIX2003")] - pub fn closedir(dirp: *mut ::DIR) -> ::c_int; + pub fn closedir(dirp: *mut ::DIR) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), link_name = "rewinddir$INODE64")] #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "rewinddir$INODE64$UNIX2003")] pub fn rewinddir(dirp: *mut ::DIR); - pub fn access(path: *const ::c_char, amode: ::c_int) -> ::c_int; - pub fn alarm(seconds: ::c_uint) -> ::c_uint; - pub fn chdir(dir: *const ::c_char) -> ::c_int; - pub fn chown(path: *const ::c_char, uid: ::uid_t, - gid: ::gid_t) -> ::c_int; + pub fn access(path: *const c_char, amode: c_int) -> c_int; + pub fn alarm(seconds: c_uint) -> c_uint; + pub fn chdir(dir: *const c_char) -> c_int; + pub fn chown(path: *const c_char, uid: uid_t, + gid: gid_t) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "close$UNIX2003")] - pub fn close(fd: ::c_int) -> ::c_int; - pub fn dup(fd: ::c_int) -> ::c_int; - pub fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int; - pub fn execv(prog: *const ::c_char, - argv: *const *const ::c_char) -> ::c_int; - pub fn execve(prog: *const ::c_char, argv: *const *const ::c_char, - envp: *const *const ::c_char) - -> ::c_int; - pub fn execvp(c: *const ::c_char, - argv: *const *const ::c_char) -> ::c_int; - pub fn fork() -> ::pid_t; - pub fn fpathconf(filedes: ::c_int, name: ::c_int) -> ::c_long; - pub fn getcwd(buf: *mut ::c_char, size: ::size_t) -> *mut ::c_char; - pub fn getegid() -> ::gid_t; - pub fn geteuid() -> ::uid_t; - pub fn getgid() -> ::gid_t; - pub fn getgroups(ngroups_max: ::c_int, groups: *mut ::gid_t) - -> ::c_int; - pub fn getlogin() -> *mut ::c_char; + pub fn close(fd: c_int) -> c_int; + pub fn dup(fd: c_int) -> c_int; + pub fn dup2(src: c_int, dst: c_int) -> c_int; + pub fn execv(prog: *const c_char, + argv: *const *const c_char) -> c_int; + pub fn execve(prog: *const c_char, argv: *const *const c_char, + envp: *const *const c_char) + -> c_int; + pub fn execvp(c: *const c_char, + argv: *const *const c_char) -> c_int; + pub fn fork() -> pid_t; + pub fn fpathconf(filedes: c_int, name: c_int) -> c_long; + pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char; + pub fn getegid() -> gid_t; + pub fn geteuid() -> uid_t; + pub fn getgid() -> gid_t; + pub fn getgroups(ngroups_max: c_int, groups: *mut gid_t) + -> c_int; + pub fn getlogin() -> *mut c_char; // GNU getopt(3) modifies its arguments despite the // char * const [] prototype; see the manpage. - pub fn getopt(argc: ::c_int, argv: *mut *mut ::c_char, - optstr: *const ::c_char) -> ::c_int; - pub fn getpgrp() -> ::pid_t; - pub fn getpid() -> ::pid_t; - pub fn getppid() -> ::pid_t; - pub fn getuid() -> ::uid_t; - pub fn isatty(fd: ::c_int) -> ::c_int; - pub fn link(src: *const ::c_char, dst: *const ::c_char) -> ::c_int; - pub fn lseek(fd: ::c_int, offset: ::off_t, whence: ::c_int) - -> ::off_t; - pub fn pathconf(path: *const ::c_char, name: ::c_int) -> ::c_long; + pub fn getopt(argc: c_int, argv: *mut *mut c_char, + optstr: *const c_char) -> c_int; + pub fn getpgrp() -> pid_t; + pub fn getpid() -> pid_t; + pub fn getppid() -> pid_t; + pub fn getuid() -> uid_t; + pub fn isatty(fd: c_int) -> c_int; + pub fn link(src: *const c_char, dst: *const c_char) -> c_int; + pub fn lseek(fd: c_int, offset: off_t, whence: c_int) + -> off_t; + pub fn pathconf(path: *const c_char, name: c_int) -> c_long; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "pause$UNIX2003")] - pub fn pause() -> ::c_int; - pub fn pipe(fds: *mut ::c_int) -> ::c_int; + pub fn pause() -> c_int; + pub fn pipe(fds: *mut c_int) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "read$UNIX2003")] - pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::size_t) - -> ::ssize_t; - pub fn rmdir(path: *const ::c_char) -> ::c_int; - pub fn setgid(gid: ::gid_t) -> ::c_int; - pub fn setpgid(pid: ::pid_t, pgid: ::pid_t) -> ::c_int; - pub fn setsid() -> ::pid_t; - pub fn setuid(uid: ::uid_t) -> ::c_int; + pub fn read(fd: c_int, buf: *mut ::c_void, count: size_t) + -> ssize_t; + pub fn rmdir(path: *const c_char) -> c_int; + pub fn setgid(gid: gid_t) -> c_int; + pub fn setpgid(pid: pid_t, pgid: pid_t) -> c_int; + pub fn setsid() -> pid_t; + pub fn setuid(uid: uid_t) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "sleep$UNIX2003")] - pub fn sleep(secs: ::c_uint) -> ::c_uint; + pub fn sleep(secs: c_uint) -> c_uint; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "nanosleep$UNIX2003")] - pub fn nanosleep(rqtp: *const ::timespec, - rmtp: *mut ::timespec) -> ::c_int; - pub fn tcgetpgrp(fd: ::c_int) -> ::pid_t; - pub fn ttyname(fd: ::c_int) -> *mut ::c_char; - pub fn unlink(c: *const ::c_char) -> ::c_int; + pub fn nanosleep(rqtp: *const timespec, + rmtp: *mut timespec) -> c_int; + pub fn tcgetpgrp(fd: c_int) -> pid_t; + pub fn ttyname(fd: c_int) -> *mut c_char; + pub fn unlink(c: *const c_char) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "wait$UNIX2003")] - pub fn wait(status: *mut ::c_int) -> ::pid_t; + pub fn wait(status: *mut c_int) -> pid_t; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "waitpid$UNIX2003")] - pub fn waitpid(pid: ::pid_t, status: *mut ::c_int, options: ::c_int) - -> ::pid_t; + pub fn waitpid(pid: pid_t, status: *mut c_int, options: c_int) + -> pid_t; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "write$UNIX2003")] - pub fn write(fd: ::c_int, buf: *const ::c_void, count: ::size_t) - -> ::ssize_t; + pub fn write(fd: c_int, buf: *const ::c_void, count: size_t) + -> ssize_t; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "pread$UNIX2003")] - pub fn pread(fd: ::c_int, buf: *mut ::c_void, count: ::size_t, - offset: ::off_t) -> ::ssize_t; + pub fn pread(fd: c_int, buf: *mut ::c_void, count: size_t, + offset: off_t) -> ssize_t; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "pwrite$UNIX2003")] - pub fn pwrite(fd: ::c_int, buf: *const ::c_void, count: ::size_t, - offset: ::off_t) -> ::ssize_t; - pub fn utime(file: *const ::c_char, buf: *const ::utimbuf) -> ::c_int; + pub fn pwrite(fd: c_int, buf: *const ::c_void, count: size_t, + offset: off_t) -> ssize_t; + pub fn utime(file: *const c_char, buf: *const utimbuf) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "kill$UNIX2003")] - pub fn kill(pid: ::pid_t, sig: ::c_int) -> ::c_int; + pub fn kill(pid: pid_t, sig: c_int) -> c_int; - pub fn mlock(addr: *const ::c_void, len: ::size_t) -> ::c_int; - pub fn munlock(addr: *const ::c_void, len: ::size_t) -> ::c_int; - pub fn mlockall(flags: ::c_int) -> ::c_int; - pub fn munlockall() -> ::c_int; + pub fn mlock(addr: *const ::c_void, len: size_t) -> c_int; + pub fn munlock(addr: *const ::c_void, len: size_t) -> c_int; + pub fn mlockall(flags: c_int) -> c_int; + pub fn munlockall() -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "mmap$UNIX2003")] pub fn mmap(addr: *mut ::c_void, - len: ::size_t, - prot: ::c_int, - flags: ::c_int, - fd: ::c_int, - offset: ::off_t) + len: size_t, + prot: c_int, + flags: c_int, + fd: c_int, + offset: off_t) -> *mut ::c_void; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "munmap$UNIX2003")] - pub fn munmap(addr: *mut ::c_void, len: ::size_t) -> ::c_int; + pub fn munmap(addr: *mut ::c_void, len: size_t) -> c_int; - pub fn if_nametoindex(ifname: *const ::c_char) -> ::c_uint; + pub fn if_nametoindex(ifname: *const c_char) -> c_uint; #[cfg_attr(target_os = "macos", link_name = "lstat$INODE64")] - pub fn lstat(path: *const ::c_char, buf: *mut ::stat) -> ::c_int; + pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "fsync$UNIX2003")] - pub fn fsync(fd: ::c_int) -> ::c_int; + pub fn fsync(fd: c_int) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "setenv$UNIX2003")] - pub fn setenv(name: *const ::c_char, val: *const ::c_char, - overwrite: ::c_int) -> ::c_int; + pub fn setenv(name: *const c_char, val: *const c_char, + overwrite: c_int) -> c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "unsetenv$UNIX2003")] - pub fn unsetenv(name: *const ::c_char) -> ::c_int; + pub fn unsetenv(name: *const c_char) -> c_int; - pub fn symlink(path1: *const ::c_char, - path2: *const ::c_char) -> ::c_int; + pub fn symlink(path1: *const c_char, + path2: *const c_char) -> c_int; - pub fn ftruncate(fd: ::c_int, length: ::off_t) -> ::c_int; + pub fn ftruncate(fd: c_int, length: off_t) -> c_int; - pub fn signal(signum: ::c_int, - handler: ::sighandler_t) -> ::sighandler_t; + pub fn signal(signum: c_int, + handler: sighandler_t) -> sighandler_t; - pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int; - pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int; - pub fn getrusage(resource: ::c_int, usage: *mut ::rusage) -> ::c_int; + pub fn getrlimit(resource: c_int, rlim: *mut rlimit) -> c_int; + pub fn setrlimit(resource: c_int, rlim: *const rlimit) -> c_int; + pub fn getrusage(resource: c_int, usage: *mut rusage) -> c_int; - pub fn getdtablesize() -> ::c_int; + pub fn getdtablesize() -> c_int; #[cfg_attr(target_os = "macos", link_name = "realpath$DARWIN_EXTSN")] - pub fn realpath(pathname: *const ::c_char, resolved: *mut ::c_char) - -> *mut ::c_char; + pub fn realpath(pathname: *const c_char, resolved: *mut c_char) + -> *mut c_char; + + pub fn flock(fd: c_int, operation: c_int) -> c_int; +} - pub fn flock(fd: ::c_int, operation: ::c_int) -> ::c_int; +#[cfg(not(target_os = "android"))] +extern { + pub fn getifaddrs(ifap: *mut *mut ifaddrs) -> c_int; + pub fn freeifaddrs(ifa: *mut ifaddrs); + pub fn glob(pattern: *const c_char, + flags: c_int, + errfunc: Option<extern "C" fn(epath: *const c_char, + errno: c_int) -> c_int>, + pglob: *mut glob_t); + pub fn globfree(pglob: *mut glob_t); + + pub fn posix_madvise(addr: *mut ::c_void, len: size_t, advice: c_int) + -> c_int; + + pub fn shm_unlink(name: *const c_char) -> c_int; + + #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), + link_name = "seekdir$INODE64")] + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "seekdir$INODE64$UNIX2003")] + pub fn seekdir(dirp: *mut ::DIR, loc: c_long); + + #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), + link_name = "telldir$INODE64")] + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "telldir$INODE64$UNIX2003")] + pub fn telldir(dirp: *mut ::DIR) -> c_long; + + pub fn getsid(pid: pid_t) -> pid_t; + pub fn madvise(addr: *mut ::c_void, len: size_t, advice: c_int) + -> c_int; + pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int; + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "putenv$UNIX2003")] + pub fn putenv(string: *mut c_char) -> c_int; + pub fn readlink(path: *const c_char, + buf: *mut c_char, + bufsz: size_t) + -> ssize_t; + + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "msync$UNIX2003")] + pub fn msync(addr: *mut ::c_void, len: size_t, flags: c_int) -> c_int; + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "mprotect$UNIX2003")] + pub fn mprotect(addr: *mut ::c_void, len: size_t, prot: c_int) + -> c_int; + pub fn sysconf(name: c_int) -> c_long; + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "usleep$UNIX2003")] + pub fn usleep(secs: c_uint) -> c_int; + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "recvfrom$UNIX2003")] + pub fn recvfrom(socket: c_int, buf: *mut ::c_void, len: size_t, + flags: c_int, addr: *mut sockaddr, + addrlen: *mut socklen_t) -> ssize_t; + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "send$UNIX2003")] + pub fn send(socket: c_int, buf: *const ::c_void, len: size_t, + flags: c_int) -> ssize_t; + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "recv$UNIX2003")] + pub fn recv(socket: c_int, buf: *mut ::c_void, len: size_t, + flags: c_int) -> ssize_t; + pub fn mkfifo(path: *const c_char, mode: mode_t) -> c_int; } cfg_if! { - if #[cfg(target_os = "android")] { - mod android; - pub use self::android::*; + if #[cfg(any(target_os = "linux", target_os = "android"))] { + mod notbsd; + pub use self::notbsd::*; + } else if #[cfg(any(target_os = "macos", + target_os = "freebsd", + target_os = "dragonfly", + target_os = "openbsd", + target_os = "netbsd", + target_os = "bitrig"))] { + mod bsd; + pub use self::bsd::*; } else { - mod other; - pub use self::other::*; + // ... } } diff --git a/src/unix/notbsd/android.rs b/src/unix/notbsd/android.rs new file mode 100644 index 00000000..78c3f14c --- /dev/null +++ b/src/unix/notbsd/android.rs @@ -0,0 +1,162 @@ +//! Android-specific definitions for linux-like values + +pub type c_char = i8; +pub type c_schar = i8; +pub type c_uchar = u8; +pub type c_short = i16; +pub type c_ushort = u16; +pub type c_int = i32; +pub type c_uint = u32; +pub type c_long = i32; +pub type c_ulong = u32; +pub type c_float = f32; +pub type c_double = f64; +pub type size_t = u32; +pub type ptrdiff_t = i32; +pub type clock_t = i32; +pub type time_t = i32; +pub type suseconds_t = i32; +pub type wchar_t = i32; +pub type c_longlong = i64; +pub type c_ulonglong = u64; +pub type intptr_t = i32; +pub type uintptr_t = u32; +pub type intmax_t = i64; +pub type uintmax_t = u64; +pub type off_t = i32; +pub type ino_t = u32; +pub type pid_t = i32; +pub type uid_t = u32; +pub type gid_t = u32; +pub type useconds_t = u32; +pub type ssize_t = i32; +pub type blkcnt_t = u32; +pub type blksize_t = u32; +pub type dev_t = u32; +pub type mode_t = u16; +pub type nlink_t = u16; + +s! { + pub struct stat { + pub st_dev: ::c_ulonglong, + __pad0: [::c_uchar; 4], + __st_ino: ::ino_t, + pub st_mode: ::c_uint, + pub st_nlink: ::c_uint, + pub st_uid: ::uid_t, + pub st_gid: ::gid_t, + pub st_rdev: ::c_ulonglong, + __pad3: [::c_uchar; 4], + pub st_size: ::c_longlong, + pub st_blksize: blksize_t, + pub st_blocks: ::c_ulonglong, + pub st_atime: ::time_t, + pub st_atime_nsec: ::c_ulong, + pub st_mtime: ::time_t, + pub st_mtime_nsec: ::c_ulong, + pub st_ctime: ::time_t, + pub st_ctime_nsec: ::c_ulong, + pub st_ino: ::c_ulonglong, + } + + pub struct pthread_attr_t { + pub flags: ::uint32_t, + pub stack_base: *mut ::c_void, + pub stack_size: ::size_t, + pub guard_size: ::size_t, + pub sched_policy: ::int32_t, + pub sched_priority: ::int32_t, + } +} + +pub const BUFSIZ: ::c_uint = 1024; +pub const FILENAME_MAX: ::c_uint = 1024; +pub const FOPEN_MAX: ::c_uint = 20; +pub const L_tmpnam: ::c_uint = 1024; +pub const TMP_MAX: ::c_uint = 308915776; +pub const _PC_NAME_MAX: ::c_int = 4; + +pub const _SC_ARG_MAX: ::c_int = 0; +pub const _SC_BC_BASE_MAX: ::c_int = 1; +pub const _SC_BC_DIM_MAX: ::c_int = 2; +pub const _SC_BC_SCALE_MAX: ::c_int = 3; +pub const _SC_BC_STRING_MAX: ::c_int = 4; +pub const _SC_CHILD_MAX: ::c_int = 5; +pub const _SC_CLK_TCK: ::c_int = 6; +pub const _SC_COLL_WEIGHTS_MAX: ::c_int = 7; +pub const _SC_EXPR_NEST_MAX: ::c_int = 8; +pub const _SC_LINE_MAX: ::c_int = 9; +pub const _SC_NGROUPS_MAX: ::c_int = 10; +pub const _SC_OPEN_MAX: ::c_int = 11; +pub const _SC_2_C_BIND: ::c_int = 13; +pub const _SC_2_C_DEV: ::c_int = 14; +pub const _SC_2_C_VERSION: ::c_int = 15; +pub const _SC_2_CHAR_TERM: ::c_int = 16; +pub const _SC_2_FORT_DEV: ::c_int = 17; +pub const _SC_2_FORT_RUN: ::c_int = 18; +pub const _SC_2_LOCALEDEF: ::c_int = 19; +pub const _SC_2_SW_DEV: ::c_int = 20; +pub const _SC_2_UPE: ::c_int = 21; +pub const _SC_2_VERSION: ::c_int = 22; +pub const _SC_JOB_CONTROL: ::c_int = 23; +pub const _SC_SAVED_IDS: ::c_int = 24; +pub const _SC_VERSION: ::c_int = 25; +pub const _SC_RE_DUP_MAX: ::c_int = 26; +pub const _SC_STREAM_MAX: ::c_int = 27; +pub const _SC_TZNAME_MAX: ::c_int = 28; +pub const _SC_XOPEN_CRYPT: ::c_int = 29; +pub const _SC_XOPEN_ENH_I18N: ::c_int = 30; +pub const _SC_XOPEN_SHM: ::c_int = 31; +pub const _SC_XOPEN_VERSION: ::c_int = 32; +pub const _SC_XOPEN_XCU_VERSION: ::c_int = 33; +pub const _SC_XOPEN_REALTIME: ::c_int = 34; +pub const _SC_XOPEN_REALTIME_THREADS: ::c_int = 35; +pub const _SC_XOPEN_LEGACY: ::c_int = 36; +pub const _SC_ATEXIT_MAX: ::c_int = 37; +pub const _SC_IOV_MAX: ::c_int = 38; +pub const _SC_PAGESIZE: ::c_int = 39; +pub const _SC_XOPEN_UNIX: ::c_int = 41; +pub const _SC_MQ_PRIO_MAX: ::c_int = 51; +pub const _SC_GETGR_R_SIZE_MAX: ::c_int = 71; +pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 72; +pub const _SC_LOGIN_NAME_MAX: ::c_int = 73; +pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: ::c_int = 74; +pub const _SC_THREAD_KEYS_MAX: ::c_int = 75; +pub const _SC_THREAD_STACK_MIN: ::c_int = 76; +pub const _SC_THREAD_THREADS_MAX: ::c_int = 77; +pub const _SC_TTY_NAME_MAX: ::c_int = 78; +pub const _SC_THREADS: ::c_int = 79; +pub const _SC_THREAD_ATTR_STACKADDR: ::c_int = 80; +pub const _SC_THREAD_ATTR_STACKSIZE: ::c_int = 81; +pub const _SC_THREAD_PRIORITY_SCHEDULING: ::c_int = 82; +pub const _SC_THREAD_PRIO_INHERIT: ::c_int = 83; +pub const _SC_THREAD_PRIO_PROTECT: ::c_int = 84; +pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 85; + +pub const PTHREAD_STACK_MIN: ::size_t = 8192; + +pub const O_SYNC: ::c_int = 0x1000; + +extern { + pub fn madvise(addr: *const ::c_void, len: ::size_t, advice: ::c_int) + -> ::c_int; + pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; + pub fn putenv(string: *const ::c_char) -> ::c_int; + pub fn readlink(path: *const ::c_char, + buf: *mut ::c_char, + bufsz: ::size_t) + -> ::c_int; + pub fn msync(addr: *const ::c_void, len: ::size_t, + flags: ::c_int) -> ::c_int; + pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int) + -> ::c_int; + pub fn sysconf(name: ::c_int) -> ::c_int; + pub fn usleep(secs: ::c_ulong) -> ::c_int; + pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t, + flags: ::c_uint, addr: *const ::sockaddr, + addrlen: *mut ::socklen_t) -> ::ssize_t; + pub fn send(socket: ::c_int, buf: *const ::c_void, len: ::size_t, + flags: ::c_uint) -> ::ssize_t; + pub fn recv(socket: ::c_int, buf: *mut ::c_void, len: ::size_t, + flags: ::c_uint) -> ::ssize_t; +} diff --git a/src/linuxlike/linux/mips.rs b/src/unix/notbsd/linux/mips.rs similarity index 73% rename from src/linuxlike/linux/mips.rs rename to src/unix/notbsd/linux/mips.rs index 1889fe9c..83ee1da0 100644 --- a/src/linuxlike/linux/mips.rs +++ b/src/unix/notbsd/linux/mips.rs @@ -1,3 +1,68 @@ +pub type c_char = i8; +pub type c_schar = i8; +pub type c_uchar = u8; +pub type c_short = i16; +pub type c_ushort = u16; +pub type c_int = i32; +pub type c_uint = u32; +pub type c_long = i32; +pub type c_ulong = u32; +pub type c_float = f32; +pub type c_double = f64; +pub type size_t = u32; +pub type ptrdiff_t = i32; +pub type clock_t = i32; +pub type time_t = i32; +pub type suseconds_t = i32; +pub type wchar_t = i32; +pub type c_longlong = i64; +pub type c_ulonglong = u64; +pub type intptr_t = i32; +pub type uintptr_t = u32; +pub type intmax_t = i64; +pub type uintmax_t = u64; +pub type off_t = i32; +pub type ino_t = u32; +pub type pid_t = i32; +pub type uid_t = u32; +pub type gid_t = u32; +pub type useconds_t = u32; +pub type ssize_t = i32; +pub type blkcnt_t = i32; +pub type blksize_t = i32; +pub type dev_t = u64; +pub type mode_t = u32; +pub type nlink_t = u32; + +s! { + pub struct stat { + pub st_dev: ::c_ulong, + pub st_pad1: [::c_long; 3], + 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: ::c_ulong, + pub st_pad2: [::c_long; 2], + pub st_size: ::off_t, + pub st_pad3: ::c_long, + pub st_atime: ::time_t, + pub st_atime_nsec: ::c_long, + pub st_mtime: ::time_t, + pub st_mtime_nsec: ::c_long, + pub st_ctime: ::time_t, + pub st_ctime_nsec: ::c_long, + pub st_blksize: ::blksize_t, + pub st_blocks: ::blkcnt_t, + pub st_pad5: [::c_long; 14], + } + + pub struct pthread_attr_t { + __size: [u32; 9] + } +} + pub const RLIMIT_NOFILE: ::c_int = 5; pub const RLIMIT_AS: ::c_int = 6; pub const RLIMIT_RSS: ::c_int = 7; diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs new file mode 100644 index 00000000..049fd8e9 --- /dev/null +++ b/src/unix/notbsd/linux/mod.rs @@ -0,0 +1,188 @@ +//! Linux-specific definitions for linux-like values + +s! { + pub struct glob_t { + pub gl_pathc: size_t, + pub gl_pathv: *mut *mut c_char, + pub gl_offs: size_t, + pub gl_flags: c_int, + + __unused1: *mut ::c_void, + __unused2: *mut ::c_void, + __unused3: *mut ::c_void, + __unused4: *mut ::c_void, + __unused5: *mut ::c_void, + } + + pub struct ifaddrs { + pub ifa_next: *mut ifaddrs, + pub ifa_name: *mut c_char, + pub ifa_flags: c_uint, + pub ifa_addr: *mut ::sockaddr, + pub ifa_netmask: *mut ::sockaddr, + pub ifa_ifu: *mut ::sockaddr, // FIXME This should be a union + pub ifa_data: *mut ::c_void + } +} + +pub const BUFSIZ: c_uint = 8192; +pub const FILENAME_MAX: c_uint = 4096; +pub const FOPEN_MAX: c_uint = 16; +pub const L_tmpnam: c_uint = 20; +pub const TMP_MAX: c_uint = 238328; +pub const _PC_NAME_MAX: c_int = 3; + +pub const _SC_ARG_MAX: c_int = 0; +pub const _SC_CHILD_MAX: c_int = 1; +pub const _SC_CLK_TCK: c_int = 2; +pub const _SC_NGROUPS_MAX: c_int = 3; +pub const _SC_OPEN_MAX: c_int = 4; +pub const _SC_STREAM_MAX: c_int = 5; +pub const _SC_TZNAME_MAX: c_int = 6; +pub const _SC_JOB_CONTROL: c_int = 7; +pub const _SC_SAVED_IDS: c_int = 8; +pub const _SC_REALTIME_SIGNALS: c_int = 9; +pub const _SC_PRIORITY_SCHEDULING: c_int = 10; +pub const _SC_TIMERS: c_int = 11; +pub const _SC_ASYNCHRONOUS_IO: c_int = 12; +pub const _SC_PRIORITIZED_IO: c_int = 13; +pub const _SC_SYNCHRONIZED_IO: c_int = 14; +pub const _SC_FSYNC: c_int = 15; +pub const _SC_MAPPED_FILES: c_int = 16; +pub const _SC_MEMLOCK: c_int = 17; +pub const _SC_MEMLOCK_RANGE: c_int = 18; +pub const _SC_MEMORY_PROTECTION: c_int = 19; +pub const _SC_MESSAGE_PASSING: c_int = 20; +pub const _SC_SEMAPHORES: c_int = 21; +pub const _SC_SHARED_MEMORY_OBJECTS: c_int = 22; +pub const _SC_AIO_LISTIO_MAX: c_int = 23; +pub const _SC_AIO_MAX: c_int = 24; +pub const _SC_AIO_PRIO_DELTA_MAX: c_int = 25; +pub const _SC_DELAYTIMER_MAX: c_int = 26; +pub const _SC_MQ_OPEN_MAX: c_int = 27; +pub const _SC_MQ_PRIO_MAX: c_int = 28; +pub const _SC_VERSION: c_int = 29; +pub const _SC_PAGESIZE: c_int = 30; +pub const _SC_RTSIG_MAX: c_int = 31; +pub const _SC_SEM_NSEMS_MAX: c_int = 32; +pub const _SC_SEM_VALUE_MAX: c_int = 33; +pub const _SC_SIGQUEUE_MAX: c_int = 34; +pub const _SC_TIMER_MAX: c_int = 35; +pub const _SC_BC_BASE_MAX: c_int = 36; +pub const _SC_BC_DIM_MAX: c_int = 37; +pub const _SC_BC_SCALE_MAX: c_int = 38; +pub const _SC_BC_STRING_MAX: c_int = 39; +pub const _SC_COLL_WEIGHTS_MAX: c_int = 40; +pub const _SC_EXPR_NEST_MAX: c_int = 42; +pub const _SC_LINE_MAX: c_int = 43; +pub const _SC_RE_DUP_MAX: c_int = 44; +pub const _SC_2_VERSION: c_int = 46; +pub const _SC_2_C_BIND: c_int = 47; +pub const _SC_2_C_DEV: c_int = 48; +pub const _SC_2_FORT_DEV: c_int = 49; +pub const _SC_2_FORT_RUN: c_int = 50; +pub const _SC_2_SW_DEV: c_int = 51; +pub const _SC_2_LOCALEDEF: c_int = 52; +pub const _SC_IOV_MAX: c_int = 60; +pub const _SC_THREADS: c_int = 67; +pub const _SC_THREAD_SAFE_FUNCTIONS: c_int = 68; +pub const _SC_GETGR_R_SIZE_MAX: c_int = 69; +pub const _SC_GETPW_R_SIZE_MAX: c_int = 70; +pub const _SC_LOGIN_NAME_MAX: c_int = 71; +pub const _SC_TTY_NAME_MAX: c_int = 72; +pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: c_int = 73; +pub const _SC_THREAD_KEYS_MAX: c_int = 74; +pub const _SC_THREAD_STACK_MIN: c_int = 75; +pub const _SC_THREAD_THREADS_MAX: c_int = 76; +pub const _SC_THREAD_ATTR_STACKADDR: c_int = 77; +pub const _SC_THREAD_ATTR_STACKSIZE: c_int = 78; +pub const _SC_THREAD_PRIORITY_SCHEDULING: c_int = 79; +pub const _SC_THREAD_PRIO_INHERIT: c_int = 80; +pub const _SC_THREAD_PRIO_PROTECT: c_int = 81; +pub const _SC_NPROCESSORS_ONLN: c_int = 84; +pub const _SC_ATEXIT_MAX: c_int = 87; +pub const _SC_XOPEN_VERSION: c_int = 89; +pub const _SC_XOPEN_XCU_VERSION: c_int = 90; +pub const _SC_XOPEN_UNIX: c_int = 91; +pub const _SC_XOPEN_CRYPT: c_int = 92; +pub const _SC_XOPEN_ENH_I18N: c_int = 93; +pub const _SC_XOPEN_SHM: c_int = 94; +pub const _SC_2_CHAR_TERM: c_int = 95; +pub const _SC_2_C_VERSION: c_int = 96; +pub const _SC_2_UPE: c_int = 97; +pub const _SC_XBS5_ILP32_OFF32: c_int = 125; +pub const _SC_XBS5_ILP32_OFFBIG: c_int = 126; +pub const _SC_XBS5_LPBIG_OFFBIG: c_int = 128; +pub const _SC_XOPEN_LEGACY: c_int = 129; +pub const _SC_XOPEN_REALTIME: c_int = 130; +pub const _SC_XOPEN_REALTIME_THREADS: c_int = 131; + +pub const RLIM_SAVED_MAX: ::rlim_t = RLIM_INFINITY; +pub const RLIM_SAVED_CUR: ::rlim_t = RLIM_INFINITY; + +#[cfg(not(target_env = "musl"))] +pub const RUSAGE_THREAD: c_int = 1; + +pub const GLOB_ERR: c_int = 1 << 0; +pub const GLOB_MARK: c_int = 1 << 1; +pub const GLOB_NOSORT: c_int = 1 << 2; +pub const GLOB_DOOFFS: c_int = 1 << 3; +pub const GLOB_NOCHECK: c_int = 1 << 4; +pub const GLOB_APPEND: c_int = 1 << 5; +pub const GLOB_NOESCAPE: c_int = 1 << 6; + +pub const GLOB_NOSPACE: c_int = 1; +pub const GLOB_ABORTED: c_int = 2; +pub const GLOB_NOMATCH: c_int = 3; + +pub const POSIX_MADV_NORMAL: c_int = 0; +pub const POSIX_MADV_RANDOM: c_int = 1; +pub const POSIX_MADV_SEQUENTIAL: c_int = 2; +pub const POSIX_MADV_WILLNEED: c_int = 3; +pub const POSIX_MADV_DONTNEED: c_int = 4; + +pub const S_IEXEC: mode_t = 64; +pub const S_IWRITE: mode_t = 128; +pub const S_IREAD: mode_t = 256; + +pub const F_LOCK: c_int = 1; +pub const F_TEST: c_int = 3; +pub const F_TLOCK: c_int = 2; +pub const F_ULOCK: c_int = 0; + +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +pub const MAP_32BIT: c_int = 0x0040; + +pub const TCP_MD5SIG: c_int = 14; + +extern { + pub fn shm_open(name: *const c_char, oflag: c_int, + mode: mode_t) -> c_int; + #[cfg(not(target_env = "musl"))] + pub fn sysctl(name: *mut c_int, + namelen: c_int, + oldp: *mut ::c_void, + oldlenp: *mut size_t, + newp: *mut ::c_void, + newlen: size_t) + -> c_int; +} + +cfg_if! { + if #[cfg(any(target_arch = "arm", target_arch = "x86", + target_arch = "x86_64"))] { + pub const PTHREAD_STACK_MIN: size_t = 16384; + } else { + pub const PTHREAD_STACK_MIN: size_t = 131072; + } +} + +cfg_if! { + if #[cfg(any(target_arch = "mips", target_arch = "mipsel"))] { + mod mips; + pub use self::mips::*; + } else { + mod notmips; + pub use self::notmips::*; + } +} diff --git a/src/linuxlike/b32/other.rs b/src/unix/notbsd/linux/notmips/b32.rs similarity index 52% rename from src/linuxlike/b32/other.rs rename to src/unix/notbsd/linux/notmips/b32.rs index 02bc4aba..8eb4ef1f 100644 --- a/src/linuxlike/b32/other.rs +++ b/src/unix/notbsd/linux/notmips/b32.rs @@ -1,6 +1,35 @@ -//! 32-bit specific definitions for linux-like values on platforms that aren't -//! MIPS or android +//! 32-bit specific definitions for linux-like values +pub type c_char = i8; +pub type c_schar = i8; +pub type c_uchar = u8; +pub type c_short = i16; +pub type c_ushort = u16; +pub type c_int = i32; +pub type c_uint = u32; +pub type c_long = i32; +pub type c_ulong = u32; +pub type c_float = f32; +pub type c_double = f64; +pub type size_t = u32; +pub type ptrdiff_t = i32; +pub type clock_t = i32; +pub type time_t = i32; +pub type suseconds_t = i32; +pub type wchar_t = i32; +pub type c_longlong = i64; +pub type c_ulonglong = u64; +pub type intptr_t = i32; +pub type uintptr_t = u32; +pub type intmax_t = i64; +pub type uintmax_t = u64; +pub type off_t = i32; +pub type ino_t = u32; +pub type pid_t = i32; +pub type uid_t = u32; +pub type gid_t = u32; +pub type useconds_t = u32; +pub type ssize_t = i32; pub type blkcnt_t = i32; pub type blksize_t = i32; pub type dev_t = u64; diff --git a/src/linuxlike/b64/aarch64.rs b/src/unix/notbsd/linux/notmips/b64/aarch64.rs similarity index 100% rename from src/linuxlike/b64/aarch64.rs rename to src/unix/notbsd/linux/notmips/b64/aarch64.rs diff --git a/src/linuxlike/b64/mod.rs b/src/unix/notbsd/linux/notmips/b64/mod.rs similarity index 100% rename from src/linuxlike/b64/mod.rs rename to src/unix/notbsd/linux/notmips/b64/mod.rs diff --git a/src/linuxlike/b64/x86_64.rs b/src/unix/notbsd/linux/notmips/b64/x86_64.rs similarity index 100% rename from src/linuxlike/b64/x86_64.rs rename to src/unix/notbsd/linux/notmips/b64/x86_64.rs diff --git a/src/linuxlike/linux/other.rs b/src/unix/notbsd/linux/notmips/mod.rs similarity index 94% rename from src/linuxlike/linux/other.rs rename to src/unix/notbsd/linux/notmips/mod.rs index 9e4668a1..2fabb483 100644 --- a/src/linuxlike/linux/other.rs +++ b/src/unix/notbsd/linux/notmips/mod.rs @@ -145,3 +145,15 @@ pub const TCP_FASTOPEN: ::c_int = 23; pub const TCP_TIMESTAMP: ::c_int = 24; pub const SO_REUSEPORT: ::c_int = 15; + +cfg_if! { + if #[cfg(any(target_arch = "x86", target_arch = "arm"))] { + mod b32; + pub use self::b32::*; + } else if #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] { + mod b64; + pub use self::b64::*; + } else { + // ... + } +} diff --git a/src/linuxlike/mod.rs b/src/unix/notbsd/mod.rs similarity index 83% rename from src/linuxlike/mod.rs rename to src/unix/notbsd/mod.rs index 6c3bd908..8222c01a 100644 --- a/src/linuxlike/mod.rs +++ b/src/unix/notbsd/mod.rs @@ -1,7 +1,3 @@ -//! Linux-like values -//! -//! Currenly applies to the Linux and Android platforms - pub type in_addr_t = u32; pub type in_port_t = u16; pub type pthread_t = c_ulong; @@ -13,58 +9,38 @@ pub type socklen_t = u32; pub enum timezone {} s! { - pub struct timeval { - pub tv_sec: time_t, - pub tv_usec: suseconds_t, - } - - pub struct sockaddr { pub sa_family: sa_family_t, pub sa_data: [u8; 14], } - pub struct sockaddr_storage { - pub ss_family: sa_family_t, - __ss_align: isize, - #[cfg(target_pointer_width = "32")] - __ss_pad2: [u8; 128 - 2 * 4], - #[cfg(target_pointer_width = "64")] - __ss_pad2: [u8; 128 - 2 * 8], - } - pub struct sockaddr_in { pub sin_family: sa_family_t, - pub sin_port: in_port_t, - pub sin_addr: in_addr, + pub sin_port: ::in_port_t, + pub sin_addr: ::in_addr, pub sin_zero: [u8; 8], } - pub struct in_addr { - pub s_addr: in_addr_t, - } - pub struct sockaddr_in6 { pub sin6_family: sa_family_t, - pub sin6_port: in_port_t, + pub sin6_port: ::in_port_t, pub sin6_flowinfo: u32, - pub sin6_addr: in6_addr, + pub sin6_addr: ::in6_addr, pub sin6_scope_id: u32, } - pub struct in6_addr { - pub s6_addr: [u16; 8], - __align: [u32; 0], - } - - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, + pub struct sockaddr_un { + pub sun_family: sa_family_t, + pub sun_path: [::c_char; 108] } - pub struct ipv6_mreq { - pub ipv6mr_multiaddr: in6_addr, - pub ipv6mr_interface: c_uint, + pub struct sockaddr_storage { + pub ss_family: sa_family_t, + __ss_align: isize, + #[cfg(target_pointer_width = "32")] + __ss_pad2: [u8; 128 - 2 * 4], + #[cfg(target_pointer_width = "64")] + __ss_pad2: [u8; 128 - 2 * 8], } pub struct addrinfo { @@ -75,50 +51,16 @@ s! { pub ai_addrlen: socklen_t, #[cfg(target_os = "linux")] - pub ai_addr: *mut sockaddr, + pub ai_addr: *mut ::sockaddr, pub ai_canonname: *mut c_char, #[cfg(any(target_os = "android", target_os = "nacl"))] - pub ai_addr: *mut sockaddr, + pub ai_addr: *mut ::sockaddr, pub ai_next: *mut addrinfo, } - pub struct sockaddr_un { - pub sun_family: sa_family_t, - pub sun_path: [c_char; 108] - } - - pub struct timespec { - pub tv_sec: time_t, - pub tv_nsec: c_long, - } - - pub struct rlimit { - pub rlim_cur: rlim_t, - pub rlim_max: rlim_t, - } - - pub struct rusage { - pub ru_utime: timeval, - pub ru_stime: timeval, - pub ru_maxrss: c_long, - pub ru_ixrss: c_long, - pub ru_idrss: c_long, - pub ru_isrss: c_long, - pub ru_minflt: c_long, - pub ru_majflt: c_long, - pub ru_nswap: c_long, - pub ru_inblock: c_long, - pub ru_oublock: c_long, - pub ru_msgsnd: c_long, - pub ru_msgrcv: c_long, - pub ru_nsignals: c_long, - pub ru_nvcsw: c_long, - pub ru_nivcsw: c_long - } - pub struct sockaddr_ll { pub sll_family: c_ushort, pub sll_protocol: c_ushort, @@ -350,16 +292,8 @@ pub const LOCK_UN: ::c_int = 8; extern { pub fn fdatasync(fd: ::c_int) -> ::c_int; -} - -cfg_if! { - if #[cfg(target_pointer_width = "32")] { - mod b32; - pub use self::b32::*; - } else { - mod b64; - pub use self::b64::*; - } + pub fn mincore(addr: *mut ::c_void, len: size_t, + vec: *mut c_uchar) -> c_int; } cfg_if! { diff --git a/src/unix/other/bsdlike.rs b/src/unix/other/bsdlike.rs deleted file mode 100644 index 2928c2eb..00000000 --- a/src/unix/other/bsdlike.rs +++ /dev/null @@ -1,22 +0,0 @@ -extern { - pub fn shm_open(name: *const ::c_char, oflag: ::c_int, ...) -> ::c_int; - pub fn sysctl(name: *mut ::c_int, - namelen: ::c_uint, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *mut ::c_void, - newlen: ::size_t) - -> ::c_int; - pub fn mincore(addr: *const ::c_void, len: ::size_t, - vec: *mut ::c_char) -> ::c_int; - pub fn sysctlbyname(name: *const ::c_char, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *mut ::c_void, - newlen: ::size_t) - -> ::c_int; - pub fn sysctlnametomib(name: *const ::c_char, - mibp: *mut ::c_int, - sizep: *mut ::size_t) - -> ::c_int; -} diff --git a/src/unix/other/mod.rs b/src/unix/other/mod.rs deleted file mode 100644 index 4f2d20ab..00000000 --- a/src/unix/other/mod.rs +++ /dev/null @@ -1,83 +0,0 @@ -//! All Unix OS-es that are not android - -extern { - pub fn getifaddrs(ifap: *mut *mut ::ifaddrs) -> ::c_int; - pub fn freeifaddrs(ifa: *mut ::ifaddrs); - pub fn glob(pattern: *const ::c_char, - flags: ::c_int, - errfunc: Option<extern "C" fn(epath: *const ::c_char, - errno: ::c_int) -> ::c_int>, - pglob: *mut ::glob_t); - pub fn globfree(pglob: *mut ::glob_t); - - pub fn posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) - -> ::c_int; - - pub fn shm_unlink(name: *const ::c_char) -> ::c_int; - - #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), - link_name = "seekdir$INODE64")] - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "seekdir$INODE64$UNIX2003")] - pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long); - - #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), - link_name = "telldir$INODE64")] - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "telldir$INODE64$UNIX2003")] - pub fn telldir(dirp: *mut ::DIR) -> ::c_long; - - pub fn getsid(pid: ::pid_t) -> ::pid_t; - pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) - -> ::c_int; - pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "putenv$UNIX2003")] - pub fn putenv(string: *mut ::c_char) -> ::c_int; - pub fn readlink(path: *const ::c_char, - buf: *mut ::c_char, - bufsz: ::size_t) - -> ::ssize_t; - - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "msync$UNIX2003")] - pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int; - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "mprotect$UNIX2003")] - pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) - -> ::c_int; - pub fn sysconf(name: ::c_int) -> ::c_long; - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "usleep$UNIX2003")] - pub fn usleep(secs: ::c_uint) -> ::c_int; - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "recvfrom$UNIX2003")] - pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t, - flags: ::c_int, addr: *mut ::sockaddr, - addrlen: *mut ::socklen_t) -> ::ssize_t; - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "send$UNIX2003")] - pub fn send(socket: ::c_int, buf: *const ::c_void, len: ::size_t, - flags: ::c_int) -> ::ssize_t; - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "recv$UNIX2003")] - pub fn recv(socket: ::c_int, buf: *mut ::c_void, len: ::size_t, - flags: ::c_int) -> ::ssize_t; - pub fn mkfifo(path: *const ::c_char, mode: ::mode_t) -> ::c_int; -} - -cfg_if! { - if #[cfg(any(target_os = "macos", - target_os = "ios", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "bitrig", - target_os = "netbsd", - target_os = "openbsd"))] { - mod bsdlike; - pub use self::bsdlike::*; - } else { - mod notbsd; - pub use self::notbsd::*; - } -} diff --git a/src/unix/other/notbsd.rs b/src/unix/other/notbsd.rs deleted file mode 100644 index f42ea1fe..00000000 --- a/src/unix/other/notbsd.rs +++ /dev/null @@ -1,14 +0,0 @@ -extern { - pub fn shm_open(name: *const ::c_char, oflag: ::c_int, - mode: ::mode_t) -> ::c_int; - #[cfg(not(target_env = "musl"))] - pub fn sysctl(name: *mut ::c_int, - namelen: ::c_int, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *mut ::c_void, - newlen: ::size_t) - -> ::c_int; - pub fn mincore(addr: *mut ::c_void, len: ::size_t, - vec: *mut ::c_uchar) -> ::c_int; -} -- GitLab