summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAdam Markey <adam@etinternational.com>2012-10-09 11:05:53 +0200
committerMark Wielaard <mjw@redhat.com>2012-10-10 10:56:42 +0200
commit6a1ed3836d644086a823138c405b48edd38479a3 (patch)
tree7343926dcb9c758f137b2389ada7807e58134f08 /lib
parent78dec228b3cfb2f9300cd0b682ebf416c9674c91 (diff)
downloadelfutils-6a1ed3836d644086a823138c405b48edd38479a3.tar.gz
Handle partial read or write.
Ran into a situation where pread was returning less data than requested for remote files on a networked filesystem. This patch modifies the IO wrappers to request the remaining data as long as no real errors occured. Signed-off-by: Adam Markey <adam@etinternational.com> Signed-off-by: Mark Wielaard <mjw@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/ChangeLog5
-rw-r--r--lib/system.h62
2 files changed, 61 insertions, 6 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 46eeeca0..525528a6 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,8 @@
+2012-10-09 Adam Markey <adam@etinternational.com>
+
+ * system.h: Changed pwrite_retry, write_retry, and pread_retry to
+ handle case where not all data was read/written.
+
2012-10-08 Jan Kratochvil <jan.kratochvil@redhat.com>
* system.h (eu_static_assert): New macro.
diff --git a/lib/system.h b/lib/system.h
index d9adee9c..8367f2bc 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -34,6 +34,7 @@
#include <stdint.h>
#include <endian.h>
#include <byteswap.h>
+#include <unistd.h>
#if __BYTE_ORDER == __LITTLE_ENDIAN
# define LE32(n) (n)
@@ -64,12 +65,61 @@ extern int crc32_file (int fd, uint32_t *resp);
#define gettext_noop(Str) Str
-#define pwrite_retry(fd, buf, len, off) \
- TEMP_FAILURE_RETRY (pwrite (fd, buf, len, off))
-#define write_retry(fd, buf, n) \
- TEMP_FAILURE_RETRY (write (fd, buf, n))
-#define pread_retry(fd, buf, len, off) \
- TEMP_FAILURE_RETRY (pread (fd, buf, len, off))
+static inline ssize_t __attribute__ ((unused))
+pwrite_retry (int fd, const void *buf, size_t len, off_t off)
+{
+ ssize_t recvd = 0;
+
+ do
+ {
+ ssize_t ret = TEMP_FAILURE_RETRY (pwrite (fd, buf + recvd, len - recvd,
+ off + recvd));
+ if (ret <= 0)
+ return ret < 0 ? ret : recvd;
+
+ recvd += ret;
+ }
+ while ((size_t) recvd < len);
+
+ return recvd;
+}
+
+static inline ssize_t __attribute__ ((unused))
+write_retry (int fd, const void *buf, size_t len)
+{
+ ssize_t recvd = 0;
+
+ do
+ {
+ ssize_t ret = TEMP_FAILURE_RETRY (write (fd, buf + recvd, len - recvd));
+ if (ret <= 0)
+ return ret < 0 ? ret : recvd;
+
+ recvd += ret;
+ }
+ while ((size_t) recvd < len);
+
+ return recvd;
+}
+
+static inline ssize_t __attribute__ ((unused))
+pread_retry (int fd, void *buf, size_t len, off_t off)
+{
+ ssize_t recvd = 0;
+
+ do
+ {
+ ssize_t ret = TEMP_FAILURE_RETRY (pread (fd, buf + recvd, len - recvd,
+ off + recvd));
+ if (ret <= 0)
+ return ret < 0 ? ret : recvd;
+
+ recvd += ret;
+ }
+ while ((size_t) recvd < len);
+
+ return recvd;
+}
/* We need define two variables, argp_program_version_hook and