aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2014-04-01 07:45:48 +0000
committerTom Tromey <tromey@redhat.com>2014-05-08 10:18:30 -0600
commitc3c3c691f2d56953d81a2a7da214623d8aef857c (patch)
tree86f198d2dd7a545bd69b5c57a6d91a022f0d009e /libiberty
parent2014-03-28 Richard Biener <rguenther@suse.de> (diff)
downloadbinutils-gdb-c3c3c691f2d56953d81a2a7da214623d8aef857c.tar.gz
binutils-gdb-c3c3c691f2d56953d81a2a7da214623d8aef857c.tar.bz2
binutils-gdb-c3c3c691f2d56953d81a2a7da214623d8aef857c.zip
2014-04-01 Richard Biener <rguenther@suse.de>
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
Diffstat (limited to 'libiberty')
-rw-r--r--libiberty/ChangeLog5
-rw-r--r--libiberty/simple-object.c25
2 files changed, 22 insertions, 8 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index f20fac0aabb..89e9bf953de 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -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
diff --git a/libiberty/simple-object.c b/libiberty/simple-object.c
index 263d174051d..5d379d053c4 100644
--- a/libiberty/simple-object.c
+++ b/libiberty/simple-object.c
@@ -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;