diff dep/animia/src/fd/bsd.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
line wrap: on
line diff
--- a/dep/animia/src/fd/bsd.cc	Sun Nov 12 04:53:19 2023 -0500
+++ b/dep/animia/src/fd/bsd.cc	Sun Nov 12 16:43:07 2023 -0500
@@ -1,10 +1,7 @@
 /**
- * bsd.cpp
- *  - provides support for most* versions of BSD
- *  - this also works for OS X :)
- * more technical details: this is essentially a wrapper
- * around the very C-like BSD system functions that are...
- * kind of unnatural to use in modern C++.
+ * fd/bsd.cpp
+ *  - this ONLY* supports OS X as of now
+ *     (*there is some FreeBSD support code)
  **/
 #include <fcntl.h>
 #include <iostream>
@@ -25,7 +22,7 @@
 /* this is a cleaned up version of a function from... Apple?
    ...anyway, what it essentially does is gets the size and stuff from
    sysctl() and reserves the space in a vector to store the PIDs */
-bool GetAllPids(std::set<pid_t>& pids) {
+bool UnixFdTools::GetAllPids(std::set<pid_t>& pids) {
 	struct kinfo_proc* result = NULL;
 	size_t length = 0;
 	static const int name[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};
@@ -53,7 +50,7 @@
 		pids.push_back(result[i].kp_proc.p_pid);
 }
 
-bool GetProcessName(pid_t pid, std::string& result) {
+bool UnixFdTools::GetProcessName(pid_t pid, std::string& result) {
 #ifdef __FreeBSD__
 	struct kinfo_proc* proc = kinfo_getproc(pid);
 	if (!proc)
@@ -81,7 +78,7 @@
 }
 
 /* this only works on OS X :( */
-bool EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::tuple<pid_t, std::string>>& files) {
+bool UnixFdTools::EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::tuple<pid_t, std::string>>& files) {
 	for (const auto& pid : pids) {
 		int bufsz = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, NULL, 0);
 		if (bufsz == -1)