diff options
| author | Chloe M <chloe@faracom.org> | 2026-08-21 00:38:13 -0500 |
|---|---|---|
| committer | Chloe M <chloe@aptel.org> | 2026-08-21 00:56:13 -0500 |
| commit | fb6440da4eb9ce7a2c3c7504440d1befb2759135 (patch) | |
| tree | 2220b86a630a9c4558b889bb0eead5567574c0bd /core/build.c | |
| parent | db850c6e046f681feedcf6e0fe1577d183fd940a (diff) | |
core: build: Simplify CC invocation via popen(3)
Signed-off-by: Chloe M <chloe@aptel.org>
Diffstat (limited to 'core/build.c')
| -rw-r--r-- | core/build.c | 26 |
1 files changed, 15 insertions, 11 deletions
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 |
