OSDN Git Service

* fhandler.cc (fhandler_base::write): In the lseek_bug case, set EOF
authorcorinna <corinna>
Sat, 28 Aug 2004 15:46:57 +0000 (15:46 +0000)
committercorinna <corinna>
Sat, 28 Aug 2004 15:46:57 +0000 (15:46 +0000)
before zero filling. Combine similar error handling statements.

winsup/cygwin/ChangeLog
winsup/cygwin/fhandler.cc

index c0a4581..f2c80e9 100644 (file)
@@ -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.
 
index 97b01eb..3dd549c 100644 (file)
@@ -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;
                }
            }