2020-10-27 04:46:15 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <utils.hpp>
|
|
|
|
|
2021-01-13 07:50:55 +01:00
|
|
|
struct mmap_data {
|
2020-12-31 07:11:24 +01:00
|
|
|
uint8_t *buf = nullptr;
|
|
|
|
size_t sz = 0;
|
2021-01-13 07:50:55 +01:00
|
|
|
|
|
|
|
mmap_data() = default;
|
|
|
|
mmap_data(const mmap_data&) = delete;
|
|
|
|
mmap_data(mmap_data &&other) { consume(other); }
|
|
|
|
~mmap_data() { if (buf) munmap(buf, sz); }
|
|
|
|
mmap_data& operator=(mmap_data &&other) { consume(other); return *this; }
|
|
|
|
|
2020-12-31 07:11:24 +01:00
|
|
|
using str_pairs = std::initializer_list<std::pair<std::string_view, std::string_view>>;
|
|
|
|
int patch(str_pairs list);
|
|
|
|
bool contains(std::string_view pattern);
|
2020-10-27 04:46:15 +01:00
|
|
|
|
2021-01-13 07:50:55 +01:00
|
|
|
static mmap_data rw(const char *name);
|
|
|
|
static mmap_data ro(const char *name);
|
2020-10-27 04:46:15 +01:00
|
|
|
|
2021-01-13 07:50:55 +01:00
|
|
|
private:
|
|
|
|
void consume(mmap_data &other);
|
|
|
|
};
|