Mercurial > minori
comparison dep/animia/src/fd/win32.cc @ 139:478f3b366199
dep/animia: separate lots of things, use base class for OS stuff
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Sun, 12 Nov 2023 16:43:07 -0500 |
| parents | 28842a8d0c6b |
| children | 1e696863b54c |
comparison
equal
deleted
inserted
replaced
| 138:28842a8d0c6b | 139:478f3b366199 |
|---|---|
| 197 return false; | 197 return false; |
| 198 | 198 |
| 199 return true; | 199 return true; |
| 200 } | 200 } |
| 201 | 201 |
| 202 bool GetAllPids(std::set<pid_t>& pids) { | 202 bool Win32FdTools::GetAllPids(std::set<pid_t>& pids) { |
| 203 HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); | 203 HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
| 204 if (hProcessSnap == INVALID_HANDLE_VALUE) | 204 if (hProcessSnap == INVALID_HANDLE_VALUE) |
| 205 return false; | 205 return false; |
| 206 | 206 |
| 207 PROCESSENTRY32 pe32; | 207 PROCESSENTRY32 pe32; |
| 218 ::CloseHandle(hProcessSnap); | 218 ::CloseHandle(hProcessSnap); |
| 219 | 219 |
| 220 return true; | 220 return true; |
| 221 } | 221 } |
| 222 | 222 |
| 223 bool GetProcessName(pid_t pid, std::string& result) { | 223 bool Win32FdTools::GetProcessName(pid_t pid, std::string& result) { |
| 224 unsigned long ret_size = 0; // size given by GetModuleBaseNameW | 224 unsigned long ret_size = 0; // size given by GetModuleBaseNameW |
| 225 Handle handle(::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid)); | 225 Handle handle(::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid)); |
| 226 if (!handle.get()) | 226 if (!handle.get()) |
| 227 return false; | 227 return false; |
| 228 | 228 |
| 240 | 240 |
| 241 return true; | 241 return true; |
| 242 } | 242 } |
| 243 | 243 |
| 244 /* this could be changed to being a callback, but... I'm too lazy right now :) */ | 244 /* this could be changed to being a callback, but... I'm too lazy right now :) */ |
| 245 bool EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::tuple<pid_t, std::string>>& files) { | 245 bool Win32FdTools::EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::tuple<pid_t, std::string>>& files) { |
| 246 std::unordered_map<pid_t, Handle> proc_handles; | 246 std::unordered_map<pid_t, Handle> proc_handles; |
| 247 | 247 |
| 248 for (const pid_t& pid : pids) { | 248 for (const pid_t& pid : pids) { |
| 249 const HANDLE handle = ::OpenProcess(PROCESS_DUP_HANDLE, false, pid); | 249 const HANDLE handle = ::OpenProcess(PROCESS_DUP_HANDLE, false, pid); |
| 250 if (handle) | 250 if (handle) |
