Module Name: src Committed By: rillig Date: Sat Jan 14 09:21:58 UTC 2023
Modified Files: src/usr.bin/xlint/common: param.h src/usr.bin/xlint/xlint: xlint.c Log Message: lint: remove unnecessary MBLKSIZ, use stack buffer in xlint No functional change. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/usr.bin/xlint/common/param.h cvs rdiff -u -r1.95 -r1.96 src/usr.bin/xlint/xlint/xlint.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/xlint/common/param.h diff -u src/usr.bin/xlint/common/param.h:1.9 src/usr.bin/xlint/common/param.h:1.10 --- src/usr.bin/xlint/common/param.h:1.9 Tue Aug 3 17:27:48 2021 +++ src/usr.bin/xlint/common/param.h Sat Jan 14 09:21:58 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.9 2021/08/03 17:27:48 rillig Exp $ */ +/* $NetBSD: param.h,v 1.10 2023/01/14 09:21:58 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -32,12 +32,6 @@ */ /* - * The size of memory blocks which are used to allocate memory in larger - * chunks. - */ -#define MBLKSIZ ((size_t)0x4000) - -/* * Sizes of hash tables * Should be primes. Possible primes are * 307, 401, 503, 601, 701, 809, 907, 1009, 1103, 1201, 1301, 1409, 1511. Index: src/usr.bin/xlint/xlint/xlint.c diff -u src/usr.bin/xlint/xlint/xlint.c:1.95 src/usr.bin/xlint/xlint/xlint.c:1.96 --- src/usr.bin/xlint/xlint/xlint.c:1.95 Sat Oct 1 09:48:02 2022 +++ src/usr.bin/xlint/xlint/xlint.c Sat Jan 14 09:21:58 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: xlint.c,v 1.95 2022/10/01 09:48:02 rillig Exp $ */ +/* $NetBSD: xlint.c,v 1.96 2023/01/14 09:21:58 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: xlint.c,v 1.95 2022/10/01 09:48:02 rillig Exp $"); +__RCSID("$NetBSD: xlint.c,v 1.96 2023/01/14 09:21:58 rillig Exp $"); #endif #include <sys/param.h> @@ -915,36 +915,31 @@ static void cat(char *const *srcs, const char *dest) { int ifd, ofd, i; - char *src, *buf; + char *src; ssize_t rlen; + char buf[0x4000]; if ((ofd = open(dest, O_WRONLY | O_CREAT | O_TRUNC, 0666)) == -1) { warn("cannot open %s", dest); terminate(-1); } - buf = xmalloc(MBLKSIZ); - for (i = 0; (src = srcs[i]) != NULL; i++) { if ((ifd = open(src, O_RDONLY)) == -1) { - free(buf); warn("cannot open %s", src); terminate(-1); } do { - if ((rlen = read(ifd, buf, MBLKSIZ)) == -1) { - free(buf); + if ((rlen = read(ifd, buf, sizeof(buf))) == -1) { warn("read error on %s", src); terminate(-1); } if (write(ofd, buf, (size_t)rlen) == -1) { - free(buf); warn("write error on %s", dest); terminate(-1); } - } while (rlen == MBLKSIZ); + } while (rlen == sizeof(buf)); (void)close(ifd); } (void)close(ofd); - free(buf); }