1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #ifndef _UTILS_H |
6 | #define _UTILS_H |
7 | |
8 | #include <string> |
9 | #include <vector> |
10 | #include "ScopedFd.h" |
11 | |
12 | class StringVectorToCharArray { |
13 | public: |
14 | StringVectorToCharArray(const std::vector<std::string>& vs) { |
15 | for (auto& v : vs) { |
16 | array.push_back(const_cast<char*>(v.c_str())); |
17 | } |
18 | array.push_back(nullptr); |
19 | } |
20 | char** get() { return array.data(); } |
21 | |
22 | private: |
23 | std::vector<char*> array; |
24 | }; |
25 | |
26 | ssize_t read_to_end(const ScopedFd& fd, size_t offset, void* buf, size_t size); |
27 | uint32_t crc32(uint32_t crc, unsigned char* buf, size_t len); |
28 | size_t page_size(); |
29 | size_t ceil_page_size(size_t sz) ; |
30 | |
31 | bool has_effective_caps(); |
32 | bool running_under_rr(); |
33 | const char* tmp_dir(); |
34 | |
35 | const char* ptrace_cmd_name(int request); |
36 | |
37 | #endif /*end #ifndef _UTILS_H*/ |
38 | |