summaryrefslogtreecommitdiff
path: root/libc/src/unix/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'libc/src/unix/mod.rs')
-rw-r--r--libc/src/unix/mod.rs135
1 files changed, 94 insertions, 41 deletions
diff --git a/libc/src/unix/mod.rs b/libc/src/unix/mod.rs
index 88e13c5..1565b63 100644
--- a/libc/src/unix/mod.rs
+++ b/libc/src/unix/mod.rs
@@ -3,8 +3,6 @@
//! More functions and definitions can be found in the more specific modules
//! according to the platform in question.
-use dox::Option;
-
pub type int8_t = i8;
pub type int16_t = i16;
pub type int32_t = i32;
@@ -41,8 +39,18 @@ pub type in_port_t = u16;
pub type sighandler_t = ::size_t;
pub type cc_t = ::c_uchar;
+#[cfg_attr(feature = "extra_traits", derive(Debug))]
pub enum DIR {}
+impl ::Copy for DIR {}
+impl ::Clone for DIR {
+ fn clone(&self) -> DIR { *self }
+}
+#[cfg_attr(feature = "extra_traits", derive(Debug))]
pub enum locale_t {}
+impl ::Copy for locale_t {}
+impl ::Clone for locale_t {
+ fn clone(&self) -> locale_t { *self }
+}
s! {
pub struct group {
@@ -127,23 +135,6 @@ s! {
__reserved: [c_long; 16],
}
- #[cfg_attr(target_os = "netbsd", repr(packed))]
- pub struct in_addr {
- pub s_addr: in_addr_t,
- }
-
- #[cfg_attr(feature = "align", repr(align(4)))]
- pub struct in6_addr {
- pub s6_addr: [u8; 16],
- #[cfg(not(feature = "align"))]
- __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,
#[cfg(target_os = "android")]
@@ -232,7 +223,11 @@ pub const DT_REG: u8 = 8;
pub const DT_LNK: u8 = 10;
pub const DT_SOCK: u8 = 12;
-pub const FD_CLOEXEC: ::c_int = 0x1;
+cfg_if! {
+ if #[cfg(not(target_os = "redox"))] {
+ pub const FD_CLOEXEC: ::c_int = 0x1;
+ }
+}
pub const USRQUOTA: ::c_int = 0;
pub const GRPQUOTA: ::c_int = 1;
@@ -310,9 +305,7 @@ pub const ATF_PUBL: ::c_int = 0x08;
pub const ATF_USETRAILERS: ::c_int = 0x10;
cfg_if! {
- if #[cfg(cross_platform_docs)] {
- // on dox builds don't pull in anything
- } else if #[cfg(target_os = "l4re")] {
+ if #[cfg(target_os = "l4re")] {
// required libraries for L4Re are linked externally, ATM
} else if #[cfg(feature = "use_std")] {
// cargo build, don't pull in anything extra as the libstd dep
@@ -338,8 +331,7 @@ cfg_if! {
} else if #[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "android",
- target_os = "openbsd",
- target_os = "bitrig"))] {
+ target_os = "openbsd"))] {
#[link(name = "c")]
#[link(name = "m")]
extern {}
@@ -356,6 +348,17 @@ cfg_if! {
// to "pthread" needs to be added.
#[link(name = "pthread")]
extern {}
+ } else if #[cfg(target_env = "illumos")] {
+ #[link(name = "c")]
+ #[link(name = "m")]
+ extern {}
+ } else if #[cfg(target_os = "redox")] {
+ #[cfg_attr(feature = "rustc-dep-of-std",
+ link(name = "c", kind = "static-nobundle",
+ cfg(target_feature = "crt-static")))]
+ #[cfg_attr(feature = "rustc-dep-of-std",
+ link(name = "c", cfg(not(target_feature = "crt-static"))))]
+ extern {}
} else {
#[link(name = "c")]
#[link(name = "m")]
@@ -365,8 +368,18 @@ cfg_if! {
}
}
+#[cfg_attr(feature = "extra_traits", derive(Debug))]
pub enum FILE {}
+impl ::Copy for FILE {}
+impl ::Clone for FILE {
+ fn clone(&self) -> FILE { *self }
+}
+#[cfg_attr(feature = "extra_traits", derive(Debug))]
pub enum fpos_t {} // TODO: fill this out with a struct
+impl ::Copy for fpos_t {}
+impl ::Clone for fpos_t {
+ fn clone(&self) -> fpos_t { *self }
+}
extern {
pub fn isalnum(c: c_int) -> c_int;
@@ -509,20 +522,26 @@ extern {
pub fn snprintf(s: *mut ::c_char, n: ::size_t,
format: *const ::c_char, ...) -> ::c_int;
pub fn sprintf(s: *mut ::c_char, format: *const ::c_char, ...) -> ::c_int;
+ #[cfg_attr(target_os = "linux", link_name = "__isoc99_fscanf")]
pub fn fscanf(stream: *mut ::FILE, format: *const ::c_char, ...) -> ::c_int;
+ #[cfg_attr(target_os = "linux", link_name = "__isoc99_scanf")]
pub fn scanf(format: *const ::c_char, ...) -> ::c_int;
+ #[cfg_attr(target_os = "linux", link_name = "__isoc99_sscanf")]
pub fn sscanf(s: *const ::c_char, format: *const ::c_char, ...) -> ::c_int;
pub fn getchar_unlocked() -> ::c_int;
pub fn putchar_unlocked(c: ::c_int) -> ::c_int;
#[cfg_attr(target_os = "netbsd", link_name = "__socket30")]
+ #[cfg_attr(target_os = "illumos", link_name = "__xnet_socket")]
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")]
+ #[cfg_attr(target_os = "illumos", link_name = "__xnet_connect")]
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 = "listen$UNIX2003")]
+ #[cfg_attr(target_os = "illumos", link_name = "__xnet_listen")]
pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "accept$UNIX2003")]
@@ -541,10 +560,12 @@ extern {
option_len: socklen_t) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "socketpair$UNIX2003")]
+ #[cfg_attr(target_os = "illumos", link_name = "__xnet_socketpair")]
pub fn socketpair(domain: ::c_int, type_: ::c_int, protocol: ::c_int,
socket_vector: *mut ::c_int) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "sendto$UNIX2003")]
+ #[cfg_attr(target_os = "illumos", link_name = "__xnet_sendto")]
pub fn sendto(socket: ::c_int, buf: *const ::c_void, len: ::size_t,
flags: ::c_int, addr: *const sockaddr,
addrlen: socklen_t) -> ::ssize_t;
@@ -604,8 +625,13 @@ extern {
pub fn readdir(dirp: *mut ::DIR) -> *mut ::dirent;
#[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")]
#[cfg_attr(target_os = "netbsd", link_name = "__readdir_r30")]
- #[cfg_attr(target_os = "solaris", link_name = "__posix_readdir_r")]
#[cfg_attr(target_os = "freebsd", link_name = "readdir_r@FBSD_1.0")]
+ /// The 64-bit libc on Solaris and illumos only has readdir_r. If a
+ /// 32-bit Solaris or illumos target is ever created, it should use
+ /// __posix_readdir_r. See libc(3LIB) on Solaris or illumos:
+ /// https://illumos.org/man/3lib/libc
+ /// https://docs.oracle.com/cd/E36784_01/html/E36873/libc-3lib.html
+ /// https://www.unix.com/man-page/opensolaris/3LIB/libc/
pub fn readdir_r(dirp: *mut ::DIR, entry: *mut ::dirent,
result: *mut *mut ::dirent) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
@@ -824,6 +850,14 @@ extern {
pub fn flock(fd: ::c_int, operation: ::c_int) -> ::c_int;
#[cfg_attr(target_os = "netbsd", link_name = "__gettimeofday50")]
+ #[deprecated(
+ since="0.2.54",
+ note=
+ "The signature of this function is incorrect. \
+ If you are using it, please report that in the following issue \
+ so that we can evaluate the impact of fixing it: \
+ https://github.com/rust-lang/libc/issues/1338"
+ )]
pub fn gettimeofday(tp: *mut ::timeval,
tz: *mut ::c_void) -> ::c_int;
#[cfg_attr(target_os = "netbsd", link_name = "__times13")]
@@ -845,7 +879,7 @@ extern {
#[cfg_attr(target_os = "netbsd", link_name = "__libc_thr_yield")]
pub fn sched_yield() -> ::c_int;
pub fn pthread_key_create(key: *mut pthread_key_t,
- dtor: Option<unsafe extern fn(*mut ::c_void)>)
+ dtor: ::Option<unsafe extern fn(*mut ::c_void)>)
-> ::c_int;
pub fn pthread_key_delete(key: pthread_key_t) -> ::c_int;
pub fn pthread_getspecific(key: pthread_key_t) -> *mut ::c_void;
@@ -913,6 +947,7 @@ extern {
pub fn strerror_r(errnum: ::c_int, buf: *mut c_char,
buflen: ::size_t) -> ::c_int;
+ #[cfg_attr(target_os = "illumos", link_name = "__xnet_getsockopt")]
pub fn getsockopt(sockfd: ::c_int,
level: ::c_int,
optname: ::c_int,
@@ -1011,16 +1046,11 @@ extern {
locale: *const ::c_char) -> *mut ::c_char;
pub fn localeconv() -> *mut lconv;
- pub fn sem_destroy(sem: *mut sem_t) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "sem_wait$UNIX2003")]
pub fn sem_wait(sem: *mut sem_t) -> ::c_int;
pub fn sem_trywait(sem: *mut sem_t) -> ::c_int;
pub fn sem_post(sem: *mut sem_t) -> ::c_int;
- pub fn sem_init(sem: *mut sem_t,
- pshared: ::c_int,
- value: ::c_uint)
- -> ::c_int;
pub fn statvfs(path: *const c_char, buf: *mut statvfs) -> ::c_int;
pub fn fstatvfs(fd: ::c_int, buf: *mut statvfs) -> ::c_int;
@@ -1077,10 +1107,8 @@ extern {
pub fn tcdrain(fd: ::c_int) -> ::c_int;
pub fn cfgetispeed(termios: *const ::termios) -> ::speed_t;
pub fn cfgetospeed(termios: *const ::termios) -> ::speed_t;
- pub fn cfmakeraw(termios: *mut ::termios);
pub fn cfsetispeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
pub fn cfsetospeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
- pub fn cfsetspeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
pub fn tcgetattr(fd: ::c_int, termios: *mut ::termios) -> ::c_int;
pub fn tcsetattr(fd: ::c_int,
optional_actions: ::c_int,
@@ -1114,6 +1142,16 @@ extern {
}
cfg_if! {
+ if #[cfg(not(any(target_os = "solaris", target_os = "illumos")))] {
+ extern {
+ pub fn cfmakeraw(termios: *mut ::termios);
+ pub fn cfsetspeed(termios: *mut ::termios,
+ speed: ::speed_t) -> ::c_int;
+ }
+ }
+}
+
+cfg_if! {
if #[cfg(target_env = "uclibc")] {
mod uclibc;
pub use self::uclibc::*;
@@ -1130,32 +1168,37 @@ cfg_if! {
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
- target_os = "netbsd",
- target_os = "bitrig"))] {
+ target_os = "netbsd"))] {
mod bsd;
pub use self::bsd::*;
- } else if #[cfg(target_os = "solaris")] {
- mod solaris;
- pub use self::solaris::*;
+ } else if #[cfg(any(target_os = "solaris",
+ target_os = "illumos"))] {
+ mod solarish;
+ pub use self::solarish::*;
} else if #[cfg(target_os = "haiku")] {
mod haiku;
pub use self::haiku::*;
} else if #[cfg(target_os = "hermit")] {
mod hermit;
pub use self::hermit::*;
+ } else if #[cfg(target_os = "redox")] {
+ mod redox;
+ pub use self::redox::*;
} else {
// Unknown target_os
}
}
cfg_if! {
- if #[cfg(core_cvoid)] {
- pub use core::ffi::c_void;
+ if #[cfg(libc_core_cvoid)] {
+ pub use ::ffi::c_void;
} else {
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
// enable more optimization opportunities around it recognizing things
// like malloc/free.
#[repr(u8)]
+ #[allow(missing_copy_implementations)]
+ #[allow(missing_debug_implementations)]
pub enum c_void {
// Two dummy variants so the #[repr] attribute can be used.
#[doc(hidden)]
@@ -1165,3 +1208,13 @@ cfg_if! {
}
}
}
+
+cfg_if! {
+ if #[cfg(libc_align)] {
+ mod align;
+ pub use self::align::*;
+ } else {
+ mod no_align;
+ pub use self::no_align::*;
+ }
+}