@@ -737,36 +737,46 @@ pub fn write(fd: RawFd, buf: &[u8]) -> Result<usize> {
737
737
Errno :: result ( res) . map ( |r| r as usize )
738
738
}
739
739
740
+ /// Directive that tells [`lseek`] and [`lseek64`] what the offset is relative to.
741
+ /// [`lseek`]: ./fn.lseek.html
742
+ /// [`lseek64`]: ./fn.lseek64.html
743
+ #[ repr( i32 ) ]
740
744
pub enum Whence {
741
- SeekSet ,
742
- SeekCur ,
743
- SeekEnd ,
744
- SeekData ,
745
- SeekHole
746
- }
747
-
748
- impl Whence {
749
- fn to_libc_type ( & self ) -> c_int {
750
- match self {
751
- & Whence :: SeekSet => libc:: SEEK_SET ,
752
- & Whence :: SeekCur => libc:: SEEK_CUR ,
753
- & Whence :: SeekEnd => libc:: SEEK_END ,
754
- & Whence :: SeekData => 3 ,
755
- & Whence :: SeekHole => 4
756
- }
757
- }
758
-
745
+ /// Specify an offset relative to the start of the file.
746
+ SeekSet = libc:: SEEK_SET ,
747
+ /// Specify an offset relative to the current file location.
748
+ SeekCur = libc:: SEEK_CUR ,
749
+ /// Specify an offset relative to the end of the file.
750
+ SeekEnd = libc:: SEEK_END ,
751
+ /// Specify an offset relative to the next location in the file greater than or
752
+ /// equal to offset that contains some data. If offset points to
753
+ /// some data, then the file offset is set to offset.
754
+ #[ cfg( any( target_os = "dragonfly" , target_os = "freebsd" ,
755
+ all( target_os = "linux" , not( any( target_env = "musl" ,
756
+ target_arch = "mips" ,
757
+ target_arch = "mips64" ) ) ) ) ) ]
758
+ SeekData = libc:: SEEK_DATA ,
759
+ /// Specify an offset relative to the next hole in the file greater than
760
+ /// or equal to offset. If offset points into the middle of a hole, then
761
+ /// the file offset should be set to offset. If there is no hole past offset,
762
+ /// then the file offset should be adjusted to the end of the file (i.e., there
763
+ /// is an implicit hole at the end of any file).
764
+ #[ cfg( any( target_os = "dragonfly" , target_os = "freebsd" ,
765
+ all( target_os = "linux" , not( any( target_env = "musl" ,
766
+ target_arch = "mips" ,
767
+ target_arch = "mips64" ) ) ) ) ) ]
768
+ SeekHole = libc:: SEEK_HOLE
759
769
}
760
770
761
771
pub fn lseek ( fd : RawFd , offset : libc:: off_t , whence : Whence ) -> Result < libc:: off_t > {
762
- let res = unsafe { libc:: lseek ( fd, offset, whence. to_libc_type ( ) ) } ;
772
+ let res = unsafe { libc:: lseek ( fd, offset, whence as i32 ) } ;
763
773
764
774
Errno :: result ( res) . map ( |r| r as libc:: off_t )
765
775
}
766
776
767
777
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
768
778
pub fn lseek64 ( fd : RawFd , offset : libc:: off64_t , whence : Whence ) -> Result < libc:: off64_t > {
769
- let res = unsafe { libc:: lseek64 ( fd, offset, whence. to_libc_type ( ) ) } ;
779
+ let res = unsafe { libc:: lseek64 ( fd, offset, whence as i32 ) } ;
770
780
771
781
Errno :: result ( res) . map ( |r| r as libc:: off64_t )
772
782
}
0 commit comments