aboutsummaryrefslogtreecommitdiffstats
path: root/flashrom.c
diff options
context:
space:
mode:
authorDaniel Campello <campello@chromium.org>2021-04-15 10:36:04 -0600
committerEdward O'Callaghan <quasisec@chromium.org>2021-04-29 23:53:21 +0000
commitd4063bf3a7f5fd7831ee0321def13161976676d2 (patch)
tree1d6e44bb4c9f2aea393d7764e7885aa48ada2dbb /flashrom.c
parent4cc7363d2520825aa300d81a67de71aede193f15 (diff)
downloadflashrom-d4063bf3a7f5fd7831ee0321def13161976676d2.tar.gz
flashrom-d4063bf3a7f5fd7831ee0321def13161976676d2.tar.bz2
flashrom-d4063bf3a7f5fd7831ee0321def13161976676d2.zip
flashrom.c: allow - as filename for stdin
Allows - as filename for -w/-v options. It is sometimes useful to script flashrom and allowing it to work with pipes allows for more flexibility in this specific use-case. Signed-off-by: Daniel Campello <campello@chromium.org> Change-Id: I97889cfdf7ba9a257e182c4ee2b20075cfa58d4d Reviewed-on: https://review.coreboot.org/c/flashrom/+/52383 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Diffstat (limited to 'flashrom.c')
-rw-r--r--flashrom.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/flashrom.c b/flashrom.c
index 3a733df6..e1121d86 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -1348,7 +1348,11 @@ int read_buf_from_file(unsigned char *buf, unsigned long size,
int ret = 0;
FILE *image;
- if ((image = fopen(filename, "rb")) == NULL) {
+ if (!strcmp(filename, "-"))
+ image = fdopen(fileno(stdin), "rb");
+ else
+ image = fopen(filename, "rb");
+ if (image == NULL) {
msg_gerr("Error: opening file \"%s\" failed: %s\n", filename, strerror(errno));
return 1;
}
@@ -1359,7 +1363,7 @@ int read_buf_from_file(unsigned char *buf, unsigned long size,
ret = 1;
goto out;
}
- if (image_stat.st_size != (intmax_t)size) {
+ if ((image_stat.st_size != (intmax_t)size) && strcmp(filename, "-")) {
msg_gerr("Error: Image size (%jd B) doesn't match the expected size (%lu B)!\n",
(intmax_t)image_stat.st_size, size);
ret = 1;