From 282737450582d791d93022c6ceceee29a97fc190 Mon Sep 17 00:00:00 2001 From: Rangi <35663410+Rangi42@users.noreply.github.com> Date: Sun, 25 Sep 2022 04:02:53 -0400 Subject: [PATCH] Use `STD*_FILENO` constants (#1055) These are defined in platform.h, but not consistently used Co-authored-by: Eldred Habert --- src/asm/output.c | 2 +- src/link/main.c | 4 ++-- src/link/object.c | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/asm/output.c b/src/asm/output.c index 888be27f..d2725de2 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -492,7 +492,7 @@ void out_WriteObject(void) 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); diff --git a/src/link/main.c b/src/link/main.c index 33292623..f162ad8b 100644 --- a/src/link/main.c +++ b/src/link/main.c @@ -154,9 +154,9 @@ FILE *openFile(char const *fileName, char const *mode) 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); diff --git a/src/link/object.c b/src/link/object.c index ab9bd6e5..89b7fa9f 100644 --- a/src/link/object.c +++ b/src/link/object.c @@ -459,7 +459,12 @@ static struct Section *getMainSection(struct Section *section) 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);