Module Name:    src
Committed By:   rillig
Date:           Sat Aug 29 11:24:54 UTC 2020

Modified Files:
        src/usr.bin/make: make_malloc.c make_malloc.h parse.c suff.c var.c

Log Message:
make(1): add bmake_strsedup for duplicating a substring


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/make/make_malloc.c
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/make_malloc.h
cvs rdiff -u -r1.270 -r1.271 src/usr.bin/make/parse.c
cvs rdiff -u -r1.132 -r1.133 src/usr.bin/make/suff.c
cvs rdiff -u -r1.473 -r1.474 src/usr.bin/make/var.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/make_malloc.c
diff -u src/usr.bin/make/make_malloc.c:1.15 src/usr.bin/make/make_malloc.c:1.16
--- src/usr.bin/make/make_malloc.c:1.15	Thu Aug 20 06:35:14 2020
+++ src/usr.bin/make/make_malloc.c	Sat Aug 29 11:24:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make_malloc.c,v 1.15 2020/08/20 06:35:14 rillig Exp $	*/
+/*	$NetBSD: make_malloc.c,v 1.16 2020/08/29 11:24:54 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
 
 #ifdef MAKE_NATIVE
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: make_malloc.c,v 1.15 2020/08/20 06:35:14 rillig Exp $");
+__RCSID("$NetBSD: make_malloc.c,v 1.16 2020/08/29 11:24:54 rillig Exp $");
 #endif
 
 #include <stdio.h>
@@ -92,6 +92,13 @@ bmake_strldup(const char *str, size_t le
 	return p;
 }
 
+/* Allocate a string from start up to but excluding end. */
+char *
+bmake_strsedup(const char *start, const char *end)
+{
+	return bmake_strldup(start, (size_t)(end - start));
+}
+
 /*
  * bmake_realloc --
  *	realloc, but die on error.

Index: src/usr.bin/make/make_malloc.h
diff -u src/usr.bin/make/make_malloc.h:1.8 src/usr.bin/make/make_malloc.h:1.9
--- src/usr.bin/make/make_malloc.h:1.8	Tue Aug 25 17:37:09 2020
+++ src/usr.bin/make/make_malloc.h	Sat Aug 29 11:24:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make_malloc.h,v 1.8 2020/08/25 17:37:09 rillig Exp $	*/
+/*	$NetBSD: make_malloc.h,v 1.9 2020/08/29 11:24:54 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -31,6 +31,7 @@ void *bmake_malloc(size_t);
 void *bmake_realloc(void *, size_t);
 char *bmake_strdup(const char *);
 char *bmake_strldup(const char *, size_t);
+char *bmake_strsedup(const char *, const char *);
 #else
 #include <util.h>
 #define bmake_malloc(x)         emalloc(x)

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.270 src/usr.bin/make/parse.c:1.271
--- src/usr.bin/make/parse.c:1.270	Sat Aug 29 11:13:43 2020
+++ src/usr.bin/make/parse.c	Sat Aug 29 11:24:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.270 2020/08/29 11:13:43 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.271 2020/08/29 11:24:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.270 2020/08/29 11:13:43 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.271 2020/08/29 11:24:54 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.270 2020/08/29 11:13:43 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.271 2020/08/29 11:24:54 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2402,7 +2402,7 @@ ParseSetParseFile(const char *filename)
 	Var_Set(".PARSEFILE", pf = filename, VAR_GLOBAL);
 	dirname = NULL;
     } else {
-	dirname = bmake_strldup(filename, (size_t)(slash - filename));
+	dirname = bmake_strsedup(filename, slash);
 	Var_Set(".PARSEDIR", pd = dirname, VAR_GLOBAL);
 	Var_Set(".PARSEFILE", pf = slash + 1, VAR_GLOBAL);
     }

Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.132 src/usr.bin/make/suff.c:1.133
--- src/usr.bin/make/suff.c:1.132	Sat Aug 29 11:13:43 2020
+++ src/usr.bin/make/suff.c	Sat Aug 29 11:24:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.132 2020/08/29 11:13:43 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.133 2020/08/29 11:24:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.132 2020/08/29 11:13:43 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.133 2020/08/29 11:24:54 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)suff.c	8.4 (Berkeley) 3/21/94";
 #else
-__RCSID("$NetBSD: suff.c,v 1.132 2020/08/29 11:13:43 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.133 2020/08/29 11:24:54 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2037,7 +2037,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
 #endif
 
 		eopref = eoname - targ->suff->nameLen;
-		targ->pref = bmake_strldup(sopref, (size_t)(eopref - sopref));
+		targ->pref = bmake_strsedup(sopref, eopref);
 
 		/*
 		 * Add nodes from which the target can be made

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.473 src/usr.bin/make/var.c:1.474
--- src/usr.bin/make/var.c:1.473	Sat Aug 29 07:52:55 2020
+++ src/usr.bin/make/var.c	Sat Aug 29 11:24:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.473 2020/08/29 07:52:55 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.474 2020/08/29 11:24:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.473 2020/08/29 07:52:55 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.474 2020/08/29 11:24:54 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.473 2020/08/29 07:52:55 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.474 2020/08/29 11:24:54 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2312,11 +2312,7 @@ ApplyModifier_Match(const char **pp, App
 	*dst = '\0';
 	endpat = dst;
     } else {
-	/*
-	 * Either Var_Subst or ModifyWords will need a
-	 * nul-terminated string soon, so construct one now.
-	 */
-	pattern = bmake_strldup(mod + 1, (size_t)(endpat - (mod + 1)));
+	pattern = bmake_strsedup(mod + 1, endpat);
     }
 
     if (needSubst) {

Reply via email to