Mercurial > minori
comparison dep/animia/src/fd/xnu.cc @ 230:2f5a9247e501
torrents: implement download button
erg
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Sat, 13 Jan 2024 09:42:02 -0500 |
parents | bc1ae1810855 |
children |
comparison
equal
deleted
inserted
replaced
229:adc20fa321c1 | 230:2f5a9247e501 |
---|---|
15 #include <sys/user.h> | 15 #include <sys/user.h> |
16 | 16 |
17 namespace animia::internal::xnu { | 17 namespace animia::internal::xnu { |
18 | 18 |
19 bool EnumerateOpenProcesses(process_proc_t process_proc) { | 19 bool EnumerateOpenProcesses(process_proc_t process_proc) { |
20 size_t pids_size = 512; | 20 size_t pids_size = 256; |
21 std::unique_ptr<pid_t[]> pids; | 21 std::unique_ptr<pid_t[]> pids; |
22 | 22 |
23 int returned_size = 0; | 23 int returned_size = 0; |
24 do { | 24 do { |
25 pids.reset(new pid_t[pids_size]); | 25 pids.reset(new pid_t[pids_size *= 2]); |
26 returned_size = proc_listpids(PROC_ALL_PIDS, 0, pids.get(), pids_size * sizeof(pid_t)); | 26 returned_size = proc_listpids(PROC_ALL_PIDS, 0, pids.get(), pids_size * sizeof(pid_t)); |
27 if (returned_size == -1) | 27 if (returned_size == -1) |
28 return false; | 28 return false; |
29 } while ((pids_size * sizeof(size_t)) < returned_size); | 29 } while ((pids_size * sizeof(size_t)) < returned_size); |
30 | 30 |