comparison dep/animia/src/main.cpp @ 56:6ff7aabeb9d7

deps: add animia for open files detection
author Paper <mrpapersonic@gmail.com>
date Thu, 28 Sep 2023 12:35:21 -0400
parents
children 4c6dd5999b39
comparison
equal deleted inserted replaced
54:466ac9870df9 56:6ff7aabeb9d7
1 #include "bsd.h"
2 #include "linux.h"
3 #include "win32.h"
4 #include <vector>
5 #include <string>
6 #include <unordered_map>
7 #ifdef __linux__
8 # define ON_LINUX
9 #elif (defined(unix) || defined(__unix__) || defined(__unix) || \
10 (defined(__APPLE__) && defined(__MACH__)))
11 # define ON_UNIX
12 #elif defined(_WIN32)
13 # define ON_WINDOWS
14 #endif
15
16 namespace Animia {
17
18 std::vector<int> get_all_pids() {
19 #ifdef ON_UNIX
20 return Unix::get_all_pids();
21 #elif defined(ON_LINUX)
22 return Linux::get_all_pids();
23 #elif defined(ON_WINDOWS)
24 return Windows::get_all_pids();
25 #else
26 return {};
27 #endif
28 }
29
30 std::string get_process_name(int pid) {
31 #ifdef ON_UNIX
32 return Unix::get_process_name(pid);
33 #elif defined(ON_LINUX)
34 return Linux::get_process_name(pid);
35 #elif defined(ON_WINDOWS)
36 return Windows::get_process_name(pid);
37 #else
38 return "";
39 #endif
40 }
41
42 std::vector<std::string> get_open_files(int pid) {
43 #ifdef ON_UNIX
44 return Unix::get_open_files(pid);
45 #elif defined(ON_LINUX)
46 return Linux::get_open_files(pid);
47 #elif defined(ON_WINDOWS)
48 return Windows::get_open_files(pid);
49 #else
50 return {};
51 #endif
52 }
53
54 std::unordered_map<int, std::vector<std::string>> get_all_open_files() {
55 #ifdef ON_UNIX
56 return Unix::get_all_open_files();
57 #elif defined(ON_LINUX)
58 return Linux::get_all_open_files();
59 #elif defined(ON_WINDOWS)
60 return Windows::get_all_open_files();
61 #else
62 return {};
63 #endif
64 }
65
66 }