ref: 282737450582d791d93022c6ceceee29a97fc190
parent: b8385a50e3cffb224e889760a68f6f1c93844d6a
author: Rangi <35663410+Rangi42@users.noreply.github.com>
date: Sun Sep 25 00:02:53 EDT 2022
Use `STD*_FILENO` constants (#1055) These are defined in platform.h, but not consistently used Co-authored-by: Eldred Habert <eldredhabert0@gmail.com>
--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -492,7 +492,7 @@
if (strcmp(objectName, "-") != 0)
f = fopen(objectName, "wb");
else
- f = fdopen(1, "wb");
+ f = fdopen(STDOUT_FILENO, "wb");
if (!f)
err("Couldn't write file '%s'", objectName);
--- a/src/link/main.c
+++ b/src/link/main.c
@@ -154,9 +154,9 @@
if (strcmp(fileName, "-") != 0)
file = fopen(fileName, mode);
else if (mode[0] == 'r')
- file = fdopen(0, mode);
+ file = fdopen(STDIN_FILENO, mode);
else
- file = fdopen(1, mode);
+ file = fdopen(STDOUT_FILENO, mode);
if (!file)
err("Could not open file \"%s\"", fileName);
--- a/src/link/object.c
+++ b/src/link/object.c
@@ -459,7 +459,12 @@
void obj_ReadFile(char const *fileName, unsigned int fileID)
{
- FILE *file = strcmp("-", fileName) ? fopen(fileName, "rb") : stdin;
+ FILE *file;
+
+ if (strcmp("-", fileName) != 0)
+ file = fopen(fileName, "rb");
+ else
+ file = fdopen(STDIN_FILENO, "rb"); // `stdin` is in text mode by default
if (!file)
err("Could not open file %s", fileName);