mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-18 23:12:15 +08:00
* fhandler.cc (fhandler_base::write): In the lseek_bug case, set EOF
before zero filling. Combine similar error handling statements.
This commit is contained in:
parent
2e41976b56
commit
ddea76a66b
@ -1,3 +1,8 @@
|
|||||||
|
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>
|
2004-08-28 Pierre Humblet <pierre.humblet@ieee.org>
|
||||||
|
|
||||||
* syscalls.cc (ftruncate64): On 9x, call write with a zero length
|
* syscalls.cc (ftruncate64): On 9x, call write with a zero length
|
||||||
|
@ -816,34 +816,39 @@ fhandler_base::write (const void *ptr, size_t len)
|
|||||||
Note: this bug doesn't happen on NT4, even though the
|
Note: this bug doesn't happen on NT4, even though the
|
||||||
documentation for WriteFile() says that it *may* happen
|
documentation for WriteFile() says that it *may* happen
|
||||||
on any OS. */
|
on any OS. */
|
||||||
|
/* Check there is enough space */
|
||||||
|
if (!SetEndOfFile (get_output_handle ()))
|
||||||
|
{
|
||||||
|
__seterrno ();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
char zeros[512];
|
char zeros[512];
|
||||||
int number_of_zeros_to_write = current_position - actual_length;
|
int number_of_zeros_to_write = current_position - actual_length;
|
||||||
memset (zeros, 0, 512);
|
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)
|
while (number_of_zeros_to_write > 0)
|
||||||
{
|
{
|
||||||
DWORD zeros_this_time = (number_of_zeros_to_write > 512
|
DWORD zeros_this_time = (number_of_zeros_to_write > 512
|
||||||
? 512 : number_of_zeros_to_write);
|
? 512 : number_of_zeros_to_write);
|
||||||
DWORD written;
|
DWORD written;
|
||||||
if (!WriteFile (get_output_handle (), zeros, zeros_this_time,
|
DWORD ret = WriteFile (get_output_handle (), zeros,
|
||||||
&written, NULL))
|
zeros_this_time, &written, NULL);
|
||||||
|
if (!ret || written < zeros_this_time)
|
||||||
|
{
|
||||||
|
if (!ret)
|
||||||
{
|
{
|
||||||
__seterrno ();
|
__seterrno ();
|
||||||
if (get_errno () == EPIPE)
|
if (get_errno () == EPIPE)
|
||||||
raise (SIGPIPE);
|
raise (SIGPIPE);
|
||||||
/* This might fail, but it's the best we can hope for */
|
|
||||||
SetFilePointer (get_output_handle (), current_position, NULL,
|
|
||||||
FILE_BEGIN);
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if (written < zeros_this_time) /* just in case */
|
else
|
||||||
{
|
|
||||||
set_errno (ENOSPC);
|
set_errno (ENOSPC);
|
||||||
/* This might fail, but it's the best we can hope for */
|
/* This might fail, but it's the best we can hope for */
|
||||||
SetFilePointer (get_output_handle (), current_position, NULL,
|
SetFilePointer (get_output_handle (), current_position,
|
||||||
FILE_BEGIN);
|
NULL, FILE_BEGIN);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
number_of_zeros_to_write -= written;
|
number_of_zeros_to_write -= written;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user