diff options
author | Ivan Lozano <ivanlozano@google.com> | 2021-01-25 20:35:07 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-01-25 20:35:07 +0000 |
commit | ab82bbb1a37f2aa49ad9678ec4031e89159f2ba5 (patch) | |
tree | dcca0f982ff65985e39090821fa74fcea2f3bee4 /libfuzzer/FuzzerUtilLinux.cpp | |
parent | 0e1e755ed95b5465d8a78f52836ebfe072dd1f41 (diff) | |
parent | 2951b303d0160a61ca87d3b9d9054f35627f5ce7 (diff) | |
download | libfuzzer-sys-ab82bbb1a37f2aa49ad9678ec4031e89159f2ba5.tar.gz |
Import libfuzzer-sys Rust Crate am: d4c94dacf6 am: 2951b303d0
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/libfuzzer-sys/+/1500710
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: I4f350329e875ccbb6b1eda59b80a550ef0bcb5e1
Diffstat (limited to 'libfuzzer/FuzzerUtilLinux.cpp')
-rw-r--r-- | libfuzzer/FuzzerUtilLinux.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/libfuzzer/FuzzerUtilLinux.cpp b/libfuzzer/FuzzerUtilLinux.cpp new file mode 100644 index 0000000..95490b9 --- /dev/null +++ b/libfuzzer/FuzzerUtilLinux.cpp @@ -0,0 +1,41 @@ +//===- FuzzerUtilLinux.cpp - Misc utils for Linux. ------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// Misc utils for Linux. +//===----------------------------------------------------------------------===// +#include "FuzzerPlatform.h" +#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD || \ + LIBFUZZER_OPENBSD || LIBFUZZER_EMSCRIPTEN +#include "FuzzerCommand.h" + +#include <stdlib.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <unistd.h> + + +namespace fuzzer { + +int ExecuteCommand(const Command &Cmd) { + std::string CmdLine = Cmd.toString(); + int exit_code = system(CmdLine.c_str()); + if (WIFEXITED(exit_code)) + return WEXITSTATUS(exit_code); + return exit_code; +} + +void DiscardOutput(int Fd) { + FILE* Temp = fopen("/dev/null", "w"); + if (!Temp) + return; + dup2(fileno(Temp), Fd); + fclose(Temp); +} + +} // namespace fuzzer + +#endif |