The branch main has been updated by markj:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=a03d150a3d44c49344ebd0862defd1a5ad1f524e

commit a03d150a3d44c49344ebd0862defd1a5ad1f524e
Author:     Mark Johnston <[email protected]>
AuthorDate: 2025-09-18 22:39:39 +0000
Commit:     Mark Johnston <[email protected]>
CommitDate: 2025-09-18 22:39:39 +0000

    pw: Use copy_file_range() when copying skeleton files
    
    As a bonus, check for I/O errors and print them to standard error.
    
    Reviewed by:    bapt, emaste
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Sponsored by:   Klara, Inc.
    Differential Revision:  https://reviews.freebsd.org/D52588
---
 usr.sbin/pw/cpdir.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/usr.sbin/pw/cpdir.c b/usr.sbin/pw/cpdir.c
index 63068cab000c..3839a039495a 100644
--- a/usr.sbin/pw/cpdir.c
+++ b/usr.sbin/pw/cpdir.c
@@ -36,10 +36,10 @@
 #include "pw.h"
 
 void
-copymkdir(int rootfd, char const * dir, int skelfd, mode_t mode, uid_t uid,
+copymkdir(int rootfd, char const *dir, int skelfd, mode_t mode, uid_t uid,
     gid_t gid, int flags)
 {
-       char            *p, lnk[MAXPATHLEN], copybuf[4096];
+       char            *p, lnk[MAXPATHLEN];
        int             len, homefd, srcfd, destfd;
        ssize_t         sz;
        struct stat     st;
@@ -120,8 +120,12 @@ copymkdir(int rootfd, char const * dir, int skelfd, mode_t 
mode, uid_t uid,
                        continue;
                }
 
-               while ((sz = read(srcfd, copybuf, sizeof(copybuf))) > 0)
-                       write(destfd, copybuf, sz);
+               do {
+                       sz = copy_file_range(srcfd, NULL, destfd, NULL,
+                           SSIZE_MAX, 0);
+               } while (sz > 0);
+               if (sz < 0)
+                       warn("copy_file_range");
 
                close(srcfd);
                /*

Reply via email to