ChangeLog rotatation and copyright year update
[deliverable/binutils-gdb.git] / gold / testsuite / binary_unittest.cc
index a9f47c20fcbeddcbc75d67cbc7821cd3110b0f11..35e2629af6a05cf583c06ef5c263b1b3032a31fe 100644 (file)
@@ -1,6 +1,6 @@
 // binary_unittest.cc -- test Binary_to_elf
 
-// Copyright 2008 Free Software Foundation, Inc.
+// Copyright (C) 2008-2015 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
 #include "options.h"
 #include "binary.h"
 #include "object.h"
+#include "descriptors.h"
 
 #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
 {
 
@@ -53,10 +77,10 @@ Sized_binary_test()
   // Use the executable itself as the binary data.
   struct stat st;
   CHECK(::stat(gold::program_name, &st) == 0);
-  int o = ::open(gold::program_name, O_RDONLY);
+  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,
This page took 0.024665 seconds and 4 git commands to generate.