Source-Changes-HG archive

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

[.joined/src/trunk]: .joined/src/usr.bin/make make: fix error message when re...



details:   https://anonhg.NetBSD.org/.joined/src/rev/924cf37a9f4c
branches:  trunk
changeset: 359389:924cf37a9f4c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 01 21:41:50 2022 +0000

description:
make: fix error message when reading more than 1 GB from stdin

Previously, the error message was:
        make: (null): file too large
Now it is:
        make: (stdin): file too large

diffstat:

 usr.bin/make/main.c  |   6 +++---
 usr.bin/make/parse.c |  35 +++++++----------------------------
 2 files changed, 10 insertions(+), 31 deletions(-)

diffs (120 lines):

diff -r 6c39f5979137 -r 924cf37a9f4c usr.bin/make/main.c
--- a/usr.bin/make/main.c       Sat Jan 01 21:19:37 2022 +0000
+++ b/usr.bin/make/main.c       Sat Jan 01 21:41:50 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.564 2022/01/01 19:53:40 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.565 2022/01/01 21:41:50 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
 #include "trace.h"
 
 /*     "@(#)main.c     8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.564 2022/01/01 19:53:40 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.565 2022/01/01 21:41:50 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
            "The Regents of the University of California.  "
@@ -1643,7 +1643,7 @@
        char *name, *path = NULL;
 
        if (strcmp(fname, "-") == 0) {
-               Parse_File(NULL /*stdin*/, -1);
+               Parse_File("(stdin)", -1);
                Var_Set(SCOPE_INTERNAL, "MAKEFILE", "");
        } else {
                /* if we've chdir'd, rebuild the path name */
diff -r 6c39f5979137 -r 924cf37a9f4c usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Jan 01 21:19:37 2022 +0000
+++ b/usr.bin/make/parse.c      Sat Jan 01 21:41:50 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.612 2022/01/01 21:19:37 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.613 2022/01/01 21:41:50 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -110,7 +110,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.612 2022/01/01 21:19:37 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.613 2022/01/01 21:41:50 rillig Exp $");
 
 /* types and constants */
 
@@ -360,15 +360,6 @@
        return lf->buf;
 }
 
-/*
- * Read in a file.
- *
- * Until the path search logic can be moved under here instead of
- * being in the caller in another source file, we need to have the fd
- * passed in already open. Bleh.
- *
- * If the path is NULL, use stdin.
- */
 static struct loadedfile *
 loadfile(const char *path, int fd)
 {
@@ -377,11 +368,6 @@
        size_t bufSize;
        struct stat st;
 
-       if (path == NULL) {
-               assert(fd == -1);
-               fd = STDIN_FILENO;
-       }
-
        bufSize = fstat(fd, &st) == 0 && S_ISREG(st.st_mode) &&
                  st.st_size >= 0 && st.st_size <= 0x3fffffff
            ? (size_t)st.st_size : 1024;
@@ -412,9 +398,6 @@
        if (!Buf_EndsWith(&buf, '\n'))
                Buf_AddByte(&buf, '\n');
 
-       if (path != NULL)
-               close(fd);
-
        return loadedfile_create(buf.data, buf.len);
 }
 
@@ -2048,6 +2031,7 @@
 
        /* load it */
        lf = loadfile(fullname, fd);
+       (void)close(fd);
 
        /* Start reading from this file next */
        Parse_PushInput(fullname, 0, -1, loadedfile_readMore, lf);
@@ -3028,24 +3012,19 @@
 /*
  * Parse a top-level makefile, incorporating its content into the global
  * dependency graph.
- *
- * Input:
- *     name            The name of the file being read
- *     fd              The open file to parse; will be closed at the end
  */
 void
 Parse_File(const char *name, int fd)
 {
-       char *line;             /* the line we're working on */
+       char *line;
        struct loadedfile *lf;
 
-       lf = loadfile(name, fd);
+       lf = loadfile(name, fd != -1 ? fd : STDIN_FILENO);
+       if (fd != -1)
+               (void)close(fd);
 
        assert(targets == NULL);
 
-       if (name == NULL)
-               name = "(stdin)";
-
        Parse_PushInput(name, 0, -1, loadedfile_readMore, lf);
        CurFile()->lf = lf;
 



Home | Main Index | Thread Index | Old Index