55
66// spell-checker:ignore lseek seekable
77
8- use nix:: fcntl:: { FcntlArg , OFlag , fcntl} ;
9- use nix:: unistd:: { Whence , lseek} ;
8+ use rustix:: fs:: { OFlags , SeekFrom , fcntl_getfl} ;
109use std:: os:: fd:: AsFd ;
1110use uucore:: fs:: FileInformation ;
1211
@@ -31,10 +30,10 @@ pub fn is_unsafe_overwrite<I: AsFd, O: AsFd>(input: &I, output: &O) -> bool {
3130 if file_size == 0 {
3231 return false ;
3332 }
34- // `lseek ` returns an error if the file descriptor is closed or it refers to
33+ // `seek ` returns an error if the file descriptor is closed or it refers to
3534 // a non-seekable resource (e.g., pipe, socket, or some devices).
36- let input_pos = lseek ( input. as_fd ( ) , 0 , Whence :: SeekCur ) ;
37- let output_pos = lseek ( output. as_fd ( ) , 0 , Whence :: SeekCur ) ;
35+ let input_pos = rustix :: fs :: seek ( input, SeekFrom :: Current ( 0 ) ) . map ( |v| v as i64 ) ;
36+ let output_pos = rustix :: fs :: seek ( output, SeekFrom :: Current ( 0 ) ) . map ( |v| v as i64 ) ;
3837 if is_appending ( output) {
3938 if let Ok ( pos) = input_pos {
4039 if pos >= 0 && ( pos as u64 ) >= file_size {
@@ -54,9 +53,8 @@ pub fn is_unsafe_overwrite<I: AsFd, O: AsFd>(input: &I, output: &O) -> bool {
5453
5554/// Whether the file is opened with the `O_APPEND` flag
5655fn is_appending < F : AsFd > ( file : & F ) -> bool {
57- let flags_raw = fcntl ( file. as_fd ( ) , FcntlArg :: F_GETFL ) . unwrap_or_default ( ) ;
58- let flags = OFlag :: from_bits_truncate ( flags_raw) ;
59- flags. contains ( OFlag :: O_APPEND )
56+ let flags = fcntl_getfl ( file) . unwrap_or ( OFlags :: empty ( ) ) ;
57+ flags. contains ( OFlags :: APPEND )
6058}
6159
6260#[ cfg( test) ]
0 commit comments