Skip to content

Commit

Permalink
Expose SeekData and SeedHole on all Linux targets
Browse files Browse the repository at this point in the history
These were previously missing on musl and mips targets because of
missing definitions in the libc crate.
  • Loading branch information
Amanieu committed Aug 5, 2020
1 parent 96054b6 commit 0a5c371
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,19 @@ pub fn write(fd: RawFd, buf: &[u8]) -> Result<usize> {
Errno::result(res).map(|r| r as usize)
}

// Hard-code constants for Linux since they are not exposed on all target by the
// libc crate. This is fine since these constants are part of the stable kernel
// ABI.
cfg_if! {
if #[cfg(target_os = "linux")] {
const SEEK_DATA: i32 = 3;
const SEEK_HOLE: i32 = 4;
} else if #[cfg(any(target_os = "dragonfly", target_os = "freebsd"))] {
const SEEK_DATA: i32 = libc::SEEK_DATA;
const SEEK_HOLE: i32 = libc::SEEK_HOLE;
}
}

/// Directive that tells [`lseek`] and [`lseek64`] what the offset is relative to.
///
/// [`lseek`]: ./fn.lseek.html
Expand All @@ -1018,21 +1031,15 @@ pub enum Whence {
/// Specify an offset relative to the next location in the file greater than or
/// equal to offset that contains some data. If offset points to
/// some data, then the file offset is set to offset.
#[cfg(any(target_os = "dragonfly", target_os = "freebsd",
all(target_os = "linux", not(any(target_env = "musl",
target_arch = "mips",
target_arch = "mips64")))))]
SeekData = libc::SEEK_DATA,
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
SeekData = SEEK_DATA,
/// Specify an offset relative to the next hole in the file greater than
/// or equal to offset. If offset points into the middle of a hole, then
/// the file offset should be set to offset. If there is no hole past offset,
/// then the file offset should be adjusted to the end of the file (i.e., there
/// is an implicit hole at the end of any file).
#[cfg(any(target_os = "dragonfly", target_os = "freebsd",
all(target_os = "linux", not(any(target_env = "musl",
target_arch = "mips",
target_arch = "mips64")))))]
SeekHole = libc::SEEK_HOLE
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
SeekHole = SEEK_HOLE,
}

/// Move the read/write file offset.
Expand Down

0 comments on commit 0a5c371

Please sign in to comment.