Skip to content

Commit 0a5c371

Browse files
committed
Expose SeekData and SeedHole on all Linux targets
These were previously missing on musl and mips targets because of missing definitions in the libc crate.
1 parent 96054b6 commit 0a5c371

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/unistd.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,19 @@ pub fn write(fd: RawFd, buf: &[u8]) -> Result<usize> {
10021002
Errno::result(res).map(|r| r as usize)
10031003
}
10041004

1005+
// Hard-code constants for Linux since they are not exposed on all target by the
1006+
// libc crate. This is fine since these constants are part of the stable kernel
1007+
// ABI.
1008+
cfg_if! {
1009+
if #[cfg(target_os = "linux")] {
1010+
const SEEK_DATA: i32 = 3;
1011+
const SEEK_HOLE: i32 = 4;
1012+
} else if #[cfg(any(target_os = "dragonfly", target_os = "freebsd"))] {
1013+
const SEEK_DATA: i32 = libc::SEEK_DATA;
1014+
const SEEK_HOLE: i32 = libc::SEEK_HOLE;
1015+
}
1016+
}
1017+
10051018
/// Directive that tells [`lseek`] and [`lseek64`] what the offset is relative to.
10061019
///
10071020
/// [`lseek`]: ./fn.lseek.html
@@ -1018,21 +1031,15 @@ pub enum Whence {
10181031
/// Specify an offset relative to the next location in the file greater than or
10191032
/// equal to offset that contains some data. If offset points to
10201033
/// some data, then the file offset is set to offset.
1021-
#[cfg(any(target_os = "dragonfly", target_os = "freebsd",
1022-
all(target_os = "linux", not(any(target_env = "musl",
1023-
target_arch = "mips",
1024-
target_arch = "mips64")))))]
1025-
SeekData = libc::SEEK_DATA,
1034+
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
1035+
SeekData = SEEK_DATA,
10261036
/// Specify an offset relative to the next hole in the file greater than
10271037
/// or equal to offset. If offset points into the middle of a hole, then
10281038
/// the file offset should be set to offset. If there is no hole past offset,
10291039
/// then the file offset should be adjusted to the end of the file (i.e., there
10301040
/// is an implicit hole at the end of any file).
1031-
#[cfg(any(target_os = "dragonfly", target_os = "freebsd",
1032-
all(target_os = "linux", not(any(target_env = "musl",
1033-
target_arch = "mips",
1034-
target_arch = "mips64")))))]
1035-
SeekHole = libc::SEEK_HOLE
1041+
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
1042+
SeekHole = SEEK_HOLE,
10361043
}
10371044

10381045
/// Move the read/write file offset.

0 commit comments

Comments
 (0)