diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2004-08-28 15:46:57 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2004-08-28 15:46:57 +0000 |
commit | ddea76a66b39e79b6fd4a728e0e0980841f215d9 (patch) | |
tree | 9cea255f00b6acaf6074dac25902d3c9d274d871 /winsup/cygwin/fhandler.cc | |
parent | 2e41976b562f37a3a03372058798073563e09239 (diff) | |
download | cygnal-ddea76a66b39e79b6fd4a728e0e0980841f215d9.tar.gz cygnal-ddea76a66b39e79b6fd4a728e0e0980841f215d9.tar.bz2 cygnal-ddea76a66b39e79b6fd4a728e0e0980841f215d9.zip |
* fhandler.cc (fhandler_base::write): In the lseek_bug case, set EOF
before zero filling. Combine similar error handling statements.
Diffstat (limited to 'winsup/cygwin/fhandler.cc')
-rw-r--r-- | winsup/cygwin/fhandler.cc | 37 |
1 files changed, 21 insertions, 16 deletions
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; } } |