summaryrefslogtreecommitdiff
path: root/process.h
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-02-16 01:14:10 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-02-16 01:14:10 -0500
commitacfbdf2359f533f88e284b5f5219b5c671992fc7 (patch)
tree784b7694e86634adeb8a0ec819c1745b5c09a0f9 /process.h
parent62cf95e9d3ad2b3b58cf3c67ad1a2b923d36a9b7 (diff)
processes
Diffstat (limited to 'process.h')
-rw-r--r--process.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/process.h b/process.h
new file mode 100644
index 0000000..2b34120
--- /dev/null
+++ b/process.h
@@ -0,0 +1,26 @@
+// like popen, but allowing for non-blocking reads
+#ifndef PROCESS_H_
+#define PROCESS_H_
+
+typedef struct Process Process;
+
+// returns NULL on failure
+Process *process_exec(char const *program, char **argv);
+// returns the error last error produced, or NULL if there was no error.
+char const *process_geterr(void);
+// returns:
+// -2 on error
+// -1 if no data is available right now
+// 0 on end of file
+// or a positive number indicating the number of bytes read to data (at most size)
+long long process_read(Process *process, char *data, size_t size);
+// Checks if the process has exited. Returns:
+// -1 if the process returned a non-zero exit code, or got a signal.
+// 1 if the process exited successfully
+// 0 if the process hasn't exited.
+// If message is not NULL, it will be set to a description of what happened (e.g. "exited successfully")
+int process_check_status(Process *process, char *message, size_t message_size);
+// kills process if still running, and frees data associated with it.
+void process_stop(Process *process);
+
+#endif