mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Use setmode instead of fdopen (#1520)
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "error.hpp"
|
#include "error.hpp"
|
||||||
#include "helpers.hpp" // assume, Defer
|
#include "helpers.hpp" // assume, Defer
|
||||||
|
#include "platform.hpp"
|
||||||
|
|
||||||
#include "asm/charmap.hpp"
|
#include "asm/charmap.hpp"
|
||||||
#include "asm/fstack.hpp"
|
#include "asm/fstack.hpp"
|
||||||
@@ -311,7 +312,8 @@ void out_WriteObject() {
|
|||||||
file = fopen(objectFileName.c_str(), "wb");
|
file = fopen(objectFileName.c_str(), "wb");
|
||||||
} else {
|
} else {
|
||||||
objectFileName = "<stdout>";
|
objectFileName = "<stdout>";
|
||||||
file = fdopen(STDOUT_FILENO, "wb");
|
(void)setmode(STDOUT_FILENO, O_BINARY);
|
||||||
|
file = stdout;
|
||||||
}
|
}
|
||||||
if (!file)
|
if (!file)
|
||||||
err("Failed to open object file '%s'", objectFileName.c_str());
|
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");
|
file = fopen(name.c_str(), "wb");
|
||||||
} else {
|
} else {
|
||||||
name = "<stdout>";
|
name = "<stdout>";
|
||||||
file = fdopen(STDOUT_FILENO, "wb");
|
(void)setmode(STDOUT_FILENO, O_BINARY);
|
||||||
|
file = stdout;
|
||||||
}
|
}
|
||||||
if (!file)
|
if (!file)
|
||||||
err("Failed to open state file '%s'", name.c_str());
|
err("Failed to open state file '%s'", name.c_str());
|
||||||
|
|||||||
@@ -1160,9 +1160,9 @@ static bool processFilename(char const *name) {
|
|||||||
nbErrors = 0;
|
nbErrors = 0;
|
||||||
|
|
||||||
if (!strcmp(name, "-")) {
|
if (!strcmp(name, "-")) {
|
||||||
|
name = "<stdin>";
|
||||||
(void)setmode(STDIN_FILENO, O_BINARY);
|
(void)setmode(STDIN_FILENO, O_BINARY);
|
||||||
(void)setmode(STDOUT_FILENO, O_BINARY);
|
(void)setmode(STDOUT_FILENO, O_BINARY);
|
||||||
name = "<stdin>";
|
|
||||||
processFile(STDIN_FILENO, STDOUT_FILENO, name, 0);
|
processFile(STDIN_FILENO, STDOUT_FILENO, name, 0);
|
||||||
} else {
|
} else {
|
||||||
// POSIX specifies that the results of O_RDWR on a FIFO are undefined.
|
// POSIX specifies that the results of O_RDWR on a FIFO are undefined.
|
||||||
@@ -1435,7 +1435,8 @@ int main(int argc, char *argv[]) {
|
|||||||
logoFile = fopen(logoFilename, "rb");
|
logoFile = fopen(logoFilename, "rb");
|
||||||
} else {
|
} else {
|
||||||
logoFilename = "<stdin>";
|
logoFilename = "<stdin>";
|
||||||
logoFile = fdopen(STDIN_FILENO, "rb");
|
(void)setmode(STDIN_FILENO, O_BINARY);
|
||||||
|
logoFile = stdin;
|
||||||
}
|
}
|
||||||
if (!logoFile) {
|
if (!logoFile) {
|
||||||
fprintf(
|
fprintf(
|
||||||
|
|||||||
@@ -490,7 +490,8 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
|
|||||||
file = fopen(fileName, "rb");
|
file = fopen(fileName, "rb");
|
||||||
} else {
|
} else {
|
||||||
fileName = "<stdin>";
|
fileName = "<stdin>";
|
||||||
file = fdopen(STDIN_FILENO, "rb"); // `stdin` is in text mode by default
|
(void)setmode(STDIN_FILENO, O_BINARY);
|
||||||
|
file = stdin;
|
||||||
}
|
}
|
||||||
if (!file)
|
if (!file)
|
||||||
err("Failed to open file \"%s\"", fileName);
|
err("Failed to open file \"%s\"", fileName);
|
||||||
|
|||||||
@@ -207,7 +207,8 @@ static void writeROM() {
|
|||||||
outputFile = fopen(outputFileName, "wb");
|
outputFile = fopen(outputFileName, "wb");
|
||||||
} else {
|
} else {
|
||||||
outputFileName = "<stdout>";
|
outputFileName = "<stdout>";
|
||||||
outputFile = fdopen(STDOUT_FILENO, "wb");
|
(void)setmode(STDOUT_FILENO, O_BINARY);
|
||||||
|
outputFile = stdout;
|
||||||
}
|
}
|
||||||
if (!outputFile)
|
if (!outputFile)
|
||||||
err("Failed to open output file \"%s\"", outputFileName);
|
err("Failed to open output file \"%s\"", outputFileName);
|
||||||
@@ -222,7 +223,8 @@ static void writeROM() {
|
|||||||
overlayFile = fopen(overlayFileName, "rb");
|
overlayFile = fopen(overlayFileName, "rb");
|
||||||
} else {
|
} else {
|
||||||
overlayFileName = "<stdin>";
|
overlayFileName = "<stdin>";
|
||||||
overlayFile = fdopen(STDIN_FILENO, "rb");
|
(void)setmode(STDIN_FILENO, O_BINARY);
|
||||||
|
overlayFile = stdin;
|
||||||
}
|
}
|
||||||
if (!overlayFile)
|
if (!overlayFile)
|
||||||
err("Failed to open overlay file \"%s\"", overlayFileName);
|
err("Failed to open overlay file \"%s\"", overlayFileName);
|
||||||
@@ -545,7 +547,8 @@ static void writeSym() {
|
|||||||
symFile = fopen(symFileName, "w");
|
symFile = fopen(symFileName, "w");
|
||||||
} else {
|
} else {
|
||||||
symFileName = "<stdout>";
|
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)
|
if (!symFile)
|
||||||
err("Failed to open sym file \"%s\"", symFileName);
|
err("Failed to open sym file \"%s\"", symFileName);
|
||||||
@@ -589,7 +592,8 @@ static void writeMap() {
|
|||||||
mapFile = fopen(mapFileName, "w");
|
mapFile = fopen(mapFileName, "w");
|
||||||
} else {
|
} else {
|
||||||
mapFileName = "<stdout>";
|
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)
|
if (!mapFile)
|
||||||
err("Failed to open map file \"%s\"", mapFileName);
|
err("Failed to open map file \"%s\"", mapFileName);
|
||||||
|
|||||||
Reference in New Issue
Block a user