]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
ul_copy_file: use all_read/all_write
authorEgor Chelak <egor.chelak@gmail.com>
Fri, 6 Nov 2020 17:39:02 +0000 (19:39 +0200)
committerEgor Chelak <egor.chelak@gmail.com>
Mon, 9 Nov 2020 05:19:36 +0000 (07:19 +0200)
Suggested-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
lib/fileutils.c

index a166c5d41e93c046b88ebd51c283aac370271a85..61304c77ea5f842da525233e3e4d1f33f515084e 100644 (file)
@@ -17,6 +17,7 @@
 #include <string.h>
 
 #include "c.h"
+#include "all-io.h"
 #include "fileutils.h"
 #include "pathnames.h"
 
@@ -254,13 +255,12 @@ char *stripoff_last_component(char *path)
 
 static int copy_file_simple(int from, int to)
 {
-       ssize_t nr, nw, off;
+       ssize_t nr;
        char buf[BUFSIZ];
 
-       while ((nr = read(from, buf, sizeof(buf))) > 0)
-               for (off = 0; nr > 0; nr -= nw, off += nw)
-                       if ((nw = write(to, buf + off, nr)) < 0)
-                               return -2;
+       while ((nr = read_all(from, buf, sizeof(buf))) > 0)
+               if (write_all(to, buf, nr) == -1)
+                       return -2;
        if (nr < 0)
                return -1;
 #ifdef HAVE_EXPLICIT_BZERO