From 0fbc13572cfbd8790faaf8299309204e05a1de62 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Fri, 26 Nov 2021 17:17:08 +0100 Subject: [PATCH] oseama: support extracting entity to stdout MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This allows using oseama in a pipe. It's very useful for writing data to flash using e.g. oseama extract firmware.bin -e 0 | mtd write - firmware Signed-off-by: Rafał Miłecki --- src/oseama.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/oseama.c b/src/oseama.c index d3eb9b9..f68d7d0 100644 --- a/src/oseama.c +++ b/src/oseama.c @@ -525,10 +525,6 @@ static int oseama_extract(int argc, char **argv) { fprintf(stderr, "No entity specified\n"); err = -EINVAL; goto out; - } else if (!out_path) { - fprintf(stderr, "No output file specified\n"); - err = -EINVAL; - goto out; } seama = oseama_open(seama_path, "r"); @@ -538,11 +534,15 @@ static int oseama_extract(int argc, char **argv) { goto out; } - out = fopen(out_path, "w"); - if (!out) { - fprintf(stderr, "Couldn't open %s\n", out_path); - err = -EACCES; - goto err_close_seama; + if (out_path) { + out = fopen(out_path, "w"); + if (!out) { + fprintf(stderr, "Couldn't open %s\n", out_path); + err = -EACCES; + goto err_close_seama; + } + } else { + out = stdout; } bytes = fread(&hdr, 1, sizeof(hdr), seama); @@ -558,7 +558,8 @@ static int oseama_extract(int argc, char **argv) { oseama_extract_entity(seama, out); err_close_out: - fclose(out); + if (out != stdout) + fclose(out); err_close_seama: oseama_close(seama); out: -- 2.30.2