Skip to content

Commit 147daf3

Browse files
author
Al Hoang
committed
add haiku support
1 parent 3109a6d commit 147daf3

25 files changed

+424
-101
lines changed

src/dir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl Entry {
226226
/// notably, some Linux filesystems don't implement this. The caller should use `stat` or
227227
/// `fstat` if this returns `None`.
228228
pub fn file_type(&self) -> Option<Type> {
229-
#[cfg(not(any(target_os = "illumos", target_os = "solaris")))]
229+
#[cfg(not(any(target_os = "illumos", target_os = "solaris", target_os = "haiku")))]
230230
match self.0.d_type {
231231
libc::DT_FIFO => Some(Type::Fifo),
232232
libc::DT_CHR => Some(Type::CharacterDevice),
@@ -239,7 +239,7 @@ impl Entry {
239239
}
240240

241241
// illumos and Solaris systems do not have the d_type member at all:
242-
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
242+
#[cfg(any(target_os = "illumos", target_os = "solaris", target_os = "haiku"))]
243243
None
244244
}
245245
}

src/errno.rs

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ cfg_if! {
3030
unsafe fn errno_location() -> *mut c_int {
3131
libc::___errno()
3232
}
33+
} else if #[cfg(any(target_os = "haiku",))] {
34+
unsafe fn errno_location() -> *mut c_int {
35+
libc::_errnop()
36+
}
3337
}
3438
}
3539

@@ -183,6 +187,7 @@ fn last() -> Errno {
183187
Errno::from_i32(errno())
184188
}
185189

190+
#[cfg(not(target_os = "haiku"))]
186191
fn desc(errno: Errno) -> &'static str {
187192
use self::Errno::*;
188193
match errno {
@@ -767,6 +772,80 @@ fn desc(errno: Errno) -> &'static str {
767772
}
768773
}
769774

