Mercurial > minori
comparison dep/animia/src/fd/libutil.cc @ 198:bc1ae1810855
dep/animia: switch from using classes to global functions
the old idea was ok, but sort of hackish; this method doesn't use classes
at all, and this way (especially important!) we can do wayland stuff AND x11
at the same time, which wasn't really possible without stupid workarounds in
the other method
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 24 Dec 2023 02:59:42 -0500 |
parents | 54c5d80a737e |
children |
comparison
equal
deleted
inserted
replaced
197:c4ca035c565d | 198:bc1ae1810855 |
---|---|
17 static bool IsSystemFile(const std::string& file) { | 17 static bool IsSystemFile(const std::string& file) { |
18 return (!file.find("/usr") || !file.find("/lib") || !file.find("/dev") || | 18 return (!file.find("/usr") || !file.find("/lib") || !file.find("/dev") || |
19 !file.find("/proc")); | 19 !file.find("/proc")); |
20 } | 20 } |
21 | 21 |
22 bool LibutilFdTools::EnumerateOpenProcesses(process_proc_t process_proc) { | 22 bool EnumerateOpenProcesses(process_proc_t process_proc) { |
23 static const int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0}; | 23 static const int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0}; |
24 size_t length = 0; | 24 size_t length = 0; |
25 | 25 |
26 sysctl((int*)mib, (sizeof(mib) / sizeof(*mib)) - 1, NULL, &length, NULL, 0); | 26 sysctl((int*)mib, (sizeof(mib) / sizeof(*mib)) - 1, NULL, &length, NULL, 0); |
27 | 27 |
45 return false; | 45 return false; |
46 | 46 |
47 return true; | 47 return true; |
48 } | 48 } |
49 | 49 |
50 bool LibutilFdTools::EnumerateOpenFiles(const std::set<pid_t>& pids, open_file_proc_t open_file_proc) { | 50 bool EnumerateOpenFiles(const std::set<pid_t>& pids, open_file_proc_t open_file_proc) { |
51 for (const auto& pid : pids) { | 51 for (const auto& pid : pids) { |
52 int cnt; | 52 int cnt; |
53 std::unique_ptr<struct kinfo_file[]> files; | 53 std::unique_ptr<struct kinfo_file[]> files; |
54 files.reset(kinfo_getfile(pid, &cnt)); | 54 files.reset(kinfo_getfile(pid, &cnt)); |
55 if (!files.get()) | 55 if (!files.get()) |