ref: 7e620bff817c5826adc5a73acd7bc1774d835c74
parent: 0c5570343857570493deadf4b7933bebf5a31a0d
author: Daid <[email protected]>
date: Mon Oct 26 16:28:15 EDT 2020
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,12 @@
*/
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,14 @@
if (!fileName)
return NULL;
- FILE *file = fopen(fileName, mode);
+ FILE *file;
+ if (strcmp(fileName, "-") != 0) {
+ file = fopen(fileName, mode);
+ } else if (strchr(mode, 'r')) {
+ file = fdopen(0, mode);
+ } else {
+ file = fdopen(1, mode);
+ }
if (!file)
err(1, "Could not open file \"%s\"", fileName);