From 408c741232b001894e12287f240b3e6c33efada8 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Wed, 6 Oct 2021 15:14:22 +0200 Subject: scripts/common: Add write_full() and read_full() We have different implementations of read_full() and write_full() in our host tools, use a common implementation for these. Signed-off-by: Sascha Hauer --- scripts/rkimage.c | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) (limited to 'scripts/rkimage.c') diff --git a/scripts/rkimage.c b/scripts/rkimage.c index dde9724886..21a2838146 100644 --- a/scripts/rkimage.c +++ b/scripts/rkimage.c @@ -13,6 +13,9 @@ #include #include +#include "common.h" +#include "common.c" + #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) @@ -149,42 +152,6 @@ static void usage(const char *prgname) prgname); } -static int read_full(int fd, void *buf, size_t size) -{ - size_t insize = size; - int now; - int total = 0; - - while (size) { - now = read(fd, buf, size); - if (now == 0) - return total; - if (now < 0) - return now; - total += now; - size -= now; - buf += now; - } - - return insize; -} - -static int write_full(int fd, void *buf, size_t size) -{ - size_t insize = size; - int now; - - while (size) { - now = write(fd, buf, size); - if (now <= 0) - return now; - size -= now; - buf += now; - } - - return insize; -} - int main(int argc, char *argv[]) { int opt, i, fd; -- cgit v1.2.3