summaryrefslogtreecommitdiffstats
path: root/gold/testsuite/binary_unittest.cc
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2012-12-10 17:38:42 +0000
committerRoland McGrath <roland@gnu.org>2012-12-10 17:38:42 +0000
commit4c8a1de1fe7ae5bb8aa84cad901db098ffb167c0 (patch)
tree044a65d6fd067495f95da4a29a771000907633ea /gold/testsuite/binary_unittest.cc
parent8b9737bf8cca3d3f999bb48a27019933f2138c2c (diff)
downloadppe42-binutils-4c8a1de1fe7ae5bb8aa84cad901db098ffb167c0.tar.gz
ppe42-binutils-4c8a1de1fe7ae5bb8aa84cad901db098ffb167c0.zip
gold/
* testsuite/binary_unittest.cc (read_all): New function. (Sized_binary_test): Use it instead of ::read. * fileread.cc (do_read): Don't assume pread always reads the whole amount in a single call.
Diffstat (limited to 'gold/testsuite/binary_unittest.cc')
-rw-r--r--gold/testsuite/binary_unittest.cc25
1 files changed, 24 insertions, 1 deletions
diff --git a/gold/testsuite/binary_unittest.cc b/gold/testsuite/binary_unittest.cc
index 6e7b244121..fe10922688 100644
--- a/gold/testsuite/binary_unittest.cc
+++ b/gold/testsuite/binary_unittest.cc
@@ -38,6 +38,29 @@
#include "test.h"
#include "testfile.h"
+namespace
+{
+
+ssize_t
+read_all (int fd, unsigned char* buf, ssize_t size)
+{
+ ssize_t total_read = 0;
+ while (size > 0)
+ {
+ ssize_t nread = ::read(fd, buf, size);
+ if (nread < 0)
+ return nread;
+ if (nread == 0)
+ break;
+ buf += nread;
+ size -= nread;
+ total_read += nread;
+ }
+ return total_read;
+}
+
+} // End anonymous namespace.
+
namespace gold_testsuite
{
@@ -57,7 +80,7 @@ Sized_binary_test()
int o = open_descriptor(-1, gold::program_name, O_RDONLY);
CHECK(o >= 0);
unsigned char* filedata = new unsigned char[st.st_size];
- CHECK(::read(o, filedata, st.st_size) == st.st_size);
+ CHECK(read_all(o, filedata, st.st_size) == static_cast<ssize_t>(st.st_size));
CHECK(::close(o) == 0);
Binary_to_elf binary(static_cast<elfcpp::EM>(0xffff), size, big_endian,
OpenPOWER on IntegriCloud