//===- FuzzerIO.cpp - IO utils. -------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // IO functions. //===----------------------------------------------------------------------===//
void WriteToFile(const uint8_t *Data, size_t Size, const std::string &Path) { // Use raw C interface because this function may be called from a sig handler.
FILE *Out = fopen(Path.c_str(), "wb"); if (!Out) return;
mozilla::Unused << fwrite(Data, sizeof(Data[0]), Size, Out);
fclose(Out);
}
void ReadDirToVectorOfUnits(constchar *Path, Vector<Unit> *V, long *Epoch, size_t MaxSize, bool ExitOnError) { long E = Epoch ? *Epoch : 0;
Vector<std::string> Files; int Res = ListFilesInDirRecursive(Path, Epoch, &Files, /*TopDir*/true); if (ExitOnError && Res != 0) exit(Res);
size_t NumLoaded = 0; for (size_t i = 0; i < Files.size(); i++) { auto &X = Files[i]; if (Epoch && GetEpoch(X) < E) continue;
NumLoaded++; if ((NumLoaded & (NumLoaded - 1)) == 0 && NumLoaded >= 1024)
Printf("Loaded %zd/%zd files from %s\n", NumLoaded, Files.size(), Path); auto S = FileToVector(X, MaxSize, ExitOnError); if (!S.empty())
V->push_back(S);
}
}
int GetSizedFilesFromDir(const std::string &Dir, Vector<SizedFile> *V) {
Vector<std::string> Files; int Res = ListFilesInDirRecursive(Dir, 0, &Files, /*TopDir*/true); if (Res != 0) return Res; for (auto &File : Files) if (size_t Size = FileSize(File))
V->push_back({File, Size}); return 0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.