1 1.1 kamil //===- FuzzerIO.h - Internal header for IO utils ----------------*- C++ -* ===// 2 1.1 kamil // 3 1.1 kamil // The LLVM Compiler Infrastructure 4 1.1 kamil // 5 1.1 kamil // This file is distributed under the University of Illinois Open Source 6 1.1 kamil // License. See LICENSE.TXT for details. 7 1.1 kamil // 8 1.1 kamil //===----------------------------------------------------------------------===// 9 1.1 kamil // IO interface. 10 1.1 kamil //===----------------------------------------------------------------------===// 11 1.1 kamil 12 1.1 kamil #ifndef LLVM_FUZZER_IO_H 13 1.1 kamil #define LLVM_FUZZER_IO_H 14 1.1 kamil 15 1.1 kamil #include "FuzzerDefs.h" 16 1.1 kamil 17 1.1 kamil namespace fuzzer { 18 1.1 kamil 19 1.1 kamil long GetEpoch(const std::string &Path); 20 1.1 kamil 21 1.1 kamil Unit FileToVector(const std::string &Path, size_t MaxSize = 0, 22 1.1 kamil bool ExitOnError = true); 23 1.1 kamil 24 1.1 kamil std::string FileToString(const std::string &Path); 25 1.1 kamil 26 1.1 kamil void CopyFileToErr(const std::string &Path); 27 1.1 kamil 28 1.1 kamil void WriteToFile(const Unit &U, const std::string &Path); 29 1.1 kamil 30 1.1 kamil void ReadDirToVectorOfUnits(const char *Path, Vector<Unit> *V, 31 1.1 kamil long *Epoch, size_t MaxSize, bool ExitOnError); 32 1.1 kamil 33 1.1 kamil // Returns "Dir/FileName" or equivalent for the current OS. 34 1.1 kamil std::string DirPlusFile(const std::string &DirPath, 35 1.1 kamil const std::string &FileName); 36 1.1 kamil 37 1.1 kamil // Returns the name of the dir, similar to the 'dirname' utility. 38 1.1 kamil std::string DirName(const std::string &FileName); 39 1.1 kamil 40 1.1 kamil // Returns path to a TmpDir. 41 1.1 kamil std::string TmpDir(); 42 1.1 kamil 43 1.1 kamil bool IsInterestingCoverageFile(const std::string &FileName); 44 1.1 kamil 45 1.1 kamil void DupAndCloseStderr(); 46 1.1 kamil 47 1.1 kamil void CloseStdout(); 48 1.1 kamil 49 1.1 kamil void Printf(const char *Fmt, ...); 50 1.1 kamil 51 1.1 kamil // Print using raw syscalls, useful when printing at early init stages. 52 1.1 kamil void RawPrint(const char *Str); 53 1.1 kamil 54 1.1 kamil // Platform specific functions: 55 1.1 kamil bool IsFile(const std::string &Path); 56 1.1 kamil size_t FileSize(const std::string &Path); 57 1.1 kamil 58 1.1 kamil void ListFilesInDirRecursive(const std::string &Dir, long *Epoch, 59 1.1 kamil Vector<std::string> *V, bool TopDir); 60 1.1 kamil 61 1.1 kamil struct SizedFile { 62 1.1 kamil std::string File; 63 1.1 kamil size_t Size; 64 1.1 kamil bool operator<(const SizedFile &B) const { return Size < B.Size; } 65 1.1 kamil }; 66 1.1 kamil 67 1.1 kamil void GetSizedFilesFromDir(const std::string &Dir, Vector<SizedFile> *V); 68 1.1 kamil 69 1.1 kamil char GetSeparator(); 70 1.1 kamil // Similar to the basename utility: returns the file name w/o the dir prefix. 71 1.1 kamil std::string Basename(const std::string &Path); 72 1.1 kamil 73 1.1 kamil FILE* OpenFile(int Fd, const char *Mode); 74 1.1 kamil 75 1.1 kamil int CloseFile(int Fd); 76 1.1 kamil 77 1.1 kamil int DuplicateFile(int Fd); 78 1.1 kamil 79 1.1 kamil void RemoveFile(const std::string &Path); 80 1.1 kamil 81 1.1 kamil void DiscardOutput(int Fd); 82 1.1 kamil 83 1.1 kamil intptr_t GetHandleFromFd(int fd); 84 1.1 kamil 85 1.1 kamil } // namespace fuzzer 86 1.1 kamil 87 1.1 kamil #endif // LLVM_FUZZER_IO_H 88