1 //===- FuzzerIO.h - Internal header for IO utils ----------------*- C++ -* ===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_FUZZER_IO_H
13 #define LLVM_FUZZER_IO_H
15 #include "FuzzerDefs.h"
19 long GetEpoch(const std::string &Path);
21 Unit FileToVector(const std::string &Path, size_t MaxSize = 0,
22 bool ExitOnError = true);
24 std::string FileToString(const std::string &Path);
26 void CopyFileToErr(const std::string &Path);
28 void WriteToFile(const Unit &U, const std::string &Path);
30 void ReadDirToVectorOfUnits(const char *Path, Vector<Unit> *V,
31 long *Epoch, size_t MaxSize, bool ExitOnError);
33 // Returns "Dir/FileName" or equivalent for the current OS.
34 std::string DirPlusFile(const std::string &DirPath,
35 const std::string &FileName);
37 // Returns the name of the dir, similar to the 'dirname' utility.
38 std::string DirName(const std::string &FileName);
40 // Returns path to a TmpDir.
43 bool IsInterestingCoverageFile(const std::string &FileName);
45 void DupAndCloseStderr();
49 void Printf(const char *Fmt, ...);
51 // Print using raw syscalls, useful when printing at early init stages.
52 void RawPrint(const char *Str);
54 // Platform specific functions:
55 bool IsFile(const std::string &Path);
56 size_t FileSize(const std::string &Path);
58 void ListFilesInDirRecursive(const std::string &Dir, long *Epoch,
59 Vector<std::string> *V, bool TopDir);
64 bool operator<(const SizedFile &B) const { return Size < B.Size; }
67 void GetSizedFilesFromDir(const std::string &Dir, Vector<SizedFile> *V);
70 // Similar to the basename utility: returns the file name w/o the dir prefix.
71 std::string Basename(const std::string &Path, char Separator = GetSeparator());
73 FILE* OpenFile(int Fd, const char *Mode);
75 int CloseFile(int Fd);
77 int DuplicateFile(int Fd);
79 void RemoveFile(const std::string &Path);
81 void DiscardOutput(int Fd);
83 intptr_t GetHandleFromFd(int fd);
87 #endif // LLVM_FUZZER_IO_H