Skip to content

Commit 6213556

Browse files
committed
Removed impl Whence and assigned the libc values directly in the enum definition.
1 parent 672e9d6 commit 6213556

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

src/unistd.rs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -740,51 +740,37 @@ pub fn write(fd: RawFd, buf: &[u8]) -> Result<usize> {
740740
/// Directive that tells [`lseek`] and [`lseek64`] what the offset is relative to.
741741
/// [`lseek`]: ./fn.lseek.html
742742
/// [`lseek64`]: ./fn.lseek64.html
743+
#[repr(i32)]
743744
pub enum Whence {
744745
/// Specify an offset relative to the start of the file.
745-
SeekSet,
746+
SeekSet = libc::SEEK_SET,
746747
/// Specify an offset relative to the current file location.
747-
SeekCur,
748+
SeekCur = libc::SEEK_CUR,
748749
/// Specify an offset relative to the end of the file.
749-
SeekEnd,
750+
SeekEnd = libc::SEEK_END,
750751
/// Specify an offset relative to the next location in the file greater than or
751752
/// equal to offset that contains some data. If offset points to
752753
/// some data, then the file offset is set to offset.
753754
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))]
754-
SeekData,
755+
SeekData = libc::SEEK_DATA,
755756
/// Specify an offset relative to the next hole in the file greater than
756757
/// or equal to offset. If offset points into the middle of a hole, then
757758
/// the file offset should be set to offset. If there is no hole past offset,
758759
/// then the file offset should be adjusted to the end of the file (i.e., there
759760
/// is an implicit hole at the end of any file).
760761
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))]
761-
SeekHole
762-
}
763-
764-
impl Whence {
765-
fn to_libc_type(&self) -> c_int {
766-
match self {
767-
&Whence::SeekSet => libc::SEEK_SET,
768-
&Whence::SeekCur => libc::SEEK_CUR,
769-
&Whence::SeekEnd => libc::SEEK_END,
770-
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))]
771-
&Whence::SeekData => libc::SEEK_DATA,
772-
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))]
773-
&Whence::SeekHole => libc::SEEK_HOLE
774-
}
775-
}
776-
762+
SeekHole = libc::SEEK_HOLE
777763
}
778764

779765
pub fn lseek(fd: RawFd, offset: libc::off_t, whence: Whence) -> Result<libc::off_t> {
780-
let res = unsafe { libc::lseek(fd, offset, whence.to_libc_type()) };
766+
let res = unsafe { libc::lseek(fd, offset, whence as i32) };
781767

782768
Errno::result(res).map(|r| r as libc::off_t)
783769
}
784770

785771
#[cfg(any(target_os = "linux", target_os = "android"))]
786772
pub fn lseek64(fd: RawFd, offset: libc::off64_t, whence: Whence) -> Result<libc::off64_t> {
787-
let res = unsafe { libc::lseek64(fd, offset, whence.to_libc_type()) };
773+
let res = unsafe { libc::lseek64(fd, offset, whence as i32) };
788774

789775
Errno::result(res).map(|r| r as libc::off64_t)
790776
}

0 commit comments

Comments
 (0)