Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use setmode instead of fdopen #1520

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/asm/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "error.hpp"
#include "helpers.hpp" // assume, Defer
#include "platform.hpp"

#include "asm/charmap.hpp"
#include "asm/fstack.hpp"
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
5 changes: 3 additions & 2 deletions src/fix/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,9 +1160,9 @@ static bool processFilename(char const *name) {
nbErrors = 0;

if (!strcmp(name, "-")) {
name = "<stdin>";
(void)setmode(STDIN_FILENO, O_BINARY);
(void)setmode(STDOUT_FILENO, O_BINARY);
name = "<stdin>";
processFile(STDIN_FILENO, STDOUT_FILENO, name, 0);
} else {
// POSIX specifies that the results of O_RDWR on a FIFO are undefined.
Expand Down Expand Up @@ -1435,7 +1435,8 @@ int main(int argc, char *argv[]) {
logoFile = fopen(logoFilename, "rb");
} else {
logoFilename = "<stdin>";
logoFile = fdopen(STDIN_FILENO, "rb");
(void)setmode(STDIN_FILENO, O_BINARY);
logoFile = stdin;
}
if (!logoFile) {
fprintf(
Expand Down
3 changes: 2 additions & 1 deletion src/link/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
file = fopen(fileName, "rb");
} else {
fileName = "<stdin>";
file = fdopen(STDIN_FILENO, "rb"); // `stdin` is in text mode by default
(void)setmode(STDIN_FILENO, O_BINARY);
file = stdin;
}
if (!file)
err("Failed to open file \"%s\"", fileName);
Expand Down
12 changes: 8 additions & 4 deletions src/link/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ static void writeROM() {
outputFile = fopen(outputFileName, "wb");
} else {
outputFileName = "<stdout>";
outputFile = fdopen(STDOUT_FILENO, "wb");
(void)setmode(STDOUT_FILENO, O_BINARY);
outputFile = stdout;
}
if (!outputFile)
err("Failed to open output file \"%s\"", outputFileName);
Expand All @@ -222,7 +223,8 @@ static void writeROM() {
overlayFile = fopen(overlayFileName, "rb");
} else {
overlayFileName = "<stdin>";
overlayFile = fdopen(STDIN_FILENO, "rb");
(void)setmode(STDIN_FILENO, O_BINARY);
overlayFile = stdin;
}
if (!overlayFile)
err("Failed to open overlay file \"%s\"", overlayFileName);
Expand Down Expand Up @@ -545,7 +547,8 @@ static void writeSym() {
symFile = fopen(symFileName, "w");
} else {
symFileName = "<stdout>";
symFile = fdopen(STDOUT_FILENO, "w");
(void)setmode(STDOUT_FILENO, O_TEXT); // May have been set to O_BINARY previously
symFile = stdout;
}
if (!symFile)
err("Failed to open sym file \"%s\"", symFileName);
Expand Down Expand Up @@ -589,7 +592,8 @@ static void writeMap() {
mapFile = fopen(mapFileName, "w");
} else {
mapFileName = "<stdout>";
mapFile = fdopen(STDOUT_FILENO, "w");
(void)setmode(STDOUT_FILENO, O_TEXT); // May have been set to O_BINARY previously
mapFile = stdout;
}
if (!mapFile)
err("Failed to open map file \"%s\"", mapFileName);
Expand Down