aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-11-26 10:09:55 +0100
committerlemon <lsof@mailbox.org>2025-11-26 10:09:55 +0100
commitb190f33220890babd0b753ae6a9fcfcf1cf026a9 (patch)
tree83f318fb2200ee9ea68b82ba750ec6ce4db99789
parent14d133398059981e328cb2b0b2b7b4ef0c3ec06a (diff)
use bstdout for -E
-rw-r--r--common.h2
-rw-r--r--main.c12
2 files changed, 7 insertions, 7 deletions
diff --git a/common.h b/common.h
index 1936c32..a1f1d21 100644
--- a/common.h
+++ b/common.h
@@ -338,7 +338,7 @@ struct wbuf {
union {
struct {
char *buf;
- const uint cap;
+ uint cap;
uint len;
int fd;
};
diff --git a/main.c b/main.c
index cadff6b..5b6a2e4 100644
--- a/main.c
+++ b/main.c
@@ -355,17 +355,17 @@ driver(void)
assert(*task.inft == IFTc && "nyi");
return cc1(task.out, *task.inf);
} else if (task.outft == OFTc) {
- static char tmp[1<<12];
- struct wbuf _buf = FDBUF(tmp, sizeof tmp, 1),
- *buf = &_buf;
- bool ok = 1;
+ struct wbuf _buf = {0}, *buf = &bstdout;
if (task.out) {
+ buf = &_buf;
+ buf->buf = alloc(&globarena, buf->cap = 1<<12, 1);
buf->fd = open(task.out, O_CREAT | O_TRUNC | O_WRONLY, 0777);
if (buf->fd < 0) {
error(NULL, "open(%'s): %s", task.out, strerror(errno));
return 1;
}
}
+ bool ok = 1;
if (!task.out && task.ninf == 1)
cpp(buf, task.inf[0]);
else for (int i = 0; i < task.ninf; ++i) {
@@ -383,9 +383,9 @@ driver(void)
if (!WIFEXITED(wstat)) ok = 0;
ok = ok && WEXITSTATUS(wstat) == 0;
}
- if (task.out) {
+ ioflush(buf);
+ if (task.out)
close(buf->fd);
- }
return ok ? 0 : 1;
} else if (task.outft == OFTexe || task.outft == OFTdll) {
compileobjs();