diff dep/animia/src/fd/win32.cc @ 150:ffa535b6d630

*: avoid usage of std::[pair,tuple] https://arne-mertz.de/2017/03/smelly-pair-tuple/ it's better to use real structures and such where variables are easily known... also apparently using [] on structs is actually valid? I had no idea.
author Paper <mrpapersonic@gmail.com>
date Tue, 14 Nov 2023 16:27:33 -0500
parents aa4df5a84338
children 54744a48a7d7
line wrap: on
line diff
--- a/dep/animia/src/fd/win32.cc	Tue Nov 14 13:40:11 2023 -0500
+++ b/dep/animia/src/fd/win32.cc	Tue Nov 14 16:27:33 2023 -0500
@@ -224,7 +224,7 @@
 bool Win32FdTools::GetProcessName(pid_t pid, std::string& result) {
 	unsigned long ret_size = 0; // size given by GetModuleBaseNameW
 	Handle handle(::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid));
-	if (!handle.get())
+	if (handle.get() == INVALID_HANDLE_VALUE)
 		return false;
 
 	/* agh... */
@@ -243,12 +243,12 @@
 }
 
 /* this could be changed to being a callback, but... I'm too lazy right now :) */
-bool Win32FdTools::EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::pair<pid_t, std::string>>& files) {
+bool Win32FdTools::EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<OpenFile>& files) {
 	std::unordered_map<pid_t, Handle> proc_handles;
 
 	for (const pid_t& pid : pids) {
 		const HANDLE handle = ::OpenProcess(PROCESS_DUP_HANDLE, false, pid);
-		if (handle)
+		if (handle != INVALID_HANDLE_VALUE)
 			proc_handles[pid] = Handle(handle);
 	}
 
@@ -269,7 +269,7 @@
 			continue;
 
 		Handle handle(DuplicateHandle(proc_handles[pid].get(), h.HandleValue));
-		if (!handle.get())
+		if (handle.get() == INVALID_HANDLE_VALUE)
 			continue;
 
 		if (GetFileType(handle.get()) != FILE_TYPE_DISK)
@@ -279,8 +279,11 @@
 		if (!IsFilePathOk(path))
 			continue;
 
-		/* create an empty vector if it doesn't exist, probably unnecessary */
-		files.push_back({pid, path});
+		OpenFile file;
+		file.pid = pid;
+		file.path = path;
+
+		files.push_back(file);
 	}
 
 	return true;