Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint lint: remove unnecessary MBLKSIZ, use stack bu...



details:   https://anonhg.NetBSD.org/src/rev/4a9cf2347fb5
branches:  trunk
changeset: 373031:4a9cf2347fb5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 14 09:21:58 2023 +0000

description:
lint: remove unnecessary MBLKSIZ, use stack buffer in xlint

No functional change.

diffstat:

 usr.bin/xlint/common/param.h |   8 +-------
 usr.bin/xlint/xlint/xlint.c  |  17 ++++++-----------
 2 files changed, 7 insertions(+), 18 deletions(-)

diffs (81 lines):

diff -r a6335267fe7d -r 4a9cf2347fb5 usr.bin/xlint/common/param.h
--- a/usr.bin/xlint/common/param.h      Sat Jan 14 08:48:18 2023 +0000
+++ b/usr.bin/xlint/common/param.h      Sat Jan 14 09:21:58 2023 +0000
@@ -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.
diff -r a6335267fe7d -r 4a9cf2347fb5 usr.bin/xlint/xlint/xlint.c
--- a/usr.bin/xlint/xlint/xlint.c       Sat Jan 14 08:48:18 2023 +0000
+++ b/usr.bin/xlint/xlint/xlint.c       Sat Jan 14 09:21:58 2023 +0000
@@ -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 @@
 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);
 }



Home | Main Index | Thread Index | Old Index