diff options
author | Richard Biener <rguenther@suse.de> | 2014-04-01 07:45:48 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2014-04-01 07:45:48 +0000 |
commit | 25336bb650009bc065a2f49f8ae6bcf0e32f5160 (patch) | |
tree | 9fcab2cab3f1eb0edaeb2eb0111accf2731ea14c /libiberty | |
parent | 75d850f3681a4f907b43983936db7f28a2ec230d (diff) | |
download | gcc-25336bb650009bc065a2f49f8ae6bcf0e32f5160.zip gcc-25336bb650009bc065a2f49f8ae6bcf0e32f5160.tar.gz gcc-25336bb650009bc065a2f49f8ae6bcf0e32f5160.tar.bz2 |
simple-object.c (simple_object_internal_write): Handle EINTR and short writes.
2014-04-01 Richard Biener <rguenther@suse.de>
libiberty/
* simple-object.c (simple_object_internal_write): Handle
EINTR and short writes.
From-SVN: r208972
Diffstat (limited to 'libiberty')
-rw-r--r-- | libiberty/ChangeLog | 5 | ||||
-rw-r--r-- | libiberty/simple-object.c | 25 |
2 files changed, 22 insertions, 8 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index f20fac0..89e9bf9 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 263d174..5d379d0 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; |