diff --git a/compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp b/compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp --- a/compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp @@ -22,6 +22,10 @@ #include #include +#if LIBFUZZER_FUCHSIA +#include +#endif + namespace fuzzer { bool IsFile(const std::string &Path) { @@ -124,6 +128,19 @@ rename(OldPath.c_str(), NewPath.c_str()); } +#if LIBFUZZER_FUCHSIA +// In fuchsia, accessing /dev/null is not supported. There's nothing +// similar to a file that discards everything that is written to it. +// The way of doing something similar in fuchsia is by using +// fdio_null_create and binding that to a file descriptor. +void DiscardOutput(int Fd) { + fdio_t *fdio_null = fdio_null_create(); + if (fdio_null == nullptr) return; + int nullfd = fdio_bind_to_fd(fdio_null, -1, 0); + if (nullfd < 0) return; + dup2(nullfd, Fd); +} +#else void DiscardOutput(int Fd) { FILE* Temp = fopen("/dev/null", "w"); if (!Temp) @@ -131,6 +148,7 @@ dup2(fileno(Temp), Fd); fclose(Temp); } +#endif intptr_t GetHandleFromFd(int fd) { return static_cast(fd);