775+
#[cfg(target_os = "haiku")]
776+
fn desc(errno: Errno) -> &'static str {
777+
use self::Errno::*;
778+
match errno {
779+
UnknownErrno => "Unknown errno",
780+
EPERM => "Operation not permitted",
781+
ENOENT => "No such file or directory",
782+
ESRCH => "No such process",
783+
EINTR => "Interrupted system call",
784+
EIO => "I/O error",
785+
ENXIO => "No such device or address",
786+
E2BIG => "Argument list too long",
787+
ENOEXEC => "Exec format error",
788+
EBADF => "Bad file number",
789+
ECHILD => "No child processes",
790+
EAGAIN => "Try again",
791+
ENOMEM => "Out of memory",
792+
EACCES => "Permission denied",
793+
EFAULT => "Bad address",
794+
EBUSY => "Device or resource busy",
795+
EEXIST => "File exists",
796+
EXDEV => "Cross-device link",
797+
ENODEV => "No such device",
798+
ENOTDIR => "Not a directory",
799+
EISDIR => "Is a directory",
800+
EINVAL => "Invalid argument",
801+
ENFILE => "File table overflow",
802+
EMFILE => "Too many open files",
803+
ENOTTY => "Not a typewriter",
804+
ETXTBSY => "Text file busy",
805+
EFBIG => "File too large",
806+
ENOSPC => "No space left on device",
807+
ESPIPE => "Illegal seek",
808+
EROFS => "Read-only file system",
809+
EMLINK => "Too many links",
810+
EPIPE => "Broken pipe",
811+
EDOM => "Math argument out of domain of func",
812+
ERANGE => "Math result not representable",
813+
EDEADLK => "Resource deadlock would occur",
814+
ENAMETOOLONG => "File name too long",
815+
ENOLCK => "No record locks available",
816+
ENOSYS => "Function not implemented",
817+
ENOTEMPTY => "Directory not empty",
818+
ELOOP => "Too many symbolic links encountered",
819+
ENOMSG => "No message of desired type",
820+
EIDRM => "Identifier removed",
821+
EINPROGRESS => "Operation now in progress",
822+
EALREADY => "Operation already in progress",
823+
ENOTSOCK => "Socket operation on non-socket",
824+
EDESTADDRREQ => "Destination address required",
825+
EMSGSIZE => "Message too long",
826+
EPROTOTYPE => "Protocol wrong type for socket",
827+
ENOPROTOOPT => "Protocol not available",
828+
EPROTONOSUPPORT => "Protocol not supported",
829+
EADDRINUSE => "Address already in use",
830+
EADDRNOTAVAIL => "Cannot assign requested address",
831+
ENETDOWN => "Network is down",
832+
ENETUNREACH => "Network is unreachable",
833+
ENETRESET => "Network dropped connection because of reset",
834+
ECONNABORTED => "Software caused connection abort",
835+
ECONNRESET => "Connection reset by peer",
836+
ENOBUFS => "No buffer space available",
837+
EISCONN => "Transport endpoint is already connected",
838+
ENOTCONN => "Transport endpoint is not connected",
839+
ESHUTDOWN => "Cannot send after transport endpoint shutdown",
840+
ETIMEDOUT => "Connection timed out",
841+
ECONNREFUSED => "Connection refused",
842+
EHOSTDOWN => "Host is down",
843+
EHOSTUNREACH => "No route to host",
844+
_ => "unknown errno",
845+
846+
}
847+
}
848+
770849
#[cfg(any(target_os = "linux", target_os = "android",
771850
target_os = "fuchsia"))]
772851
mod consts {
@@ -2725,3 +2804,178 @@ mod consts {
27252804
}
27262805
}
27272806
}
2807+
2808+
#[cfg(target_os = "haiku")]
2809+
mod consts {
2810+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2811+
#[repr(i32)]
2812+
#[non_exhaustive]
2813+
pub enum Errno {
2814+
UnknownErrno = 0,
2815+
EPERM = libc::EPERM,
2816+
ENOENT = libc::ENOENT,
2817+
ESRCH = libc::ESRCH,
2818+
EINTR = libc::EINTR,
2819+
EIO = libc::EIO,
2820+
ENXIO = libc::ENXIO,
2821+
E2BIG = libc::E2BIG,
2822+
ENOEXEC = libc::ENOEXEC,
2823+
EBADF = libc::EBADF,
2824+
ECHILD = libc::ECHILD,
2825+
EDEADLK = libc::EDEADLK,
2826+
ENOMEM = libc::ENOMEM,
2827+
EACCES = libc::EACCES,
2828+
EFAULT = libc::EFAULT,
2829+
EBUSY = libc::EBUSY,
2830+
EEXIST = libc::EEXIST,
2831+
EXDEV = libc::EXDEV,
2832+
ENODEV = libc::ENODEV,
2833+
ENOTDIR = libc::ENOTDIR,
2834+
EISDIR = libc::EISDIR,
2835+
EINVAL = libc::EINVAL,
2836+
ENFILE = libc::ENFILE,
2837+
EMFILE = libc::EMFILE,
2838+
ENOTTY = libc::ENOTTY,
2839+
ETXTBSY = libc::ETXTBSY,
2840+
EFBIG = libc::EFBIG,
2841+
ENOSPC = libc::ENOSPC,
2842+
ESPIPE = libc::ESPIPE,
2843+
EROFS = libc::EROFS,
2844+
EMLINK = libc::EMLINK,
2845+
EPIPE = libc::EPIPE,
2846+
EDOM = libc::EDOM,
2847+
ERANGE = libc::ERANGE,
2848+
EAGAIN = libc::EAGAIN,
2849+
EINPROGRESS = libc::EINPROGRESS,
2850+
EALREADY = libc::EALREADY,
2851+
ENOTSOCK = libc::ENOTSOCK,
2852+
EDESTADDRREQ = libc::EDESTADDRREQ,
2853+
EMSGSIZE = libc::EMSGSIZE,
2854+
EPROTOTYPE = libc::EPROTOTYPE,
2855+
ENOPROTOOPT = libc::ENOPROTOOPT,
2856+
EPROTONOSUPPORT = libc::EPROTONOSUPPORT,
2857+
ENOTSUP = libc::ENOTSUP,
2858+
EADDRINUSE = libc::EADDRINUSE,
2859+
EADDRNOTAVAIL = libc::EADDRNOTAVAIL,
2860+
ENETDOWN = libc::ENETDOWN,
2861+
ENETUNREACH = libc::ENETUNREACH,
2862+
ENETRESET = libc::ENETRESET,
2863+
ECONNABORTED = libc::ECONNABORTED,
2864+
ECONNRESET = libc::ECONNRESET,
2865+
ENOBUFS = libc::ENOBUFS,
2866+
EISCONN = libc::EISCONN,
2867+
ENOTCONN = libc::ENOTCONN,
2868+
ESHUTDOWN = libc::ESHUTDOWN,
2869+
ETIMEDOUT = libc::ETIMEDOUT,
2870+
ECONNREFUSED = libc::ECONNREFUSED,
2871+
ELOOP = libc::ELOOP,
2872+
ENAMETOOLONG = libc::ENAMETOOLONG,
2873+
EHOSTDOWN = libc::EHOSTDOWN,
2874+
EHOSTUNREACH = libc::EHOSTUNREACH,
2875+
ENOTEMPTY = libc::ENOTEMPTY,
2876+
EDQUOT = libc::EDQUOT,
2877+
ESTALE = libc::ESTALE,
2878+
ENOLCK = libc::ENOLCK,
2879+
ENOSYS = libc::ENOSYS,
2880+
EIDRM = libc::EIDRM,
2881+
ENOMSG = libc::ENOMSG,
2882+
EOVERFLOW = libc::EOVERFLOW,
2883+
ECANCELED = libc::ECANCELED,
2884+
EILSEQ = libc::EILSEQ,
2885+
ENOATTR = libc::ENOATTR,
2886+
EBADMSG = libc::EBADMSG,
2887+
EMULTIHOP = libc::EMULTIHOP,
2888+
ENOLINK = libc::ENOLINK,
2889+
EPROTO = libc::EPROTO,
2890+
}
2891+
2892+
impl Errno {
2893+
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
2894+
pub const EDEADLOCK: Errno = Errno::EDEADLK;
2895+
pub const EOPNOTSUPP: Errno = Errno::ENOTSUP;
2896+
}
2897+
2898+
pub const fn from_i32(e: i32) -> Errno {
2899+
use self::Errno::*;
2900+
2901+
match e {
2902+
libc::EPERM => EPERM,
2903+
libc::ENOENT => ENOENT,
2904+
libc::ESRCH => ESRCH,
2905+
libc::EINTR => EINTR,
2906+
libc::EIO => EIO,
2907+
libc::ENXIO => ENXIO,
2908+
libc::E2BIG => E2BIG,
2909+
libc::ENOEXEC => ENOEXEC,
2910+
libc::EBADF => EBADF,
2911+
libc::ECHILD => ECHILD,
2912+
libc::EDEADLK => EDEADLK,
2913+
libc::ENOMEM => ENOMEM,
2914+
libc::EACCES => EACCES,
2915+
libc::EFAULT => EFAULT,
2916+
libc::EBUSY => EBUSY,
2917+
libc::EEXIST => EEXIST,
2918+
libc::EXDEV => EXDEV,
2919+
libc::ENODEV => ENODEV,
2920+
libc::ENOTDIR => ENOTDIR,
2921+
libc::EISDIR => EISDIR,
2922+
libc::EINVAL => EINVAL,
2923+
libc::ENFILE => ENFILE,
2924+
libc::EMFILE => EMFILE,
2925+
libc::ENOTTY => ENOTTY,
2926+
libc::ETXTBSY => ETXTBSY,
2927+
libc::EFBIG => EFBIG,
2928+
libc::ENOSPC => ENOSPC,
2929+
libc::ESPIPE => ESPIPE,
2930+
libc::EROFS => EROFS,
2931+
libc::EMLINK => EMLINK,
2932+
libc::EPIPE => EPIPE,
2933+
libc::EDOM => EDOM,
2934+
libc::ERANGE => ERANGE,
2935+
libc::EAGAIN => EAGAIN,
2936+
libc::EINPROGRESS => EINPROGRESS,
2937+
libc::EALREADY => EALREADY,
2938+
libc::ENOTSOCK => ENOTSOCK,
2939+
libc::EDESTADDRREQ => EDESTADDRREQ,
2940+
libc::EMSGSIZE => EMSGSIZE,
2941+
libc::EPROTOTYPE => EPROTOTYPE,
2942+
libc::ENOPROTOOPT => ENOPROTOOPT,
2943+
libc::EPROTONOSUPPORT => EPROTONOSUPPORT,
2944+
libc::ENOTSUP => ENOTSUP,
2945+
libc::EADDRINUSE => EADDRINUSE,
2946+
libc::EADDRNOTAVAIL => EADDRNOTAVAIL,
2947+
libc::ENETDOWN => ENETDOWN,
2948+
libc::ENETUNREACH => ENETUNREACH,
2949+
libc::ENETRESET => ENETRESET,
2950+
libc::ECONNABORTED => ECONNABORTED,
2951+
libc::ECONNRESET => ECONNRESET,
2952+
libc::ENOBUFS => ENOBUFS,
2953+
libc::EISCONN => EISCONN,
2954+
libc::ENOTCONN => ENOTCONN,
2955+
libc::ESHUTDOWN => ESHUTDOWN,
2956+
libc::ETIMEDOUT => ETIMEDOUT,
2957+
libc::ECONNREFUSED => ECONNREFUSED,
2958+
libc::ELOOP => ELOOP,
2959+
libc::ENAMETOOLONG => ENAMETOOLONG,
2960+
libc::EHOSTDOWN => EHOSTDOWN,
2961+
libc::EHOSTUNREACH => EHOSTUNREACH,
2962+
libc::ENOTEMPTY => ENOTEMPTY,
2963+
libc::EDQUOT => EDQUOT,
2964+
libc::ESTALE => ESTALE,
2965+
libc::ENOLCK => ENOLCK,
2966+
libc::ENOSYS => ENOSYS,
2967+
libc::EIDRM => EIDRM,
2968+
libc::ENOMSG => ENOMSG,
2969+
libc::EOVERFLOW => EOVERFLOW,
2970+
libc::ECANCELED => ECANCELED,
2971+
libc::EILSEQ => EILSEQ,
2972+
libc::ENOATTR => ENOATTR,
2973+
libc::EBADMSG => EBADMSG,
2974+
libc::EMULTIHOP => EMULTIHOP,
2975+
libc::ENOLINK => ENOLINK,
2976+
libc::EPROTO => EPROTO,
2977+
_ => UnknownErrno,
2978+
}
2979+
}
2980+
}
2981+

