aboutsummaryrefslogtreecommitdiff
path: root/fake-lib.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2017-05-18 07:09:40 +0100
committerSimon Tatham <anakin@pobox.com>2017-05-18 07:10:17 +0100
commit3b3a5fd6bf7a3542ab8e8701c93c3d0f505c722f (patch)
tree5d8299dec3ce144bb5765382b6268fb39a856542 /fake-lib.c
parent48919caa7b9fb99ba8196098c0ca2e1b3dae5160 (diff)
downloadwix-on-linux-3b3a5fd6bf7a3542ab8e8701c93c3d0f505c722f.tar.gz
wix-on-linux-3b3a5fd6bf7a3542ab8e8701c93c3d0f505c722f.tar.bz2
wix-on-linux-3b3a5fd6bf7a3542ab8e8701c93c3d0f505c722f.zip
Move system_argv_* into their own file.
Diffstat (limited to 'fake-lib.c')
-rw-r--r--fake-lib.c52
1 files changed, 0 insertions, 52 deletions
diff --git a/fake-lib.c b/fake-lib.c
index cf6be49..e2bc364 100644
--- a/fake-lib.c
+++ b/fake-lib.c
@@ -7,10 +7,6 @@
7#include <uchar.h> 7#include <uchar.h>
8#include <err.h> 8#include <err.h>
9 9
10#include <sys/types.h>
11#include <sys/wait.h>
12#include <unistd.h>
13
14#include "memory.h" 10#include "memory.h"
15#include "fake-lib.h" 11#include "fake-lib.h"
16 12
@@ -29,54 +25,6 @@ char *ascii(const char16_t *wstr, bool translate_slashes)
29 return ret; 25 return ret;
30} 26}
31 27
32void system_argv_array(char **args)
33{
34 pid_t pid = fork();
35 if (pid < 0)
36 err(1, "fork");
37
38 if (pid == 0) {
39 execvp(args[0], args);
40 warn("execvp");
41 _exit(127);
42 }
43
44 int status;
45 if (waitpid(pid, &status, 0) != pid)
46 err(1, "waitpid");
47 if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0))
48 errx(1, "subcommand failed");
49}
50
51void system_argv(const char *cmd, ...)
52{
53 int nargs, nchars;
54 const char *word;
55 va_list ap;
56
57 va_start(ap, cmd);
58 nargs = 1; /* terminating NULL */
59 nchars = 0;
60 for (word = cmd; word; word = va_arg(ap, const char *)) {
61 nargs++;
62 nchars += 1 + strlen(word);
63 }
64 va_end(ap);
65
66 char *args[nargs], chars[nchars];
67 char **argp = args, *charp = chars;
68 va_start(ap, cmd);
69 for (word = cmd; word; word = va_arg(ap, const char *)) {
70 *argp++ = charp;
71 strcpy(charp, word);
72 charp += 1 + strlen(word);
73 }
74 va_end(ap);
75 *argp++ = NULL;
76
77 system_argv_array(args);
78}
79
80void c16cpy(char16_t *out, uint32_t *outsize, char *s) 28void c16cpy(char16_t *out, uint32_t *outsize, char *s)
81{ 29{
82 uint32_t retlen = 0; 30 uint32_t retlen = 0;