summaryrefslogtreecommitdiff
path: root/cpp.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpp.c')
-rw-r--r--cpp.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/cpp.c b/cpp.c
index d4ec2a6..8e03209 100644
--- a/cpp.c
+++ b/cpp.c
@@ -5,25 +5,46 @@
#include "proc.h"
#include "xmalloc.h"
-int cpp_exec(char *in_file, char *out_file, size_t out_len)
+static size_t argv_len(char **argv)
{
+ size_t len = 0;
+
+ for (; argv && *argv; argv++)
+ len++;
+
+ return len;
+}
+
+int cpp_exec(char *in_file, char *out_file, size_t out_len, char **argv)
+{
+ size_t argc = 7 + argv_len(argv);
char *tmp = xstrdup(in_file);
- char *argv[7] = {
- "cpp",
- "-I", ETCDIRE_STRING,
- "-o", out_file,
- in_file,
- NULL,
- };
+ char **cpp_argv;
int ret = 0;
char *base;
+ unsigned int i = 0;
base = basename(tmp);
slprintf(out_file, out_len, "/tmp/.tmp-%u-%s", rand(), base);
- if (proc_exec("cpp", argv))
+ cpp_argv = xmalloc(argc * sizeof(char *));
+
+ cpp_argv[i++] = "cpp";
+
+ for (; argv && *argv; argv++, i++)
+ cpp_argv[i] = *argv;
+
+ cpp_argv[i++] = "-I";
+ cpp_argv[i++] = ETCDIRE_STRING;
+ cpp_argv[i++] = "-o";
+ cpp_argv[i++] = out_file;
+ cpp_argv[i++] = in_file;
+ cpp_argv[i++] = NULL;
+
+ if (proc_exec("cpp", cpp_argv))
ret = -1;
+ xfree(cpp_argv);
xfree(tmp);
return ret;
}