This is the mail archive of the
cygwin-patches@cygwin.com
mailing list for the Cygwin project.
Re: [Patch]: Truncate
At 01:00 PM 8/23/2004 +0200, Corinna Vinschen wrote:
>Except for this comment, which isn't valid (see above), please check it in.
Done. But here is another simple patch taking care of your concern that
we can fail while zero filling, leaving the file system filled to capacity.
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.
Index: fhandler.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler.cc,v
retrieving revision 1.203
diff -u -p -r1.203 fhandler.cc
--- fhandler.cc 19 Aug 2004 15:47:51 -0000 1.203
+++ fhandler.cc 28 Aug 2004 01:37:53 -0000
@@ -815,11 +815,17 @@ fhandler_base::write (const void *ptr, s
back and fill in the gap with zeros. - DJ
Note: this bug doesn't happen on NT4, even though the
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];
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
@@ -831,6 +837,7 @@ fhandler_base::write (const void *ptr, s
__seterrno ();
if (get_errno () == EPIPE)
raise (SIGPIPE);
+ err:
/* This might fail, but it's the best we can hope for */
SetFilePointer (get_output_handle (),
current_position, NULL,
FILE_BEGIN);
@@ -840,10 +847,7 @@ fhandler_base::write (const void *ptr, s
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;
+ goto err;
}
number_of_zeros_to_write -= written;
}