Module Name:    src
Committed By:   rillig
Date:           Sat Jan  1 21:41:51 UTC 2022

Modified Files:
        src/usr.bin/make: main.c parse.c

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.564 -r1.565 src/usr.bin/make/main.c
cvs rdiff -u -r1.612 -r1.613 src/usr.bin/make/parse.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/make/main.c
diff -u src/usr.bin/make/main.c:1.564 src/usr.bin/make/main.c:1.565
--- src/usr.bin/make/main.c:1.564	Sat Jan  1 19:53:40 2022
+++ src/usr.bin/make/main.c	Sat Jan  1 21:41:50 2022
@@ -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 @@ ReadMakefile(const char *fname)
 	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 */

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.612 src/usr.bin/make/parse.c:1.613
--- src/usr.bin/make/parse.c:1.612	Sat Jan  1 21:19:37 2022
+++ src/usr.bin/make/parse.c	Sat Jan  1 21:41:50 2022
@@ -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 @@ loadedfile_readMore(void *x, size_t *len
 	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 @@ loadfile(const char *path, int fd)
 	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 @@ loadfile(const char *path, int fd)
 	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 @@ IncludeFile(const char *file, bool isSys
 
 	/* 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 @@ ParseLine(char *line)
 /*
  * 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;
 

Reply via email to