summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafał Miłecki2021-11-26 16:17:08 +0000
committerRafał Miłecki2021-12-02 07:33:30 +0000
commit0fbc13572cfbd8790faaf8299309204e05a1de62 (patch)
treecd31cead39c0b2a25b2df2e78080c85cbbe13cf1
parent58c9d5d8df39e57e703f9d3bd033ee595ed8cbac (diff)
downloadfirmware-utils-0fbc13572cfbd8790faaf8299309204e05a1de62.tar.gz
oseama: support extracting entity to stdout
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 <rafal@milecki.pl>
-rw-r--r--src/oseama.c21
1 files 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: