Skip to content

Commit d3158ed

Browse files
authored
Add GNU/Hurd support (#844)
1 parent 9247191 commit d3158ed

File tree

10 files changed

+88
-13
lines changed

10 files changed

+88
-13
lines changed

examples/stdio.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
123123
target_os = "aix",
124124
target_os = "emscripten",
125125
target_os = "haiku",
126+
target_os = "hurd",
126127
target_os = "redox",
127128
)))]
128129
if term.input_modes.contains(InputModes::IUTF8) {
@@ -217,6 +218,7 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
217218
solarish,
218219
target_os = "emscripten",
219220
target_os = "haiku",
221+
target_os = "hurd",
220222
target_os = "redox",
221223
)))]
222224
if term.control_modes.contains(ControlModes::CMSPAR) {
@@ -297,6 +299,7 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
297299
solarish,
298300
target_os = "aix",
299301
target_os = "haiku",
302+
target_os = "hurd",
300303
target_os = "nto",
301304
)))]
302305
println!(

src/backend/libc/c.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ pub(super) use libc::fallocate64 as fallocate;
109109
#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
110110
#[cfg(any(linux_like, target_os = "aix"))]
111111
pub(super) use libc::open64 as open;
112-
#[cfg(any(linux_kernel, target_os = "aix", target_os = "l4re"))]
112+
#[cfg(any(
113+
linux_kernel,
114+
target_os = "aix",
115+
target_os = "hurd",
116+
target_os = "l4re"
117+
))]
113118
pub(super) use libc::posix_fallocate64 as posix_fallocate;
114119
#[cfg(any(all(linux_like, not(target_os = "android")), target_os = "aix"))]
115120
pub(super) use libc::{blkcnt64_t as blkcnt_t, rlim64_t as rlim_t};
@@ -123,7 +128,7 @@ pub(super) use libc::{
123128
rlimit64 as rlimit, setrlimit64 as setrlimit, statfs64 as statfs, statvfs64 as statvfs,
124129
RLIM_INFINITY,
125130
};
126-
#[cfg(linux_like)]
131+
#[cfg(any(linux_like, target_os = "hurd"))]
127132
pub(super) use libc::{
128133
fstat64 as fstat, fstatat64 as fstatat, fstatfs64 as fstatfs, fstatvfs64 as fstatvfs,
129134
ftruncate64 as ftruncate, getrlimit64 as getrlimit, ino64_t as ino_t, lseek64 as lseek,
@@ -144,11 +149,16 @@ pub(super) use libc::{
144149
target_arch = "mips64r6"
145150
)
146151
)))]
147-
#[cfg(any(linux_like, target_os = "aix"))]
152+
#[cfg(any(linux_like, target_os = "aix", target_os = "hurd"))]
148153
pub(super) use libc::{lstat64 as lstat, stat64 as stat};
149-
#[cfg(any(linux_kernel, target_os = "aix", target_os = "emscripten"))]
154+
#[cfg(any(
155+
linux_kernel,
156+
target_os = "aix",
157+
target_os = "hurd",
158+
target_os = "emscripten"
159+
))]
150160
pub(super) use libc::{pread64 as pread, pwrite64 as pwrite};
151-
#[cfg(any(target_os = "linux", target_os = "emscripten"))]
161+
#[cfg(any(target_os = "linux", target_os = "hurd", target_os = "emscripten"))]
152162
pub(super) use libc::{preadv64 as preadv, pwritev64 as pwritev};
153163

154164
#[cfg(all(target_os = "linux", target_env = "gnu"))]

src/backend/libc/fs/dir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ use crate::io;
2121
#[cfg(feature = "process")]
2222
use crate::process::fchdir;
2323
use alloc::borrow::ToOwned;
24-
#[cfg(not(linux_like))]
24+
#[cfg(not(any(linux_like, target_os = "hurd")))]
2525
use c::readdir as libc_readdir;
26-
#[cfg(linux_like)]
26+
#[cfg(any(linux_like, target_os = "hurd"))]
2727
use c::readdir64 as libc_readdir;
2828
use core::fmt;
2929
use core::ptr::NonNull;

src/backend/libc/fs/syscalls.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ fn open_via_syscall(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<Owned
125125
pub(crate) fn open(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<OwnedFd> {
126126
// Work around <https://sourceware.org/bugzilla/show_bug.cgi?id=17523>.
127127
// glibc versions before 2.25 don't handle `O_TMPFILE` correctly.
128-
#[cfg(all(unix, target_env = "gnu"))]
128+
#[cfg(all(unix, target_env = "gnu", not(target_os = "hurd")))]
129129
if oflags.contains(OFlags::TMPFILE) && crate::backend::if_glibc_is_less_than_2_25() {
130130
return open_via_syscall(path, oflags, mode);
131131
}
@@ -153,7 +153,7 @@ pub(crate) fn open(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<OwnedF
153153
/// Use a direct syscall (via libc) for `openat`.
154154
///
155155
/// This is only currently necessary as a workaround for old glibc; see below.
156-
#[cfg(all(unix, target_env = "gnu"))]
156+
#[cfg(all(unix, target_env = "gnu", not(target_os = "hurd")))]
157157
fn openat_via_syscall(
158158
dirfd: BorrowedFd<'_>,
159159
path: &CStr,
@@ -188,7 +188,7 @@ pub(crate) fn openat(
188188
) -> io::Result<OwnedFd> {
189189
// Work around <https://sourceware.org/bugzilla/show_bug.cgi?id=17523>.
190190
// glibc versions before 2.25 don't handle `O_TMPFILE` correctly.
191-
#[cfg(all(unix, target_env = "gnu"))]
191+
#[cfg(all(unix, target_env = "gnu", not(target_os = "hurd")))]
192192
if oflags.contains(OFlags::TMPFILE) && crate::backend::if_glibc_is_less_than_2_25() {
193193
return openat_via_syscall(dirfd, path, oflags, mode);
194194
}

src/backend/libc/fs/types.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ bitflags! {
797797
bsd,
798798
target_os = "aix",
799799
target_os = "haiku",
800+
target_os = "hurd",
800801
target_os = "wasi",
801802
)))]
802803
const KEEP_SIZE = bitcast!(c::FALLOC_FL_KEEP_SIZE);
@@ -805,6 +806,7 @@ bitflags! {
805806
bsd,
806807
target_os = "aix",
807808
target_os = "haiku",
809+
target_os = "hurd",
808810
target_os = "wasi",
809811
)))]
810812
const PUNCH_HOLE = bitcast!(c::FALLOC_FL_PUNCH_HOLE);
@@ -815,6 +817,7 @@ bitflags! {
815817
target_os = "emscripten",
816818
target_os = "fuchsia",
817819
target_os = "haiku",
820+
target_os = "hurd",
818821
target_os = "l4re",
819822
target_os = "linux",
820823
target_os = "wasi",
@@ -825,6 +828,7 @@ bitflags! {
825828
bsd,
826829
target_os = "aix",
827830
target_os = "haiku",
831+
target_os = "hurd",
828832
target_os = "emscripten",
829833
target_os = "wasi",
830834
)))]
@@ -834,6 +838,7 @@ bitflags! {
834838
bsd,
835839
target_os = "aix",
836840
target_os = "haiku",
841+
target_os = "hurd",
837842
target_os = "emscripten",
838843
target_os = "wasi",
839844
)))]
@@ -843,6 +848,7 @@ bitflags! {
843848
bsd,
844849
target_os = "aix",
845850
target_os = "haiku",
851+
target_os = "hurd",
846852
target_os = "emscripten",
847853
target_os = "wasi",
848854
)))]
@@ -852,6 +858,7 @@ bitflags! {
852858
bsd,
853859
target_os = "aix",
854860
target_os = "haiku",
861+
target_os = "hurd",
855862
target_os = "emscripten",
856863
target_os = "wasi",
857864
)))]
@@ -940,7 +947,7 @@ pub enum FlockOperation {
940947
///
941948
/// [`statat`]: crate::fs::statat
942949
/// [`fstat`]: crate::fs::fstat
943-
#[cfg(not(linux_like))]
950+
#[cfg(not(any(linux_like, target_os = "hurd")))]
944951
pub type Stat = c::stat;
945952

946953
/// `struct stat` for use with [`statat`] and [`fstat`].
@@ -949,6 +956,7 @@ pub type Stat = c::stat;
949956
/// [`fstat`]: crate::fs::fstat
950957
#[cfg(any(
951958
all(linux_kernel, target_pointer_width = "64"),
959+
target_os = "hurd",
952960
target_os = "emscripten",
953961
target_os = "l4re",
954962
))]

0 commit comments

Comments
 (0)