[libFuzzer] fix minor inefficiency, PR24584
[oota-llvm.git] / lib / Fuzzer / FuzzerIO.cpp
index 1d25389770fa27f38735fad7894d2189e494fa72..a68c6c579bfb8b445fc74270200ce680c3927681 100644 (file)
@@ -32,7 +32,7 @@ static std::vector<std::string> ListFilesInDir(const std::string &Dir,
                                                long *Epoch) {
   std::vector<std::string> V;
   if (Epoch) {
-    auto E = GetEpoch(Dir.c_str());
+    auto E = GetEpoch(Dir);
     if (*Epoch >= E) return V;
     *Epoch = E;
   }
@@ -66,8 +66,11 @@ void CopyFileToErr(const std::string &Path) {
 }
 
 void WriteToFile(const Unit &U, const std::string &Path) {
-  std::ofstream OF(Path);
-  OF.write((const char*)U.data(), U.size());
+  // Use raw C interface because this function may be called from a sig handler.
+  FILE *Out = fopen(Path.c_str(), "w");
+  if (!Out) return;
+  fwrite(U.data(), sizeof(U[0]), U.size(), Out);
+  fclose(Out);
 }
 
 void ReadDirToVectorOfUnits(const char *Path, std::vector<Unit> *V,