Use cpp_exec func to invoke C preprocesor.

Signed-off-by: Vadim Kochan <[email protected]>
---
 trafgen/Makefile |  1 +
 trafgen_parser.y | 14 ++------------
 2 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/trafgen/Makefile b/trafgen/Makefile
index 9777485..bc256b2 100644
--- a/trafgen/Makefile
+++ b/trafgen/Makefile
@@ -18,6 +18,7 @@ trafgen-objs =        xmalloc.o \
                ring.o \
                timer.o \
                sysctl.o \
+               cpp.o \
                trafgen_lexer.yy.o \
                trafgen_parser.tab.o \
                trafgen.o
diff --git a/trafgen_parser.y b/trafgen_parser.y
index a05b7e8..afcb3e2 100644
--- a/trafgen_parser.y
+++ b/trafgen_parser.y
@@ -25,6 +25,7 @@
 #include "die.h"
 #include "str.h"
 #include "csum.h"
+#include "cpp.h"
 
 #define YYERROR_VERBOSE                0
 #define YYDEBUG                        0
@@ -598,22 +599,11 @@ void compile_packets(char *file, bool verbose, unsigned 
int cpu, bool invoke_cpp
        our_cpu = cpu;
 
        if (invoke_cpp) {
-               char cmd[256], *dir, *base, *a, *b;
-
-               dir = dirname((a = xstrdup(file)));
-               base = basename((b = xstrdup(file)));
-
-               slprintf(tmp_file, sizeof(tmp_file), "%s/.tmp-%u-%s", dir, 
rand(), base);
-               slprintf(cmd, sizeof(cmd), "cpp -I" ETCDIRE_STRING " %s > %s",
-                        file, tmp_file);
-               if (system(cmd) != 0) {
+               if (cpp_exec(file, tmp_file, sizeof(tmp_file))) {
                        fprintf(stderr, "Failed to invoke C preprocessor!\n");
                        goto err;
                }
-
                file = tmp_file;
-               xfree(a);
-               xfree(b);
        }
 
        if (!strncmp("-", file, strlen("-")))
-- 
2.6.2

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to