summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurence Tratt <laurie@tratt.net>2015-05-29 16:32:54 +0059
committerLaurence Tratt <laurie@tratt.net>2015-05-29 16:32:54 +0059
commit30d02b88a033cf0e9bb0fd1adb4d81c5c8dc3437 (patch)
tree5f3e4d345f796ef9df55f3c4b7f3b262878214e5 /src
parente2b08fad9c3334e2791aebc28fa1d71d0f76112b (diff)
downloadnix-30d02b88a033cf0e9bb0fd1adb4d81c5c8dc3437.zip
Basic OpenBSD support.
Some of the tests are currently unrunnable, but the basic library is at least buildable.
Diffstat (limited to 'src')
-rw-r--r--src/errno.rs307
-rw-r--r--src/fcntl.rs4
-rw-r--r--src/features.rs2
-rw-r--r--src/sys/ioctl.rs1
-rw-r--r--src/sys/mman.rs2
-rw-r--r--src/sys/mod.rs2
-rw-r--r--src/sys/signal.rs10
-rw-r--r--src/sys/socket/consts.rs2
-rw-r--r--src/sys/termios.rs4
9 files changed, 305 insertions, 29 deletions
diff --git a/src/errno.rs b/src/errno.rs
index 258b7805..d9226b96 100644
--- a/src/errno.rs
+++ b/src/errno.rs
@@ -258,7 +258,7 @@ fn desc(errno: Errno) -> &'static str {
#[cfg(any(target_os = "linux", target_os = "android"))]
ELIBEXEC => "Cannot exec a shared library directly",
- #[cfg(any(target_os = "linux", target_os = "android"))]
+ #[cfg(any(target_os = "linux", target_os = "android", target_os = "openbsd"))]
EILSEQ => "Illegal byte sequence",
#[cfg(any(target_os = "linux", target_os = "android"))]
@@ -294,10 +294,10 @@ fn desc(errno: Errno) -> &'static str {
#[cfg(any(target_os = "linux", target_os = "android"))]
EDQUOT => "Quota exceeded",
- #[cfg(any(target_os = "linux", target_os = "android"))]
+ #[cfg(any(target_os = "linux", target_os = "android", target_os = "openbsd"))]
ENOMEDIUM => "No medium found",
- #[cfg(any(target_os = "linux", target_os = "android"))]
+ #[cfg(any(target_os = "linux", target_os = "android", target_os = "openbsd"))]
EMEDIUMTYPE => "Wrong medium type",
#[cfg(any(target_os = "linux", target_os = "android"))]
@@ -342,16 +342,16 @@ fn desc(errno: Errno) -> &'static str {
#[cfg(target_os = "freebsd")]
ECAPMODE => "Not permitted in capability mode",
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
ENEEDAUTH => "Need authenticator",
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
EOVERFLOW => "Value too large to be stored in data type",
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
EILSEQ => "Illegal byte sequence",
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
ENOATTR => "Attribute not found",
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
@@ -366,46 +366,46 @@ fn desc(errno: Errno) -> &'static str {
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
EOWNERDEAD => "Previous owner died",
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
ENOTSUP => "Operation not supported",
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
EPROCLIM => "Too many processes",
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
EUSERS => "Too many users",
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
EDQUOT => "Disc quota exceeded",
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
ESTALE => "Stale NFS file handle",
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
EREMOTE => "Too many levels of remote in path",
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
EBADRPC => "RPC struct is bad",
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
ERPCMISMATCH => "RPC version wrong",
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
EPROGUNAVAIL => "RPC prog. not avail",
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
EPROGMISMATCH => "Program version wrong",
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
EPROCUNAVAIL => "Bad procedure for program",
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
EFTYPE => "Inappropriate file type or format",
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
EAUTH => "Authentication error",
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
ECANCELED => "Operation canceled",
#[cfg(any(target_os = "macos", target_os = "ios"))]
@@ -452,6 +452,12 @@ fn desc(errno: Errno) -> &'static str {
#[cfg(any(target_os = "macos", target_os = "ios"))]
EQFULL => "Interface output queue is full",
+
+ #[cfg(target_os = "openbsd")]
+ EOPNOTSUPP => "Operation not supported",
+
+ #[cfg(target_os = "openbsd")]
+ EIPSEC => "IPsec processing failure",
}
}
@@ -1201,6 +1207,213 @@ mod consts {
}
+#[cfg(target_os = "openbsd")]
+mod consts {
+ #[derive(Copy, Debug, Clone, PartialEq)]
+ pub enum Errno {
+ UnknownErrno = 0,
+ EPERM = 1,
+ ENOENT = 2,
+ ESRCH = 3,
+ EINTR = 4,
+ EIO = 5,
+ ENXIO = 6,
+ E2BIG = 7,
+ ENOEXEC = 8,
+ EBADF = 9,
+ ECHILD = 10,
+ EDEADLK = 11,
+ ENOMEM = 12,
+ EACCES = 13,
+ EFAULT = 14,
+ ENOTBLK = 15,
+ EBUSY = 16,
+ EEXIST = 17,
+ EXDEV = 18,
+ ENODEV = 19,
+ ENOTDIR = 20,
+ EISDIR = 21,
+ EINVAL = 22,
+ ENFILE = 23,
+ EMFILE = 24,
+ ENOTTY = 25,
+ ETXTBSY = 26,
+ EFBIG = 27,
+ ENOSPC = 28,
+ ESPIPE = 29,
+ EROFS = 30,
+ EMLINK = 31,
+ EPIPE = 32,
+ EDOM = 33,
+ ERANGE = 34,
+ EAGAIN = 35,
+ EINPROGRESS = 36,
+ EALREADY = 37,
+ ENOTSOCK = 38,
+ EDESTADDRREQ = 39,
+ EMSGSIZE = 40,
+ EPROTOTYPE = 41,
+ ENOPROTOOPT = 42,
+ EPROTONOSUPPORT = 43,
+ ESOCKTNOSUPPORT = 44,
+ EOPNOTSUPP = 45,
+ EPFNOSUPPORT = 46,
+ EAFNOSUPPORT = 47,
+ EADDRINUSE = 48,
+ EADDRNOTAVAIL = 49,
+ ENETDOWN = 50,
+ ENETUNREACH = 51,
+ ENETRESET = 52,
+ ECONNABORTED = 53,
+ ECONNRESET = 54,
+ ENOBUFS = 55,
+ EISCONN = 56,
+ ENOTCONN = 57,
+ ESHUTDOWN = 58,
+ ETOOMANYREFS = 59,
+ ETIMEDOUT = 60,
+ ECONNREFUSED = 61,
+ ELOOP = 62,
+ ENAMETOOLONG = 63,
+ EHOSTDOWN = 64,
+ EHOSTUNREACH = 65,
+ ENOTEMPTY = 66,
+ EPROCLIM = 67,
+ EUSERS = 68,
+ EDQUOT = 69,
+ ESTALE = 70,
+ EREMOTE = 71,
+ EBADRPC = 72,
+ ERPCMISMATCH = 73,
+ EPROGUNAVAIL = 74,
+ EPROGMISMATCH = 75,
+ EPROCUNAVAIL = 76,
+ ENOLCK = 77,
+ ENOSYS = 78,
+ EFTYPE = 79,
+ EAUTH = 80,
+ ENEEDAUTH = 81,
+ EIPSEC = 82,
+ ENOATTR = 83,
+ EILSEQ = 84,
+ ENOMEDIUM = 85,
+ EMEDIUMTYPE = 86,
+ EOVERFLOW = 87,
+ ECANCELED = 88,
+ EIDRM = 89,
+ ENOMSG = 90,
+ ENOTSUP = 91,
+ }
+
+ impl_errno!(Errno);
+
+ pub const ELAST: Errno = Errno::ENOTSUP;
+ pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
+
+ pub const EL2NSYNC: Errno = Errno::UnknownErrno;
+
+ pub fn from_i32(e: i32) -> Errno {
+ use self::Errno::*;
+
+ match e {
+ 0 => UnknownErrno,
+ 1 => EPERM,
+ 2 => ENOENT,
+ 3 => ESRCH,
+ 4 => EINTR,
+ 5 => EIO,
+ 6 => ENXIO,
+ 7 => E2BIG,
+ 8 => ENOEXEC,
+ 9 => EBADF,
+ 10 => ECHILD,
+ 11 => EDEADLK,
+ 12 => ENOMEM,
+ 13 => EACCES,
+ 14 => EFAULT,
+ 15 => ENOTBLK,
+ 16 => EBUSY,
+ 17 => EEXIST,
+ 18 => EXDEV,
+ 19 => ENODEV,
+ 20 => ENOTDIR,
+ 21 => EISDIR,
+ 22 => EINVAL,
+ 23 => ENFILE,
+ 24 => EMFILE,
+ 25 => ENOTTY,
+ 26 => ETXTBSY,
+ 27 => EFBIG,
+ 28 => ENOSPC,
+ 29 => ESPIPE,
+ 30 => EROFS,
+ 31 => EMLINK,
+ 32 => EPIPE,
+ 33 => EDOM,
+ 34 => ERANGE,
+ 35 => EAGAIN,
+ 36 => EINPROGRESS,
+ 37 => EALREADY,
+ 38 => ENOTSOCK,
+ 39 => EDESTADDRREQ,
+ 40 => EMSGSIZE,
+ 41 => EPROTOTYPE,
+ 42 => ENOPROTOOPT,
+ 43 => EPROTONOSUPPORT,
+ 44 => ESOCKTNOSUPPORT,
+ 45 => EOPNOTSUPP,
+ 46 => EPFNOSUPPORT,
+ 47 => EAFNOSUPPORT,
+ 48 => EADDRINUSE,
+ 49 => EADDRNOTAVAIL,
+ 50 => ENETDOWN,
+ 51 => ENETUNREACH,
+ 52 => ENETRESET,
+ 53 => ECONNABORTED,
+ 54 => ECONNRESET,
+ 55 => ENOBUFS,
+ 56 => EISCONN,
+ 57 => ENOTCONN,
+ 58 => ESHUTDOWN,
+ 59 => ETOOMANYREFS,
+ 60 => ETIMEDOUT,
+ 61 => ECONNREFUSED,
+ 62 => ELOOP,
+ 63 => ENAMETOOLONG,
+ 64 => EHOSTDOWN,
+ 65 => EHOSTUNREACH,
+ 66 => ENOTEMPTY,
+ 67 => EPROCLIM,
+ 68 => EUSERS,
+ 69 => EDQUOT,
+ 70 => ESTALE,
+ 71 => EREMOTE,
+ 72 => EBADRPC,
+ 73 => ERPCMISMATCH,
+ 74 => EPROGUNAVAIL,
+ 75 => EPROGMISMATCH,
+ 76 => EPROCUNAVAIL,
+ 77 => ENOLCK,
+ 78 => ENOSYS,
+ 79 => EFTYPE,
+ 80 => EAUTH,
+ 81 => ENEEDAUTH,
+ 82 => EIPSEC,
+ 83 => ENOATTR,
+ 84 => EILSEQ,
+ 85 => ENOMEDIUM,
+ 86 => EMEDIUMTYPE,
+ 87 => EOVERFLOW,
+ 88 => ECANCELED,
+ 89 => EIDRM,
+ 90 => ENOMSG,
+ 91 => ENOTSUP,
+ _ => UnknownErrno,
+ }
+ }
+}
+
+
#[cfg(test)]
mod test {
use super::*;
@@ -1396,6 +1609,60 @@ mod test {
}
#[test]
+ #[cfg(target_os = "openbsd")]
+ pub fn test_openbsd_errnos() {
+ check_errno!(
+ EADDRINUSE,
+ EADDRNOTAVAIL,
+ EAFNOSUPPORT,
+ EALREADY,
+ EAUTH,
+ EBADRPC,
+ ECANCELED,
+ ECONNABORTED,
+ ECONNREFUSED,
+ ECONNRESET,
+ EDESTADDRREQ,
+ EDQUOT,
+ EFTYPE,
+ EHOSTDOWN,
+ EHOSTUNREACH,
+ EILSEQ,
+ EINPROGRESS,
+ EIPSEC,
+ EISCONN,
+ EMEDIUMTYPE,
+ EMSGSIZE,
+ ENEEDAUTH,
+ ENETDOWN,
+ ENETRESET,
+ ENETUNREACH,
+ ENOATTR,
+ ENOBUFS,
+ ENOMEDIUM,
+ ENOPROTOOPT,
+ ENOTCONN,
+ ENOTSOCK,
+ ENOTSUP,
+ EOPNOTSUPP,
+ EOVERFLOW,
+ EPFNOSUPPORT,
+ EPROCLIM,
+ EPROCUNAVAIL,
+ EPROGMISMATCH,
+ EPROGUNAVAIL,
+ EPROTONOSUPPORT,
+ EPROTOTYPE,
+ EREMOTE,
+ ESHUTDOWN,
+ ESOCKTNOSUPPORT,
+ ESTALE,
+ ETIMEDOUT,
+ ETOOMANYREFS,
+ EUSERS);
+ }
+
+ #[test]
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub fn test_darwin_errnos() {
check_errno!(
diff --git a/src/fcntl.rs b/src/fcntl.rs
index 28fce037..2c2eb408 100644
--- a/src/fcntl.rs
+++ b/src/fcntl.rs
@@ -40,7 +40,7 @@ mod ffi {
pub const F_GETLK: c_int = 5;
}
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
mod os {
use libc::{c_int, c_short, off_t, pid_t};
@@ -190,7 +190,7 @@ mod consts {
);
}
-#[cfg(target_os = "freebsd")]
+#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
mod consts {
use libc::c_int;
diff --git a/src/features.rs b/src/features.rs
index 34c41b32..f4a1f4e3 100644
--- a/src/features.rs
+++ b/src/features.rs
@@ -92,7 +92,7 @@ mod os {
}
}
-#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
mod os {
pub fn socket_atomic_cloexec() -> bool {
false
diff --git a/src/sys/ioctl.rs b/src/sys/ioctl.rs
index d295d08d..0a2a3451 100644
--- a/src/sys/ioctl.rs
+++ b/src/sys/ioctl.rs
@@ -82,6 +82,7 @@ pub type ioctl_op_t = c_ulong;
#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "freebsd",
+ target_os = "openbsd",
target_os = "dragonfly"))]
type os_ioctl_op_t = c_ulong;
diff --git a/src/sys/mman.rs b/src/sys/mman.rs
index 0815b618..54f256b2 100644
--- a/src/sys/mman.rs
+++ b/src/sys/mman.rs
@@ -113,7 +113,7 @@ mod consts {
pub const MAP_FAILED: isize = -1;
}
-#[cfg(target_os = "freebsd")]
+#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
mod consts {
use libc::c_int;
diff --git a/src/sys/mod.rs b/src/sys/mod.rs
index f0fda20a..ac9d6216 100644
--- a/src/sys/mod.rs
+++ b/src/sys/mod.rs
@@ -2,7 +2,7 @@
#[cfg(any(target_os = "linux", target_os = "android"))]
pub mod epoll;
-#[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd"))]
+#[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "openbsd"))]
pub mod event;
// TODO: switch from feature flags to conditional builds
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index 8f3ecdcf..f777841b 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -201,6 +201,7 @@ pub mod signal {
#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "freebsd",
+ target_os = "openbsd",
target_os = "dragonfly"))]
pub mod signal {
use libc;
@@ -238,7 +239,7 @@ pub mod signal {
pub const SIGUSR1: libc::c_int = 30;
pub const SIGUSR2: libc::c_int = 31;
- #[cfg(any(target_os = "macos", target_os = "ios"))]
+ #[cfg(any(target_os = "macos", target_os = "ios", target_os = "openbsd"))]
pub type sigset_t = u32;
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
#[repr(C)]
@@ -278,6 +279,13 @@ pub mod signal {
pub sa_mask: sigset_t,
}
+ #[cfg(target_os = "openbsd")]
+ #[repr(C)]
+ pub struct sigaction {
+ pub sa_handler: extern fn(libc::c_int),
+ pub sa_mask: sigset_t,
+ pub sa_flags: SockFlag,
+ }
}
mod ffi {
diff --git a/src/sys/socket/consts.rs b/src/sys/socket/consts.rs
index caa06fff..a716b1ab 100644
--- a/src/sys/socket/consts.rs
+++ b/src/sys/socket/consts.rs
@@ -96,7 +96,7 @@ mod os {
}
// Not all of these constants exist on freebsd
-#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
+#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd"))]
mod os {
use libc::{c_int, uint8_t};
diff --git a/src/sys/termios.rs b/src/sys/termios.rs
index 7473eab4..4050e7d5 100644
--- a/src/sys/termios.rs
+++ b/src/sys/termios.rs
@@ -17,7 +17,7 @@ mod ffi {
// `Termios` contains bitflags which are not considered
// `foreign-function-safe` by the compiler.
#[allow(improper_ctypes)]
- #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "linux"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd", target_os = "linux"))]
extern {
pub fn cfgetispeed(termios: *const Termios) -> speed_t;
pub fn cfgetospeed(termios: *const Termios) -> speed_t;
@@ -89,7 +89,7 @@ mod ffi {
pub use self::android::*;
- #[cfg(any(target_os = "macos", target_os = "freebsd"))]
+ #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd"))]
pub mod consts {
use libc::{c_int, c_ulong, c_uchar};