Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
exec_pipe.hpp
Go to the documentation of this file.
1#pragma once
3#include <cstdint>
4#include <cstdio>
5#include <cstring>
6#include <memory>
7#include <vector>
8
9namespace bb {
10inline std::vector<uint8_t> exec_pipe([[maybe_unused]] const std::string& command)
11{
12#ifdef __wasm__
13 throw_or_abort("Can't use popen() in wasm! Implement this functionality natively.");
14#else
15 // popen() with "r" captures only stdout; stderr is inherited unchanged.
16 std::unique_ptr<FILE, int (*)(FILE*)> pipe(popen(command.c_str(), "r"), pclose); // NOLINT
17 if (!pipe) {
18 throw_or_abort("popen() failed: '" + command + "' due to " + strerror(errno));
19 }
20
21 std::vector<uint8_t> output;
22 uint8_t buf[4096]; // NOLINT
23
24 while (size_t n = fread(buf, 1, sizeof(buf), pipe.get())) {
25 output.insert(output.end(), buf, buf + n);
26 }
27 return output;
28#endif
29}
30} // namespace bb
uint8_t const * buf
Definition data_store.hpp:9
Entry point for Barretenberg command-line interface.
std::vector< uint8_t > exec_pipe(const std::string &command)
Definition exec_pipe.hpp:10
void throw_or_abort(std::string const &err)