aboutsummaryrefslogtreecommitdiffstats
path: root/spawn.c
diff options
context:
space:
mode:
authorsin <sin@2f30.org>2019-08-02 15:43:07 +0100
committersin <sin@2f30.org>2019-08-03 22:28:36 +0100
commit50592339bf450037972b85777d1c524e35545aa8 (patch)
treedc1fcea3d52e382b37f50c45d16cb9dc9b5a8036 /spawn.c
parent47d659c5fc930f0815c2bf5a24b3c2228b13695e (diff)
downloadnoice-50592339bf450037972b85777d1c524e35545aa8.tar.gz
Implement nopen(1)
Diffstat (limited to 'spawn.c')
-rw-r--r--spawn.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/spawn.c b/spawn.c
new file mode 100644
index 0000000..614ab64
--- /dev/null
+++ b/spawn.c
@@ -0,0 +1,43 @@
+/* See LICENSE file for copyright and license details. */
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <stdarg.h>
+#include <unistd.h>
+
+#include "util.h"
+
+void
+spawnvp(char *dir, char *file, char *argv[])
+{
+ pid_t pid;
+ int status;
+
+ pid = fork();
+ if (pid == 0) {
+ if (dir != NULL)
+ chdir(dir);
+ execvp(file, argv);
+ _exit(1);
+ } else {
+ /* Ignore interruptions */
+ while (waitpid(pid, &status, 0) == -1)
+ ;
+ }
+}
+
+void
+spawnlp(char *dir, char *file, char *argv0, ...)
+{
+ char *argv[NR_ARGS];
+ va_list ap;
+ int argc;
+
+ va_start(ap, argv0);
+ argv[0] = argv0;
+ for (argc = 1; argv[argc] = va_arg(ap, char *); argc++)
+ ;
+ argv[argc] = NULL;
+ va_end(ap);
+ spawnvp(dir, file, argv);
+}
Un proyecto texto-plano.xyz