[PATCH firmware-utils 2/2] oseama: support extracting entity to stdout
Rafał Miłecki
zajec5 at gmail.com
Fri Nov 26 08:17:08 PST 2021
From: Rafał Miłecki <rafal at milecki.pl>
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 at milecki.pl>
---
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.31.1
More information about the openwrt-devel
mailing list