summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-03-09 07:19:29 -0500
committermidipix <writeonce@midipix.org>2016-03-10 08:32:40 -0500
commit9fc04630472ab18b2338050714ee0419281227e1 (patch)
tree912464bd57d2605746c25d853b6f26487e556fc7 /src
parent528799aa1ab548dc649befeb9fa81f0d83f14a50 (diff)
downloadslibtool-9fc04630472ab18b2338050714ee0419281227e1.tar.bz2
slibtool-9fc04630472ab18b2338050714ee0419281227e1.tar.xz
slbt_spawn(): initial implementation.
Diffstat (limited to 'src')
-rw-r--r--src/internal/slibtool_spawn_impl.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/internal/slibtool_spawn_impl.h b/src/internal/slibtool_spawn_impl.h
new file mode 100644
index 0000000..b376ad8
--- /dev/null
+++ b/src/internal/slibtool_spawn_impl.h
@@ -0,0 +1,69 @@
+/*******************************************************************/
+/* slibtool: a skinny libtool implementation, written in C */
+/* Copyright (C) 2016 Z. Gilboa */
+/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
+/*******************************************************************/
+
+#include <unistd.h>
+#include <stdbool.h>
+#include <sys/wait.h>
+
+#ifndef SLBT_USE_FORK
+#ifndef SLBT_USE_VFORK
+#ifndef SLBT_USE_POSIX_SPAWN
+#define SLBT_USE_POSIX_SPAWN
+#endif
+#endif
+#endif
+
+#ifdef SLBT_USE_POSIX_SPAWN
+#include <spawn.h>
+#endif
+
+extern char ** environ;
+
+static inline int slbt_spawn(
+ struct slbt_exec_ctx * ectx,
+ bool fwait)
+{
+ pid_t pid;
+
+
+#ifdef SLBT_USE_POSIX_SPAWN
+
+ if (posix_spawnp(
+ &pid,
+ ectx->program,
+ 0,0,
+ ectx->argv,
+ ectx->envp ? ectx->envp : environ))
+ pid = -1;
+
+#else
+
+#ifdef SLBT_USE_FORK
+ pid = fork();
+#else
+ pid = vfork();
+#endif
+
+#endif
+
+ if (pid < 0)
+ return -1;
+
+ if (pid == 0)
+ return execvp(
+ ectx->program,
+ ectx->argv);
+
+ ectx->pid = pid;
+
+ if (fwait)
+ return waitpid(
+ pid,
+ &ectx->exitcode,
+ 0);
+
+ return 0;
+}