diff mbox series

tools: fix reading file from stdin for client example and make reading from stdin behavior more clear to the user

Message ID 20190426055609.10286-1-jneuhauser@dh-electronics.com
State Changes Requested
Headers show
Series tools: fix reading file from stdin for client example and make reading from stdin behavior more clear to the user | expand

Commit Message

Johann Neuhauser April 26, 2019, 5:56 a.m. UTC
Signed-off-by: Johann Neuhauser <jneuhauser@dh-electronics.com>
---
 tools/client.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/tools/client.c b/tools/client.c
index 0536cb2..6b42c08 100644
--- a/tools/client.c
+++ b/tools/client.c
@@ -35,10 +35,11 @@ 
 
 static void usage(void) {
 	printf("client <image .swu to be installed>...\n");
+	printf("\nWith - or no swu file given, read from STDIN.\n");
 }
 
 char buf[256];
-int fd;
+int fd = STDIN_FILENO;
 int verbose = 1;
 bool dryrun = false;
 int end_status = EXIT_SUCCESS;
@@ -99,7 +100,7 @@  static int end(RECOVERY_STATUS status)
  */
 static int send_file(const char* filename) {
 	int rc;
-	if ( (fd = open(filename, O_RDONLY)) < 0) {
+	if (filename && (fd = open(filename, O_RDONLY)) < 0) {
 		printf ("I cannot open %s\n", filename);
 		return EXIT_FAILURE;
 	}
@@ -166,6 +167,7 @@  int main(int argc, char *argv[]) {
 	argv += optind;
 
 	if (argc == 0 || (argc == 1 && strcmp(argv[0], "-") == 0)) {
+		printf("no input given, reading from STDIN...\n");
 		if (send_file(NULL)) exit(1);
 	} else {
 		for (int i = 0; i < argc; i++) {