]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/nlohmann-json/test/thirdparty/Fuzzer/FuzzerIOPosix.cpp
1 //===- FuzzerIOPosix.cpp - IO utils for Posix. ----------------------------===//
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 //===----------------------------------------------------------------------===//
9 // IO functions implementation using Posix API.
10 //===----------------------------------------------------------------------===//
11 #include "FuzzerDefs.h"
14 #include "FuzzerExtFunctions.h"
23 #include <sys/types.h>
28 bool IsFile(const std::string
&Path
) {
30 if (stat(Path
.c_str(), &St
))
32 return S_ISREG(St
.st_mode
);
35 void ListFilesInDirRecursive(const std::string
&Dir
, long *Epoch
,
36 std::vector
<std::string
> *V
, bool TopDir
) {
37 auto E
= GetEpoch(Dir
);
39 if (E
&& *Epoch
>= E
) return;
41 DIR *D
= opendir(Dir
.c_str());
43 Printf("No such directory: %s; exiting\n", Dir
.c_str());
46 while (auto E
= readdir(D
)) {
47 std::string Path
= DirPlusFile(Dir
, E
->d_name
);
48 if (E
->d_type
== DT_REG
|| E
->d_type
== DT_LNK
)
50 else if (E
->d_type
== DT_DIR
&& *E
->d_name
!= '.')
51 ListFilesInDirRecursive(Path
, Epoch
, V
, false);
62 FILE* OpenFile(int Fd
, const char* Mode
) {
63 return fdopen(Fd
, Mode
);
66 int CloseFile(int fd
) {
70 int DuplicateFile(int Fd
) {
74 void RemoveFile(const std::string
&Path
) {
78 std::string
DirName(const std::string
&FileName
) {
79 char *Tmp
= new char[FileName
.size() + 1];
80 memcpy(Tmp
, FileName
.c_str(), FileName
.size() + 1);
81 std::string Res
= dirname(Tmp
);
88 #endif // LIBFUZZER_POSIX