diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2021-11-28 19:28:43 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2021-11-28 19:28:43 +0000 |
commit | 0a2b352b03317e999da1f6267e4f52c363714806 (patch) | |
tree | 4739c20bbb0e68615f4c3a44921e5c5a2755c787 /bin/cp | |
parent | 3401a7779d41e9ec5b75640de44fd2872b30d820 (diff) |
Stop using MAXBSIZE to eliminate sys/param.h including (which injects a
ton of namespace intrusion). Create local sizes, and refactor some code
along the way.
ok millert
Diffstat (limited to 'bin/cp')
-rw-r--r-- | bin/cp/utils.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/bin/cp/utils.c b/bin/cp/utils.c index 5c9c9e1b6c0..347081151f2 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -1,4 +1,4 @@ -/* $OpenBSD: utils.c,v 1.49 2021/10/24 21:24:21 deraadt Exp $ */ +/* $OpenBSD: utils.c,v 1.50 2021/11/28 19:28:41 deraadt Exp $ */ /* $NetBSD: utils.c,v 1.6 1997/02/26 14:40:51 cgd Exp $ */ /*- @@ -30,7 +30,7 @@ * SUCH DAMAGE. */ -#include <sys/param.h> /* MAXBSIZE */ +#include <sys/types.h> #include <sys/stat.h> #include <sys/mman.h> #include <sys/time.h> @@ -47,6 +47,8 @@ #include "extern.h" +#define _MAXBSIZE (64 * 1024) + int copy_overwrite(void); int @@ -56,17 +58,18 @@ copy_file(FTSENT *entp, int exists) static char *zeroes; struct stat to_stat, *fs; int from_fd, rcount, rval, to_fd, wcount; + const size_t buflen = _MAXBSIZE; #ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED char *p; #endif if (!buf) { - buf = malloc(MAXBSIZE); + buf = malloc(buflen); if (!buf) err(1, "malloc"); } if (!zeroes) { - zeroes = calloc(1, MAXBSIZE); + zeroes = calloc(1, buflen); if (!zeroes) err(1, "calloc"); } @@ -141,7 +144,7 @@ copy_file(FTSENT *entp, int exists) struct stat tosb; if (!fstat(to_fd, &tosb) && S_ISREG(tosb.st_mode)) skipholes = 1; - while ((rcount = read(from_fd, buf, MAXBSIZE)) > 0) { + while ((rcount = read(from_fd, buf, buflen)) > 0) { if (skipholes && memcmp(buf, zeroes, rcount) == 0) wcount = lseek(to_fd, rcount, SEEK_CUR) == -1 ? -1 : rcount; else |