Use setmode instead of fdopen (#1520)

This commit is contained in:
Sylvie
2024-09-29 14:06:59 -04:00
committed by GitHub
parent 9783671399
commit 4cd0dd5314
4 changed files with 18 additions and 9 deletions

View File

@@ -12,6 +12,7 @@
#include "error.hpp"
#include "helpers.hpp" // assume, Defer
#include "platform.hpp"
#include "asm/charmap.hpp"
#include "asm/fstack.hpp"
@@ -311,7 +312,8 @@ void out_WriteObject() {
file = fopen(objectFileName.c_str(), "wb");
} else {
objectFileName = "<stdout>";
file = fdopen(STDOUT_FILENO, "wb");
(void)setmode(STDOUT_FILENO, O_BINARY);
file = stdout;
}
if (!file)
err("Failed to open object file '%s'", objectFileName.c_str());
@@ -503,7 +505,8 @@ void out_WriteState(std::string name, std::vector<StateFeature> const &features)
file = fopen(name.c_str(), "wb");
} else {
name = "<stdout>";
file = fdopen(STDOUT_FILENO, "wb");
(void)setmode(STDOUT_FILENO, O_BINARY);
file = stdout;
}
if (!file)
err("Failed to open state file '%s'", name.c_str());