[PATCH 17/17] commands: loadb: Make use of open_and_lseek()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <andrew.smirnov@xxxxxxxxx>
---
 commands/loadb.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/commands/loadb.c b/commands/loadb.c
index 8c3906ca4..a1f6e63ec 100644
--- a/commands/loadb.c
+++ b/commands/loadb.c
@@ -661,21 +661,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,
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux