Avoid closing stdin/stdout/stderr standard streams

This commit is contained in:
Rangi committed 2026-07-13 13:02:46 -04:00
1 parent 8ab6190f96
commit e9fa1e4e94
11 files changed
+42 -22

No files matched your search

+4 -5
View File
@@ -15,6 +15,7 @@
#include "diagnostics.hpp"
#include "helpers.hpp"
#include "platform.hpp"
#include "util.hpp" // xclose, xfclose
#include "fix/main.hpp"
#include "fix/mbc.hpp"
@@ -463,7 +464,6 @@ bool fix_ProcessFile(char const *name, char const *outputName) {
}
int output = -1;
bool openedOutput = false;
if (outputName) {
if (!strcmp(outputName, "-")) {
output = STDOUT_FILENO;
@@ -476,12 +476,11 @@ bool fix_ProcessFile(char const *name, char const *outputName) {
return true;
// LCOV_EXCL_STOP
}
openedOutput = true;
}
}
Defer closeOutput{[&] {
if (openedOutput) {
close(output);
if (outputName) {
xclose(output);
}
}};
@@ -497,7 +496,7 @@ bool fix_ProcessFile(char const *name, char const *outputName) {
// operations may fail, all of which we handle.
error("Failed to open \"%s\" for reading+writing: %s", name, strerror(errno));
} else {
Defer closeInput{[&] { close(input); }};
Defer closeInput{[&] { xclose(input); }};
struct stat stat;
if (fstat(input, &stat) == -1) {
error("Failed to stat \"%s\": %s", name, strerror(errno)); // LCOV_EXCL_LINE
+1 -1
View File
@@ -308,7 +308,7 @@ static void initLogo() {
fatal("Failed to open \"%s\" for reading: %s", logoFilename, strerror(errno));
// LCOV_EXCL_STOP
}
Defer closeLogo{[&] { fclose(logoFile); }};
Defer closeLogo{[&] { xfclose(logoFile); }};
uint8_t logoBpp[sizeof(options.logo)];
if (size_t nbRead = fread(logoBpp, 1, sizeof(logoBpp), logoFile);