flowtop: man: Add how-to activate conntrack by modprobe
[netsniff-ng-new.git] / cpp.c
blobf6c15af0b59ec0c34ba1548ff57b827fcb93dab9
1 #include <stdio.h>
2 #include <libgen.h>
4 #include "cpp.h"
5 #include "str.h"
6 #include "proc.h"
7 #include "xmalloc.h"
9 static size_t argv_len(char *const argv[])
11 size_t len = 0;
13 for (; argv && *argv; argv++)
14 len++;
16 return len;
19 int cpp_exec(char *in_file, char *out_file, size_t out_len, char *const argv[])
21 size_t argc = 7 + argv_len(argv);
22 char *tmp = xstrdup(in_file);
23 char **cpp_argv;
24 int ret = 0;
25 char *base;
26 unsigned int i = 0;
28 base = basename(tmp);
29 slprintf(out_file, out_len, "/tmp/.tmp-%u-%s", rand(), base);
31 cpp_argv = xmalloc(argc * sizeof(char *));
33 cpp_argv[i++] = "cpp";
35 for (; argv && *argv; argv++, i++)
36 cpp_argv[i] = *argv;
38 cpp_argv[i++] = "-I";
39 cpp_argv[i++] = ETCDIRE_STRING;
40 cpp_argv[i++] = "-o";
41 cpp_argv[i++] = out_file;
42 cpp_argv[i++] = in_file;
43 cpp_argv[i++] = NULL;
45 if (proc_exec("cpp", cpp_argv))
46 ret = -1;
48 xfree(cpp_argv);
49 xfree(tmp);
50 return ret;