blob: 3b66a52d1a6492793ddad07faa057796919711bb [file] [log] [blame]
Zachary Turner24a148b2016-11-30 19:06:14 +00001//===- FuzzerIO.h - Internal header for IO utils ----------------*- C++ -* ===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9// IO interface.
10//===----------------------------------------------------------------------===//
Marcos Pividori178fe582016-12-13 17:46:11 +000011
Zachary Turner24a148b2016-11-30 19:06:14 +000012#ifndef LLVM_FUZZER_IO_H
13#define LLVM_FUZZER_IO_H
14
15#include "FuzzerDefs.h"
16
17namespace fuzzer {
18
Zachary Turner24a148b2016-11-30 19:06:14 +000019long GetEpoch(const std::string &Path);
20
21Unit FileToVector(const std::string &Path, size_t MaxSize = 0,
22 bool ExitOnError = true);
23
Zachary Turner24a148b2016-11-30 19:06:14 +000024std::string FileToString(const std::string &Path);
25
26void CopyFileToErr(const std::string &Path);
27
28void WriteToFile(const Unit &U, const std::string &Path);
29
30void ReadDirToVectorOfUnits(const char *Path, std::vector<Unit> *V,
31 long *Epoch, size_t MaxSize, bool ExitOnError);
32
33// Returns "Dir/FileName" or equivalent for the current OS.
34std::string DirPlusFile(const std::string &DirPath,
35 const std::string &FileName);
36
Kostya Serebryany1cba0a92016-11-30 21:53:32 +000037// Returns the name of the dir, similar to the 'dirname' utility.
38std::string DirName(const std::string &FileName);
39
Kostya Serebryany26482432017-01-05 04:32:19 +000040// Returns path to a TmpDir.
41std::string TmpDir();
42
Marcos Pividori60cc2fb2017-01-22 01:27:47 +000043bool IsInterestingCoverageFile(const std::string &FileName);
44
Zachary Turner24a148b2016-11-30 19:06:14 +000045void DupAndCloseStderr();
46
47void CloseStdout();
48
49void Printf(const char *Fmt, ...);
50
Kostya Serebryanyd0ecb4c2017-01-26 01:04:54 +000051// Print using raw syscalls, useful when printing at early init stages.
52void RawPrint(const char *Str);
53
Zachary Turner5abac172016-11-30 21:44:26 +000054// Platform specific functions:
55bool IsFile(const std::string &Path);
56
57void ListFilesInDirRecursive(const std::string &Dir, long *Epoch,
58 std::vector<std::string> *V, bool TopDir);
59
60char GetSeparator();
61
62FILE* OpenFile(int Fd, const char *Mode);
63
64int CloseFile(int Fd);
65
66int DuplicateFile(int Fd);
67
Marcos Pividori7c1defd2016-12-13 17:46:40 +000068void RemoveFile(const std::string &Path);
Zachary Turner5abac172016-11-30 21:44:26 +000069
Marcos Pividori61ecfc02017-01-22 01:58:45 +000070void DiscardOutput(int Fd);
71
Marcos Pividori360be4d2017-02-08 00:03:18 +000072intptr_t GetHandleFromFd(int fd);
73
Zachary Turner24a148b2016-11-30 19:06:14 +000074} // namespace fuzzer
Marcos Pividori178fe582016-12-13 17:46:11 +000075
Zachary Turner24a148b2016-11-30 19:06:14 +000076#endif // LLVM_FUZZER_IO_H