summaryrefslogtreecommitdiffstats
path: root/src/common/processing.h
diff options
context:
space:
mode:
authorsumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
committersumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
commit76424950e373d3b04ac3dd13019151bfba3e8423 (patch)
tree4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/common/processing.h
Add the files
Diffstat (limited to 'src/common/processing.h')
-rw-r--r--src/common/processing.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/common/processing.h b/src/common/processing.h
new file mode 100644
index 0000000..51105c8
--- /dev/null
+++ b/src/common/processing.h
@@ -0,0 +1,55 @@
+#pragma once
+
+#include "common/FFstrbuf.h"
+
+#ifndef _WIN32
+ #include <sys/types.h> // pid_t
+#endif
+
+typedef struct FFProcessHandle {
+#if _WIN32
+ void* pid; // HANDLE
+ void* pipeRead; // HANDLE
+#else
+ pid_t pid;
+ int pipeRead;
+#endif
+} FFProcessHandle;
+
+const char* ffProcessSpawn(char* const argv[], bool useStdErr, FFProcessHandle* outHandle);
+const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer); // Destroys handle internally
+
+static inline const char* ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[]) {
+ FFProcessHandle handle;
+ const char* error = ffProcessSpawn(argv, false, &handle);
+ if (error) {
+ return error;
+ }
+
+ error = ffProcessReadOutput(&handle, buffer);
+ if (!error) {
+ ffStrbufTrimRightSpace(buffer);
+ }
+ return error;
+}
+
+static inline const char* ffProcessAppendStdErr(FFstrbuf* buffer, char* const argv[]) {
+ FFProcessHandle handle;
+ const char* error = ffProcessSpawn(argv, true, &handle);
+ if (error) {
+ return error;
+ }
+
+ error = ffProcessReadOutput(&handle, buffer);
+ if (!error) {
+ ffStrbufTrimRightSpace(buffer);
+ }
+ return error;
+}
+
+#ifdef _WIN32
+bool ffProcessGetInfoWindows(uint32_t pid, uint32_t* ppid, FFstrbuf* pname, FFstrbuf* exe, const char** exeName, FFstrbuf* exePath, bool* gui);
+#else
+void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, const char** exeName, FFstrbuf* exePath);
+const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, int32_t* tty);
+#endif