aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMosder <git@mosder.eu>2026-10-13 19:40:11 +0200
committerMosder <git@mosder.eu>2026-10-13 19:40:11 +0200
commitec315985c9f51c932b1177539c43a024bf58207d (patch)
tree8b2b59e61a17b04f3f942ab903a08a4b58695b91
parent7698b0c7774f89b8329e898b534329f7a945cbd0 (diff)
fix: fixed flushing wrong stream and removed some POSIX deps
-rw-r--r--src/tester.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/tester.c b/src/tester.c
index c027811..05bc3d1 100644
--- a/src/tester.c
+++ b/src/tester.c
@@ -159,15 +159,15 @@ void mos_test_assert_out_fn(
FILE *tmp = mos_safe_tmpfile();
- int fd = fileno(stream);
+ int fd = mos_fileno(stream);
int og = mos_safe_dup(fd);
fflush(stream);
- mos_safe_dup2(fileno(tmp), fd);
+ mos_safe_dup2(mos_fileno(tmp), fd);
function();
fflush(stream);
- lseek(fd, 0, SEEK_SET);
- read(fd, out, n + 1);
+ rewind(tmp);
+ fread(out, 1, n + 1, tmp);
fclose(tmp);
mos_safe_dup2(og, fd);
@@ -190,15 +190,15 @@ void mos_suppress_output_fn(FILE *stream) {
suppressed.outs = mos_safe_realloc(suppressed.outs, suppressed.out_cap * sizeof(int));
suppressed.ogs = mos_safe_realloc(suppressed.ogs, suppressed.out_cap * sizeof(int));
}
- int fd = fileno(stream);
+ int fd = mos_fileno(stream);
suppressed.outs[suppressed.n_outs] = fd;
suppressed.ogs[suppressed.n_outs++] = mos_safe_dup(fd);
if (dev_null == NULL)
dev_null = mos_safe_tmpfile();
- fflush(NULL);
- mos_safe_dup2(fileno(dev_null), fd);
+ fflush(stream);
+ mos_safe_dup2(mos_fileno(dev_null), fd);
}
void mos_unsuppress_outputs(void) {
@@ -206,7 +206,7 @@ void mos_unsuppress_outputs(void) {
return;
if (dev_null != NULL)
- fflush(dev_null);
+ fflush(NULL);
for (size_t i = suppressed.n_outs; i-- > 0;) {
mos_safe_dup2(suppressed.ogs[i], suppressed.outs[i]);