src/fcntl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ libc_bitflags!(
5858
/// Open the file in append-only mode.
5959
O_APPEND;
6060
/// Generate a signal when input or output becomes possible.
61-
#[cfg(not(any(target_os = "illumos", target_os = "solaris")))]
61+
#[cfg(not(any(target_os = "illumos", target_os = "solaris", target_os = "haiku")))]
6262
#[cfg_attr(docsrs, doc(cfg(all())))]
6363
O_ASYNC;
6464
/// Closes the file descriptor once an `execve` call is made.
@@ -128,7 +128,7 @@ libc_bitflags!(
128128
#[cfg_attr(docsrs, doc(cfg(all())))]
129129
O_NOCTTY;
130130
/// Same as `O_NONBLOCK`.
131-
#[cfg(not(target_os = "redox"))]
131+
#[cfg(not(any(target_os = "redox", target_os = "haiku")))]
132132
#[cfg_attr(docsrs, doc(cfg(all())))]
133133
O_NDELAY;
134134
/// `open()` will fail if the given path is a symbolic link.

src/features.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ mod os {
114114
#[cfg(any(target_os = "macos",
115115
target_os = "ios",
116116
target_os = "fuchsia",
117+
target_os = "haiku",
117118
target_os = "solaris"))]
118119
mod os {
119120
/// Check if the OS supports atomic close-on-exec for sockets

src/net/if_.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ libc_bitflags!(
2828
IFF_BROADCAST;
2929
/// Internal debugging flag. (see
3030
/// [`netdevice(7)`](https://man7.org/linux/man-pages/man7/netdevice.7.html))
31+
#[cfg(not(target_os = "haiku"))]
3132
IFF_DEBUG;
3233
/// Interface is a loopback interface. (see
3334
/// [`netdevice(7)`](https://man7.org/linux/man-pages/man7/netdevice.7.html))

src/sys/ioctl/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ pub use self::linux::*;
236236
target_os = "ios",
237237
target_os = "macos",
238238
target_os = "netbsd",
239+
target_os = "haiku",
239240
target_os = "openbsd"))]
240241
#[macro_use]
241242
mod bsd;
@@ -246,6 +247,7 @@ mod bsd;
246247
target_os = "ios",
247248
target_os = "macos",
248249
target_os = "netbsd",
250+
target_os = "haiku",
249251
target_os = "openbsd"))]
250252
pub use self::bsd::*;
251253

src/sys/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ feature! {
5252
pub mod memfd;
5353
}
5454

55-
#[cfg(not(target_os = "redox"))]
55+
#[cfg(not(any(target_os = "redox", target_os = "haiku")))]
5656
feature! {
5757
#![feature = "mman"]
5858
pub mod mman;
@@ -94,7 +94,7 @@ feature! {
9494
pub mod reboot;
9595
}
9696

97-
#[cfg(not(any(target_os = "redox", target_os = "fuchsia", target_os = "illumos")))]
97+
#[cfg(not(any(target_os = "redox", target_os = "fuchsia", target_os = "illumos", target_os = "haiku")))]
9898
feature! {
9999
#![feature = "resource"]
100100
pub mod resource;
@@ -126,7 +126,7 @@ feature! {
126126
pub mod signalfd;
127127
}
128128

129-
#[cfg(not(target_os = "redox"))]
129+
#[cfg(not(any(target_os = "redox", target_os = "haiku")))]
130130
feature! {
131131
#![feature = "socket"]
132132
#[allow(missing_docs)]

0 commit comments

Comments
 (0)