Use WriteToFile instead of internal_write in non-POSIX code

llvm-svn: 234487
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
index b335838..ae3c080 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
@@ -522,9 +522,9 @@
 
   if (cov_max_block_size == 0) {
     // Writing to a file. Just go ahead.
-    internal_write(cov_fd, &header, sizeof(header));
-    internal_write(cov_fd, module, module_name_length);
-    internal_write(cov_fd, blob, blob_size);
+    WriteToFile(cov_fd, &header, sizeof(header));
+    WriteToFile(cov_fd, module, module_name_length);
+    WriteToFile(cov_fd, blob, blob_size);
   } else {
     // Writing to a socket. We want to split the data into appropriately sized
     // blocks.
@@ -547,8 +547,7 @@
       internal_memcpy(block_data_begin, blob_pos, payload_size);
       blob_pos += payload_size;
       ((CovHeader *)block.data())->data_length = payload_size;
-      internal_write(cov_fd, block.data(),
-                     header_size_with_module + payload_size);
+      WriteToFile(cov_fd, block.data(), header_size_with_module + payload_size);
     }
   }
 }
@@ -595,7 +594,7 @@
   InternalScopedString path(kMaxPathLength);
   fd_t fd = CovOpenFile(&path, false, "trace-points");
   if (fd == kInvalidFd) return;
-  internal_write(fd, out.data(), out.length());
+  WriteToFile(fd, out.data(), out.length());
   CloseFile(fd);
 
   fd = CovOpenFile(&path, false, "trace-compunits");
@@ -603,7 +602,7 @@
   out.clear();
   for (uptr i = 0; i < comp_unit_name_vec.size(); i++)
     out.append("%s\n", comp_unit_name_vec[i].copied_module_name);
-  internal_write(fd, out.data(), out.length());
+  WriteToFile(fd, out.data(), out.length());
   CloseFile(fd);
 
   fd = CovOpenFile(&path, false, "trace-events");
@@ -612,8 +611,9 @@
   u8 *event_bytes = reinterpret_cast<u8*>(tr_event_array);
   // The trace file could be huge, and may not be written with a single syscall.
   while (bytes_to_write) {
-    uptr actually_written = internal_write(fd, event_bytes, bytes_to_write);
-    if (actually_written <= bytes_to_write) {
+    uptr actually_written;
+    if (WriteToFile(fd, event_bytes, bytes_to_write, &actually_written) &&
+        actually_written <= bytes_to_write) {
       bytes_to_write -= actually_written;
       event_bytes += actually_written;
     } else {
@@ -660,7 +660,7 @@
   InternalScopedString path(kMaxPathLength);
   fd_t fd = CovOpenFile(&path, false, "caller-callee");
   if (fd == kInvalidFd) return;
-  internal_write(fd, out.data(), out.length());
+  WriteToFile(fd, out.data(), out.length());
   CloseFile(fd);
   VReport(1, " CovDump: %zd caller-callee pairs written\n", total);
 }
@@ -695,7 +695,7 @@
     fd_t fd =
         CovOpenFile(&path, /* packed */ false, base_name, "counters-sancov");
     if (fd == kInvalidFd) return;
-    internal_write(fd, bitset.data() + r.beg, r.end - r.beg);
+    WriteToFile(fd, bitset.data() + r.beg, r.end - r.beg);
     CloseFile(fd);
     VReport(1, " CovDump: %zd counters written for '%s'\n", r.end - r.beg,
             base_name);
@@ -722,7 +722,7 @@
     const char *base_name = StripModuleName(r.copied_module_name);
     fd_t fd = CovOpenFile(&path, /* packed */false, base_name, "bitset-sancov");
     if (fd == kInvalidFd) return;
-    internal_write(fd, out.data() + r.beg, r.end - r.beg);
+    WriteToFile(fd, out.data() + r.beg, r.end - r.beg);
     CloseFile(fd);
     VReport(1,
             " CovDump: bitset of %zd bits written for '%s', %zd bits are set\n",
@@ -777,7 +777,7 @@
       // One file per module per process.
       fd_t fd = CovOpenFile(&path, false /* packed */, module_name);
       if (fd == kInvalidFd) continue;
-      internal_write(fd, offsets.data(), offsets.size() * sizeof(offsets[0]));
+      WriteToFile(fd, offsets.data(), offsets.size() * sizeof(offsets[0]));
       CloseFile(fd);
       VReport(1, " CovDump: %s: %zd PCs written\n", path.data(), num_offsets);
     }