From 14ad13bfc3e83e7b9befb78b837d28427d8eacdf Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:26 -0800 Subject: commands: loadb: Make use of open_and_lseek() Save a bit of extra code by replacing explict calls to open() and lseek() with a single call to open_and_lseek(). Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- commands/loadb.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'commands') diff --git a/commands/loadb.c b/commands/loadb.c index 8c3906ca42..37c272f6c7 100644 --- a/commands/loadb.c +++ b/commands/loadb.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -661,21 +662,11 @@ static int do_load_serial_bin(int argc, char *argv[]) output_file = DEF_FILE; /* File should exist */ - ofd = open(output_file, O_WRONLY | O_CREAT); + ofd = open_and_lseek(output_file, O_WRONLY | O_CREAT, offset); if (ofd < 0) { perror(argv[0]); return 3; } - /* Seek to the right offset */ - if (offset) { - int seek = lseek(ofd, offset, SEEK_SET); - if (seek != offset) { - close(ofd); - ofd = 0; - perror(argv[0]); - return 4; - } - } printf("## Ready for binary (kermit) download " "to 0x%08lX offset on %s device at %d bps...\n", offset, -- cgit v1.2.3