Module Name:    src
Committed By:   rillig
Date:           Fri Dec  3 23:29:30 UTC 2021

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

Log Message:
make: only allocate the name of an included file if necessary

The string passed to IncludeFile is only used during that function call,
it is not stored anywhere.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.566 -r1.567 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/parse.c
diff -u src/usr.bin/make/parse.c:1.566 src/usr.bin/make/parse.c:1.567
--- src/usr.bin/make/parse.c:1.566	Fri Dec  3 23:13:29 2021
+++ src/usr.bin/make/parse.c	Fri Dec  3 23:29:30 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.566 2021/12/03 23:13:29 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.567 2021/12/03 23:29:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.566 2021/12/03 23:13:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.567 2021/12/03 23:29:30 rillig Exp $");
 
 /* types and constants */
 
@@ -2123,7 +2123,7 @@ Parse_AddIncludeDir(const char *dir)
  * line options.
  */
 static void
-IncludeFile(char *file, bool isSystem, bool depinc, bool silent)
+IncludeFile(const char *file, bool isSystem, bool depinc, bool silent)
 {
 	struct loadedfile *lf;
 	char *fullname;		/* full pathname of file */
@@ -2237,8 +2237,8 @@ IncludeFile(char *file, bool isSystem, b
 static void
 ParseInclude(char *directive)
 {
-	char endc;		/* the character which ends the file spec */
-	char *p, *xfile;
+	char endc;		/* '>' or '"' */
+	char *p;
 	bool silent = directive[0] != 'i';
 	FStr file;
 
@@ -2269,11 +2269,15 @@ ParseInclude(char *directive)
 
 	*p = '\0';
 
-	(void)Var_Subst(file.str, SCOPE_CMDLINE, VARE_WANTRES, &xfile);
-	/* TODO: handle errors */
+	if (strchr(file.str, '$') != NULL) {
+		char *xfile;
+		Var_Subst(file.str, SCOPE_CMDLINE, VARE_WANTRES, &xfile);
+		/* TODO: handle errors */
+		file = FStr_InitOwn(xfile);
+	}
 
-	IncludeFile(xfile, endc == '>', directive[0] == 'd', silent);
-	free(xfile);
+	IncludeFile(file.str, endc == '>', directive[0] == 'd', silent);
+	FStr_Done(&file);
 }
 
 /*

Reply via email to