Skip to content

Commit dcb12dd

Browse files
committed
Cygwin: fhandler_base::open: move O_TRUNC comment into O_TRUNC case
Signed-off-by: Corinna Vinschen <[email protected]> (cherry picked from commit 9e61935)
1 parent f85d881 commit dcb12dd

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

winsup/cygwin/fhandler/base.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -769,18 +769,17 @@ fhandler_base::open (int flags, mode_t mode)
769769
set_created_file_access (fh, pc, mode);
770770
}
771771

772-
/* If you O_TRUNC a file on Linux, the data is truncated, but the EAs are
773-
preserved. If you open a file on Windows with FILE_OVERWRITE{_IF} or
774-
FILE_SUPERSEDE, all streams are truncated, including the EAs. So we don't
775-
use the FILE_OVERWRITE{_IF} flags, but instead just open the file and set
776-
the size of the data stream explicitely to 0. Apart from being more Linux
777-
compatible, this implementation has the pleasant side-effect to be more
778-
than 5% faster than using FILE_OVERWRITE{_IF} (tested on W7 32 bit). */
779772
if ((flags & O_TRUNC)
780773
&& (flags & O_ACCMODE) != O_RDONLY
781774
&& io.Information != FILE_CREATED
782775
&& get_device () == FH_FS)
783776
{
777+
/* If you O_TRUNC a file on Linux, the data is truncated, but the EAs are
778+
preserved. If you open a file on Windows with FILE_OVERWRITE{_IF} or
779+
FILE_SUPERSEDE, all streams are truncated, including the EAs. So we
780+
don't use FILE_OVERWRITE{_IF} but just open the file and truncate the
781+
data stream to size 0. Apart from being more Linux compatible, this
782+
has the pleasant side-effect to be more than 5% faster. */
784783
FILE_END_OF_FILE_INFORMATION feofi = { EndOfFile:{ QuadPart:0 } };
785784
status = NtSetInformationFile (fh, &io, &feofi, sizeof feofi,
786785
FileEndOfFileInformation);

0 commit comments

Comments
 (0)