ref: 0bb5efebfdc50024b3752ce2b82f4f1366a29c99
parent: b6bf7ae6206ca0c755414679e311aed082fa4473
parent: 642daf1a76847fbe4b361f3d0810b60c41aad89e
author: Eldred Habert <eldredhabert0@gmail.com>
date: Sat Nov 7 20:20:44 EST 2020
Merge pull request #610 from daid/stdin Allow rgbasm and rgblink to use stdout and stdin as input and output
--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -471,7 +471,11 @@
*/
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)
err(1, "Couldn't write file '%s'", tzObjectname);
--- a/src/link/main.c
+++ b/src/link/main.c
@@ -13,6 +13,7 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -126,7 +127,13 @@
if (!fileName)
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)
err(1, "Could not open file \"%s\"", fileName);