aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 9dab384..f20fac0 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-28 Richard Biener <rguenther@suse.de>
+
+ * simple-object.c (simple_object_internal_read): Handle
+ EINTR and short reads.
+
2014-03-13 Uros Bizjak <ubizjak@gmail.com>
* regex.c (bzero) [!_LIBC]: Define without coma expression.
diff --git a/libiberty/simple-object.c b/libiberty/simple-object.c
index fde3454..263d174 100644
--- a/libiberty/simple-object.c
+++ b/libiberty/simple-object.c
@@ -63,8 +63,6 @@ simple_object_internal_read (int descriptor, off_t offset,
unsigned char *buffer, size_t size,
const char **errmsg, int *err)
{
- ssize_t got;
-
if (lseek (descriptor, offset, SEEK_SET) < 0)
{
*errmsg = "lseek";
@@ -72,15 +70,26 @@ simple_object_internal_read (int descriptor, off_t offset,
return 0;
}
- got = read (descriptor, buffer, size);
- if (got < 0)
+ do
{
- *errmsg = "read";
- *err = errno;
- return 0;
+ ssize_t got = read (descriptor, buffer, size);
+ if (got == 0)
+ break;
+ else if (got > 0)
+ {
+ buffer += got;
+ size -= got;
+ }
+ else if (errno != EINTR)
+ {
+ *errmsg = "read";
+ *err = errno;
+ return 0;
+ }
}
+ while (size > 0);
- if ((size_t) got < size)
+ if (size > 0)
{
*errmsg = "file too short";
*err = 0;