2014-04-01 Richard Biener <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 1 Apr 2014 07:45:48 +0000 (07:45 +0000)
committerTom Tromey <tromey@redhat.com>
Thu, 8 May 2014 16:18:30 +0000 (10:18 -0600)
libiberty/
* simple-object.c (simple_object_internal_write): Handle
EINTR and short writes.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@208972 138bc75d-0d04-0410-961f-82ee72b054a4

libiberty/ChangeLog
libiberty/simple-object.c

index f20fac0aabbce3487f13567783dc3a495144b670..89e9bf953de21ab64d881cd9a1d014177d0f0a20 100644 (file)
@@ -1,3 +1,8 @@
+2014-04-01  Richard Biener  <rguenther@suse.de>
+
+       * simple-object.c (simple_object_internal_write): Handle
+       EINTR and short writes.
+
 2014-03-28  Richard Biener  <rguenther@suse.de>
 
        * simple-object.c (simple_object_internal_read): Handle
index 263d174051dafef741fb9627c1f0b18aeccb4ca3..5d379d053c419cfacf812ba89e60fe93b8d7b73d 100644 (file)
@@ -107,8 +107,6 @@ simple_object_internal_write (int descriptor, off_t offset,
                              const unsigned char *buffer, size_t size,
                              const char **errmsg, int *err)
 {
-  ssize_t wrote;
-
   if (lseek (descriptor, offset, SEEK_SET) < 0)
     {
       *errmsg = "lseek";
@@ -116,15 +114,26 @@ simple_object_internal_write (int descriptor, off_t offset,
       return 0;
     }
 
-  wrote = write (descriptor, buffer, size);
-  if (wrote < 0)
+  do
     {
-      *errmsg = "write";
-      *err = errno;
-      return 0;
+      ssize_t wrote = write (descriptor, buffer, size);
+      if (wrote == 0)
+       break;
+      else if (wrote > 0)
+       {
+         buffer += wrote;
+         size -= wrote;
+       }
+      else if (errno != EINTR)
+       {
+         *errmsg = "write";
+         *err = errno;
+         return 0;
+       }
     }
+  while (size > 0);
 
-  if ((size_t) wrote < size)
+  if (size > 0)
     {
       *errmsg = "short write";
       *err = 0;