Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2004-08-28 19:46:57 +0400
committerCorinna Vinschen <corinna@vinschen.de>2004-08-28 19:46:57 +0400
commitddea76a66b39e79b6fd4a728e0e0980841f215d9 (patch)
tree9cea255f00b6acaf6074dac25902d3c9d274d871 /winsup
parent2e41976b562f37a3a03372058798073563e09239 (diff)
* fhandler.cc (fhandler_base::write): In the lseek_bug case, set EOF
before zero filling. Combine similar error handling statements.
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/ChangeLog5
-rw-r--r--winsup/cygwin/fhandler.cc37
2 files changed, 26 insertions, 16 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index c0a458131..f2c80e96d 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,10 @@
2004-08-28 Pierre Humblet <pierre.humblet@ieee.org>
+ * fhandler.cc (fhandler_base::write): In the lseek_bug case, set EOF
+ before zero filling. Combine similar error handling statements.
+
+2004-08-28 Pierre Humblet <pierre.humblet@ieee.org>
+
* syscalls.cc (ftruncate64): On 9x, call write with a zero length
to zero fill when the file is extended.
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index 97b01eb64..3dd549c41 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -816,35 +816,40 @@ fhandler_base::write (const void *ptr, size_t len)
Note: this bug doesn't happen on NT4, even though the
documentation for WriteFile() says that it *may* happen
on any OS. */
+ /* Check there is enough space */
+ if (!SetEndOfFile (get_output_handle ()))
+ {
+ __seterrno ();
+ return -1;
+ }
char zeros[512];
int number_of_zeros_to_write = current_position - actual_length;
memset (zeros, 0, 512);
- SetFilePointer (get_output_handle (), 0, NULL, FILE_END);
+ SetFilePointer (get_output_handle (), actual_length, NULL,
+ FILE_BEGIN);
while (number_of_zeros_to_write > 0)
{
DWORD zeros_this_time = (number_of_zeros_to_write > 512
? 512 : number_of_zeros_to_write);
DWORD written;
- if (!WriteFile (get_output_handle (), zeros, zeros_this_time,
- &written, NULL))
+ DWORD ret = WriteFile (get_output_handle (), zeros,
+ zeros_this_time, &written, NULL);
+ if (!ret || written < zeros_this_time)
{
- __seterrno ();
- if (get_errno () == EPIPE)
- raise (SIGPIPE);
+ if (!ret)
+ {
+ __seterrno ();
+ if (get_errno () == EPIPE)
+ raise (SIGPIPE);
+ }
+ else
+ set_errno (ENOSPC);
/* This might fail, but it's the best we can hope for */
- SetFilePointer (get_output_handle (), current_position, NULL,
- FILE_BEGIN);
+ SetFilePointer (get_output_handle (), current_position,
+ NULL, FILE_BEGIN);
return -1;
}
- if (written < zeros_this_time) /* just in case */
- {
- set_errno (ENOSPC);
- /* This might fail, but it's the best we can hope for */
- SetFilePointer (get_output_handle (), current_position, NULL,
- FILE_BEGIN);
- return -1;
- }
number_of_zeros_to_write -= written;
}
}