[newlib-cygwin/main] Cygwin: fhandler_base::open: move O_TRUNC comment into O_TRUNC case
Corinna Vinschen
corinna@sourceware.org
Tue Apr 8 14:07:26 GMT 2025
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=9e6193576f341f1d1a8caefb7a4ae4b7b5407e74
commit 9e6193576f341f1d1a8caefb7a4ae4b7b5407e74
Author: Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Tue Apr 8 15:54:42 2025 +0200
Commit: Corinna Vinschen <corinna@vinschen.de>
CommitDate: Tue Apr 8 16:06:20 2025 +0200
Cygwin: fhandler_base::open: move O_TRUNC comment into O_TRUNC case
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diff:
---
winsup/cygwin/fhandler/base.cc | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/winsup/cygwin/fhandler/base.cc b/winsup/cygwin/fhandler/base.cc
index 36d814bf3543..32aca2c51a62 100644
--- a/winsup/cygwin/fhandler/base.cc
+++ b/winsup/cygwin/fhandler/base.cc
@@ -769,18 +769,17 @@ fhandler_base::open (int flags, mode_t mode)
set_created_file_access (fh, pc, mode);
}
- /* If you O_TRUNC a file on Linux, the data is truncated, but the EAs are
- preserved. If you open a file on Windows with FILE_OVERWRITE{_IF} or
- FILE_SUPERSEDE, all streams are truncated, including the EAs. So we don't
- use the FILE_OVERWRITE{_IF} flags, but instead just open the file and set
- the size of the data stream explicitely to 0. Apart from being more Linux
- compatible, this implementation has the pleasant side-effect to be more
- than 5% faster than using FILE_OVERWRITE{_IF} (tested on W7 32 bit). */
if ((flags & O_TRUNC)
&& (flags & O_ACCMODE) != O_RDONLY
&& io.Information != FILE_CREATED
&& get_device () == FH_FS)
{
+ /* If you O_TRUNC a file on Linux, the data is truncated, but the EAs are
+ preserved. If you open a file on Windows with FILE_OVERWRITE{_IF} or
+ FILE_SUPERSEDE, all streams are truncated, including the EAs. So we
+ don't use FILE_OVERWRITE{_IF} but just open the file and truncate the
+ data stream to size 0. Apart from being more Linux compatible, this
+ has the pleasant side-effect to be more than 5% faster. */
FILE_END_OF_FILE_INFORMATION feofi = { EndOfFile:{ QuadPart:0 } };
status = NtSetInformationFile (fh, &io, &feofi, sizeof feofi,
FileEndOfFileInformation);
More information about the Cygwin-cvs
mailing list