From e92fb432f7ec61d8cb2066dba38cf955dcd6c676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20H=C3=B6glund?= <jonas.hoglund@embeddednation.com> Date: Wed, 28 Apr 2021 10:06:23 +0200 Subject: [PATCH] Enable output of extrated file to stdout. --- fdtextract.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/fdtextract.c b/fdtextract.c index 460f0fb..91040aa 100644 --- a/fdtextract.c +++ b/fdtextract.c @@ -96,11 +96,6 @@ static int extract_image(char *buf, char *name, char *out) unsigned int data_size, data_offset; const fdt32_t *val; - if (!out) { - printf("Error: please specify output file name.\n"); - return -1; - } - snprintf(path, MAX_PATH_LEN, "/images/%s", name); noffset = fdt_path_offset(buf, path); if (noffset < 0) { @@ -108,8 +103,6 @@ static int extract_image(char *buf, char *name, char *out) return -1; } - printf("Extracting %s to %s.\n", name, out); - /* Get offset of image. Try both relative and absolute offset. */ val = fdt_getprop(buf, noffset, "data-offset", NULL); if(val) { @@ -135,11 +128,18 @@ static int extract_image(char *buf, char *name, char *out) data_size = fdt32_to_cpu(*val); - fd = open(out, O_WRONLY | O_CREAT | O_TRUNC, 0666); - if (fd < 0) { - printf("Error opening output file %s.\n", out); - return errno; + /* If output file is provided, write to that file. If not, write + to stdout. */ + if (out) { + fd = open(out, O_WRONLY | O_CREAT | O_TRUNC, 0666); + if (fd < 0) { + printf("Error opening output file %s.\n", out); + return errno; + } + } else { + fd = STDOUT_FILENO; } + count = write(fd, buf + data_offset, data_size); if (count < data_size) { printf("Error writing output file %s.\n", out); -- GitLab