Skip to content

Commit

Permalink
Fix various compilation errors on haiku.
Browse files Browse the repository at this point in the history
This builds on top of #407!
  • Loading branch information
sunfishcode committed Sep 25, 2022
1 parent cd9beb9 commit 3900961
Show file tree
Hide file tree
Showing 30 changed files with 344 additions and 115 deletions.
13 changes: 10 additions & 3 deletions examples/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,22 @@ fn main() -> io::Result<()> {
println!("Fsize Limit: {:?}", getrlimit(Resource::Fsize));
println!("Data Limit: {:?}", getrlimit(Resource::Data));
println!("Stack Limit: {:?}", getrlimit(Resource::Stack));
#[cfg(not(target_os = "haiku"))]
println!("Core Limit: {:?}", getrlimit(Resource::Core));
#[cfg(not(target_os = "solaris"))]
#[cfg(not(any(target_os = "haiku", target_os = "solaris")))]
println!("Rss Limit: {:?}", getrlimit(Resource::Rss));
#[cfg(not(target_os = "solaris"))]
#[cfg(not(any(target_os = "haiku", target_os = "solaris")))]
println!("Nproc Limit: {:?}", getrlimit(Resource::Nproc));
#[cfg(not(target_os = "solaris"))]
println!("Nofile Limit: {:?}", getrlimit(Resource::Nofile));
#[cfg(not(target_os = "solaris"))]
#[cfg(not(any(target_os = "haiku", target_os = "solaris")))]
println!("Memlock Limit: {:?}", getrlimit(Resource::Memlock));
#[cfg(not(target_os = "openbsd"))]
println!("As Limit: {:?}", getrlimit(Resource::As));
#[cfg(not(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "haiku",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
Expand All @@ -65,6 +67,7 @@ fn main() -> io::Result<()> {
#[cfg(not(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "haiku",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
Expand All @@ -75,6 +78,7 @@ fn main() -> io::Result<()> {
#[cfg(not(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "haiku",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
Expand All @@ -85,6 +89,7 @@ fn main() -> io::Result<()> {
#[cfg(not(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "haiku",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
Expand All @@ -95,6 +100,7 @@ fn main() -> io::Result<()> {
#[cfg(not(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "haiku",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
Expand All @@ -107,6 +113,7 @@ fn main() -> io::Result<()> {
target_os = "dragonfly",
target_os = "emscripten",
target_os = "freebsd",
target_os = "haiku",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
Expand Down
18 changes: 14 additions & 4 deletions examples/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,14 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
if (term.c_iflag & IXOFF) != 0 {
print!(" IXOFF");
}
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
#[cfg(not(any(target_os = "haiku", target_os = "ios", target_os = "macos")))]
if (term.c_iflag & IMAXBEL) != 0 {
print!(" IMAXBEL");
}
#[cfg(not(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "macos",
Expand Down Expand Up @@ -276,6 +277,7 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
#[cfg(not(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "haiku",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
Expand All @@ -288,6 +290,7 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
#[cfg(not(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "macos",
Expand Down Expand Up @@ -330,6 +333,7 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
#[cfg(not(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "haiku",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
Expand All @@ -342,6 +346,7 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
#[cfg(not(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "macos",
Expand Down Expand Up @@ -432,20 +437,25 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
term.c_cc[VMIN]
);
println!(
" START={} STOP={} SUSP={} EOL={} REPRINT={} DISCARD={}",
" START={} STOP={} SUSP={} EOL={}",
key(term.c_cc[VSTART]),
key(term.c_cc[VSTOP]),
key(term.c_cc[VSUSP]),
key(term.c_cc[VEOL]),
);
#[cfg(not(target_os = "haiku"))]
println!(
" REPRINT={} DISCARD={}",
key(term.c_cc[VREPRINT]),
key(term.c_cc[VDISCARD])
);
#[cfg(not(target_os = "haiku"))]
println!(
" WERASE={} LNEXT={} EOL2={}",
" WERASE={} VLNEXT={}",
key(term.c_cc[VWERASE]),
key(term.c_cc[VLNEXT]),
key(term.c_cc[VEOL2])
);
println!(" EOL2={}", key(term.c_cc[VEOL2]));
}
} else {
println!(" - is not a tty");
Expand Down
35 changes: 30 additions & 5 deletions src/backend/libc/fs/dir.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use super::super::c;
use super::super::conv::owned_fd;
#[cfg(not(any(target_os = "illumos", target_os = "solaris")))]
#[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))]
use super::types::FileType;
use crate::fd::{AsFd, BorrowedFd};
use crate::ffi::CStr;
#[cfg(target_os = "wasi")]
use crate::ffi::CString;
use crate::fs::{fcntl_getfl, fstat, openat, Mode, OFlags, Stat};
#[cfg(not(any(
target_os = "haiku",
target_os = "illumos",
target_os = "netbsd",
target_os = "redox",
Expand All @@ -16,6 +17,7 @@ use crate::fs::{fcntl_getfl, fstat, openat, Mode, OFlags, Stat};
)))]
use crate::fs::{fstatfs, StatFs};
#[cfg(not(any(
target_os = "haiku",
target_os = "illumos",
target_os = "redox",
target_os = "solaris",
Expand Down Expand Up @@ -137,6 +139,7 @@ impl Dir {

/// `fstatfs(self)`
#[cfg(not(any(
target_os = "haiku",
target_os = "illumos",
target_os = "netbsd",
target_os = "redox",
Expand All @@ -150,6 +153,7 @@ impl Dir {

/// `fstatvfs(self)`
#[cfg(not(any(
target_os = "haiku",
target_os = "illumos",
target_os = "redox",
target_os = "solaris",
Expand All @@ -172,12 +176,13 @@ impl Dir {
// struct, as the name is NUL-terminated and memory may not be allocated for
// the full extent of the struct. Copy the fields one at a time.
unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent {
#[cfg(not(any(target_os = "illumos", target_os = "solaris")))]
#[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))]
let d_type = input.d_type;

#[cfg(not(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "haiku",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
Expand Down Expand Up @@ -217,16 +222,24 @@ unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent {
#[cfg(any(target_os = "ios", target_os = "macos"))]
let d_seekoff = input.d_seekoff;

#[cfg(target_os = "haiku")]
let d_dev = input.d_dev;
#[cfg(target_os = "haiku")]
let d_pdev = input.d_pdev;
#[cfg(target_os = "haiku")]
let d_pino = input.d_pino;

// Construct the input. Rust will give us an error if any OS has a input
// with a field that we missed here. And we can avoid blindly copying the
// whole `d_name` field, which may not be entirely allocated.
#[cfg_attr(target_os = "wasi", allow(unused_mut))]
#[cfg(not(target_os = "dragonfly"))]
let mut dirent = libc_dirent {
#[cfg(not(any(target_os = "illumos", target_os = "solaris")))]
#[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))]
d_type,
#[cfg(not(any(
target_os = "freebsd",
target_os = "haiku",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
Expand Down Expand Up @@ -261,7 +274,19 @@ unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent {
d_name: zeroed(),
#[cfg(target_os = "openbsd")]
__d_padding: zeroed(),
#[cfg(target_os = "haiku")]
d_dev,
#[cfg(target_os = "haiku")]
d_pdev,
#[cfg(target_os = "haiku")]
d_pino,
};
/*
pub d_ino: ino_t,
pub d_pino: i64,
pub d_reclen: ::c_ushort,
pub d_name: [::c_char; 1024], // Max length is _POSIX_PATH_MAX
// */

// On dragonfly, `dirent` has some non-public padding fields so we can't
// directly initialize it.
Expand Down Expand Up @@ -339,7 +364,7 @@ impl DirEntry {
}

/// Returns the type of this directory entry.
#[cfg(not(any(target_os = "illumos", target_os = "solaris")))]
#[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))]
#[inline]
pub fn file_type(&self) -> FileType {
FileType::from_dirent_d_type(self.dirent.d_type)
Expand All @@ -354,7 +379,7 @@ impl DirEntry {
)))]
#[inline]
pub fn ino(&self) -> u64 {
self.dirent.d_ino
self.dirent.d_ino as u64
}

/// Return the inode number of this directory entry.
Expand Down
7 changes: 6 additions & 1 deletion src/backend/libc/fs/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,12 @@ impl FileType {
}

/// Construct a `FileType` from the `d_type` field of a `c::dirent`.
#[cfg(not(any(target_os = "illumos", target_os = "redox", target_os = "solaris")))]
#[cfg(not(any(
target_os = "haiku",
target_os = "illumos",
target_os = "redox",
target_os = "solaris"
)))]
pub(crate) const fn from_dirent_d_type(d_type: u8) -> Self {
match d_type {
c::DT_REG => Self::RegularFile,
Expand Down
Loading

0 comments on commit 3900961

Please sign in to comment.