Module Name:    src
Committed By:   rillig
Date:           Sat Aug 29 11:13:43 UTC 2020

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

Log Message:
make(1): merge duplicate code for bmake_strldup


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/make/hash.h
cvs rdiff -u -r1.269 -r1.270 src/usr.bin/make/parse.c
cvs rdiff -u -r1.131 -r1.132 src/usr.bin/make/suff.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/hash.h
diff -u src/usr.bin/make/hash.h:1.18 src/usr.bin/make/hash.h:1.19
--- src/usr.bin/make/hash.h:1.18	Thu Aug 13 03:54:57 2020
+++ src/usr.bin/make/hash.h	Sat Aug 29 11:13:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hash.h,v 1.18 2020/08/13 03:54:57 rillig Exp $	*/
+/*	$NetBSD: hash.h,v 1.19 2020/08/29 11:13:43 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -91,7 +91,7 @@ typedef struct Hash_Entry {
 					 * bucket. */
     void	      *clientPtr;	/* Arbitrary pointer */
     unsigned	      namehash;		/* hash value of key */
-    char	      name[1];		/* key string */
+    char	      name[1];		/* key string, variable length */
 } Hash_Entry;
 
 typedef struct Hash_Table {

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.269 src/usr.bin/make/parse.c:1.270
--- src/usr.bin/make/parse.c:1.269	Sat Aug 29 07:52:55 2020
+++ src/usr.bin/make/parse.c	Sat Aug 29 11:13:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.269 2020/08/29 07:52:55 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.270 2020/08/29 11:13:43 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.269 2020/08/29 07:52:55 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.270 2020/08/29 11:13:43 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.269 2020/08/29 07:52:55 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.270 2020/08/29 11:13:43 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2395,18 +2395,14 @@ ParseSetParseFile(const char *filename)
 {
     char *slash, *dirname;
     const char *pd, *pf;
-    int len;
 
     slash = strrchr(filename, '/');
     if (slash == NULL) {
 	Var_Set(".PARSEDIR", pd = curdir, VAR_GLOBAL);
 	Var_Set(".PARSEFILE", pf = filename, VAR_GLOBAL);
-	dirname= NULL;
+	dirname = NULL;
     } else {
-	len = slash - filename;
-	dirname = bmake_malloc(len + 1);
-	memcpy(dirname, filename, len);
-	dirname[len] = '\0';
+	dirname = bmake_strldup(filename, (size_t)(slash - filename));
 	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.131 src/usr.bin/make/suff.c:1.132
--- src/usr.bin/make/suff.c:1.131	Sat Aug 29 10:41:12 2020
+++ src/usr.bin/make/suff.c	Sat Aug 29 11:13:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.131 2020/08/29 10:41:12 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.132 2020/08/29 11:13:43 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.131 2020/08/29 10:41:12 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.132 2020/08/29 11:13:43 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.131 2020/08/29 10:41:12 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.132 2020/08/29 11:13:43 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2020,7 +2020,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
 	    ln = Lst_FindFrom(sufflist, ln, SuffSuffIsSuffix, &sd);
 
 	    if (ln != NULL) {
-		int	    prefLen;	    /* Length of the prefix */
+	        const char *eopref;
 
 		/*
 		 * Allocate a Src structure to which things can be transformed
@@ -2036,15 +2036,8 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
 		targ->cp = Lst_Init();
 #endif
 
-		/*
-		 * Allocate room for the prefix, whose end is found by
-		 * subtracting the length of the suffix from
-		 * the end of the name.
-		 */
-		prefLen = (eoname - targ->suff->nameLen) - sopref;
-		targ->pref = bmake_malloc(prefLen + 1);
-		memcpy(targ->pref, sopref, prefLen);
-		targ->pref[prefLen] = '\0';
+		eopref = eoname - targ->suff->nameLen;
+		targ->pref = bmake_strldup(sopref, (size_t)(eopref - sopref));
 
 		/*
 		 * Add nodes from which the target can be made

Reply via email to