@@ -737,36 +737,40 @@ 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" , target_os = "linux" ) ) ]
755
+ SeekData = libc:: SEEK_DATA ,
756
+ /// Specify an offset relative to the next hole in the file greater than
757
+ /// or equal to offset. If offset points into the middle of a hole, then
758
+ /// the file offset should be set to offset. If there is no hole past offset ,
759
+ /// then the file offset should be adjusted to the end of the file (i.e., there
760
+ /// is an implicit hole at the end of any file).
761
+ # [ cfg ( any ( target_os = "dragonfly" , target_os = "freebsd" , target_os = "linux" ) ) ]
762
+ SeekHole = libc :: SEEK_HOLE
759
763
}
760
764
761
765
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 ( ) ) } ;
766
+ let res = unsafe { libc:: lseek ( fd, offset, whence as i32 ) } ;
763
767
764
768
Errno :: result ( res) . map ( |r| r as libc:: off_t )
765
769
}
766
770
767
771
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
768
772
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 ( ) ) } ;
773
+ let res = unsafe { libc:: lseek64 ( fd, offset, whence as i32 ) } ;
770
774
771
775
Errno :: result ( res) . map ( |r| r as libc:: off64_t )
772
776
}
0 commit comments