@@ -740,51 +740,37 @@ pub fn write(fd: RawFd, buf: &[u8]) -> Result<usize> {
740
740
/// Directive that tells [`lseek`] and [`lseek64`] what the offset is relative to.
741
741
/// [`lseek`]: ./fn.lseek.html
742
742
/// [`lseek64`]: ./fn.lseek64.html
743
+ #[ repr( i32 ) ]
743
744
pub enum Whence {
744
745
/// Specify an offset relative to the start of the file.
745
- SeekSet ,
746
+ SeekSet = libc :: SEEK_SET ,
746
747
/// Specify an offset relative to the current file location.
747
- SeekCur ,
748
+ SeekCur = libc :: SEEK_CUR ,
748
749
/// Specify an offset relative to the end of the file.
749
- SeekEnd ,
750
+ SeekEnd = libc :: SEEK_END ,
750
751
/// Specify an offset relative to the next location in the file greater than or
751
752
/// equal to offset that contains some data. If offset points to
752
753
/// some data, then the file offset is set to offset.
753
754
#[ cfg( any( target_os = "linux" , target_os = "dragonfly" , target_os = "freebsd" ) ) ]
754
- SeekData ,
755
+ SeekData = libc :: SEEK_DATA ,
755
756
/// Specify an offset relative to the next hole in the file greater than
756
757
/// or equal to offset. If offset points into the middle of a hole, then
757
758
/// the file offset should be set to offset. If there is no hole past offset,
758
759
/// then the file offset should be adjusted to the end of the file (i.e., there
759
760
/// is an implicit hole at the end of any file).
760
761
#[ 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
777
763
}
778
764
779
765
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 ) } ;
781
767
782
768
Errno :: result ( res) . map ( |r| r as libc:: off_t )
783
769
}
784
770
785
771
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
786
772
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 ) } ;
788
774
789
775
Errno :: result ( res) . map ( |r| r as libc:: off64_t )
790
776
}
0 commit comments