Merge pull request #610 from daid/stdin

Allow rgbasm and rgblink to use stdout and stdin as input and output
This commit is contained in:
Eldred Habert
2020-11-08 01:20:44 +01:00
committed by GitHub
2 changed files with 13 additions and 2 deletions

View File

@@ -471,7 +471,11 @@ static void registerExportedSymbol(struct Symbol *symbol, void *arg)
*/ */
void out_WriteObject(void) void out_WriteObject(void)
{ {
FILE *f = fopen(tzObjectname, "wb"); FILE *f;
if (strcmp(tzObjectname, "-") != 0)
f = fopen(tzObjectname, "wb");
else
f = fdopen(1, "wb");
if (!f) if (!f)
err(1, "Couldn't write file '%s'", tzObjectname); err(1, "Couldn't write file '%s'", tzObjectname);

View File

@@ -13,6 +13,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
@@ -126,7 +127,13 @@ FILE *openFile(char const *fileName, char const *mode)
if (!fileName) if (!fileName)
return NULL; return NULL;
FILE *file = fopen(fileName, mode); FILE *file;
if (strcmp(fileName, "-") != 0)
file = fopen(fileName, mode);
else if (mode[0] == 'r')
file = fdopen(0, mode);
else
file = fdopen(1, mode);
if (!file) if (!file)
err(1, "Could not open file \"%s\"", fileName); err(1, "Could not open file \"%s\"", fileName);