diff dep/animia/src/bsd.cpp @ 97:18979b066284

animia/unix: fix a bunch of stuff that breaks OS X things
author Paper <mrpapersonic@gmail.com>
date Thu, 02 Nov 2023 13:14:15 -0400
parents c912128af0eb
children f5940a575d83
line wrap: on
line diff
--- a/dep/animia/src/bsd.cpp	Wed Nov 01 15:16:49 2023 -0400
+++ b/dep/animia/src/bsd.cpp	Thu Nov 02 13:14:15 2023 -0400
@@ -6,6 +6,8 @@
  * around the very C-like BSD system functions that are...
  * kind of unnatural to use in modern C++.
  **/
+#include "bsd.h"
+#include "os.h"
 #include <assert.h>
 #include <fcntl.h>
 #include <iostream>
@@ -56,7 +58,7 @@
 	return ret;
 }
 
-std::string get_process_name(int pid) {
+std::string get_process_name(const int pid) {
 	std::string ret;
 #ifdef __FreeBSD__
 	struct kinfo_proc* proc = kinfo_getproc(pid);
@@ -75,7 +77,7 @@
 	return ret;
 }
 
-std::vector<std::string> get_open_files(int pid) {
+std::vector<std::string> get_open_files(const int pid) {
 	/* note: this is OS X only right now. eventually, I'll find a way
 	   to do this in FreeBSD, OpenBSD and the like */
 	std::vector<std::string> ret;
@@ -103,7 +105,9 @@
 			if (sz != PROC_PIDFDVNODEPATHINFO_SIZE)
 				continue;
 
-			if (vnodeInfo.pfi.fi_openflags & O_WRONLY || vnodeInfo.pfi.fi_openflags & O_RDWR)
+			/* I *think* this is correct. For some reason, with VLC on macOS this thinks files are read/write,
+			   which is totally unnecessary and even harmful. */
+			if ((vnodeInfo.pfi.fi_status & O_ACCMODE) == O_WRONLY)
 				continue;
 
 			ret.push_back(vnodeInfo.pvip.vip_path);
@@ -112,6 +116,21 @@
 	return ret;
 }
 
+std::vector<std::string> filter_system_files(const std::vector<std::string>& in) {
+#ifdef ON_OSX
+	std::vector<std::string> ret;
+	for (const auto& str : in)
+		/* these are some places nobody would ever want to store media files. */
+		if (str.find("/Library") && str.find("/System") && str.find("/Applications") &&
+			str.find("/dev") && str.find("/private"))
+			ret.push_back(str);
+	return ret;
+#else
+	return in;
+#endif
+}
+
+
 std::unordered_map<int, std::vector<std::string>> get_all_open_files() {
 	std::unordered_map<int, std::vector<std::string>> map;
 	std::vector<int> pids = get_all_pids();