From 685e64fda2573c0e4b9379d1df366762104993c7 Mon Sep 17 00:00:00 2001 From: Pierre-Hugues Husson Date: Sat, 9 May 2020 14:02:50 +0200 Subject: [PATCH] [simg2img_simple] Don't break when splice doesn't work (over adb for instance) --- cmds/simg2img_simple.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmds/simg2img_simple.cpp b/cmds/simg2img_simple.cpp index f8a25a3..d6640de 100644 --- a/cmds/simg2img_simple.cpp +++ b/cmds/simg2img_simple.cpp @@ -42,8 +42,15 @@ typedef struct chunk_header { */ void nsendfile(int out_fd, int in_fd, size_t count) { + char buf[1024*1024]; while(count) { ssize_t res = splice(in_fd, NULL, out_fd, NULL, count, 0); + if(res==-1) { + ssize_t sizeToRead = sizeof(buf); + if(count < sizeToRead) sizeToRead = count; + res = read(in_fd, buf, sizeToRead); + if(write(out_fd, buf, res) != res) exit(114); + } if(res == 0 || res == -1) exit(112); count -= res; }