From fb6440da4eb9ce7a2c3c7504440d1befb2759135 Mon Sep 17 00:00:00 2001 From: Chloe M Date: Fri, 21 Aug 2026 00:38:13 -0500 Subject: core: build: Simplify CC invocation via popen(3) Signed-off-by: Chloe M --- core/build.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'core/build.c') diff --git a/core/build.c b/core/build.c index b61ab3c..c82436f 100644 --- a/core/build.c +++ b/core/build.c @@ -88,10 +88,11 @@ trunc_extension(const char *filename) static int invoke_cc(const char *cfile_path, struct build_params *params) { - pid_t child; - int status; char *trunc_ext; + char cmdbuf[128]; char outpath[256]; + char outbuf[32]; + FILE *pipe; if (cfile_path == NULL || params == NULL) { return -1; @@ -103,17 +104,20 @@ invoke_cc(const char *cfile_path, struct build_params *params) } snprintf(outpath, sizeof(outpath), "%s.o", trunc_ext); - child = fork(); - if (child == 0) { - printf("[CC]\t\t%s\n", cfile_path); - execl(BOP_CC, BOP_CC, "-c", cfile_path, "-o", outpath, BOP_DEFAULT_CFLAGS, NULL); - } else { - waitpid(child, &status, 0); - free(trunc_ext); - return status; + snprintf(cmdbuf, sizeof(cmdbuf), "%s -c %s -o %s", BOP_CC, cfile_path, outpath); + + if ((pipe = popen(cmdbuf, "r")) == NULL) { + printf("fatal: failed to invoke cc\n"); + return -1; } - return -1; + printf("[CC]\t\t%s\n", cfile_path); + while ((fgets(outbuf, sizeof(outbuf), pipe)) != NULL) { + printf("%s", outbuf); + } + + pclose(pipe); + return 0; } static int -- cgit v1.2.3