Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make(1): merge duplicate code for bmake_strldup



details:   https://anonhg.NetBSD.org/src/rev/078741dade65
branches:  trunk
changeset: 943255:078741dade65
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 29 11:13:43 2020 +0000

description:
make(1): merge duplicate code for bmake_strldup

diffstat:

 usr.bin/make/hash.h  |   4 ++--
 usr.bin/make/parse.c |  14 +++++---------
 usr.bin/make/suff.c  |  19 ++++++-------------
 3 files changed, 13 insertions(+), 24 deletions(-)

diffs (118 lines):

diff -r c14720774a3b -r 078741dade65 usr.bin/make/hash.h
--- a/usr.bin/make/hash.h       Sat Aug 29 10:52:47 2020 +0000
+++ b/usr.bin/make/hash.h       Sat Aug 29 11:13:43 2020 +0000
@@ -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 @@
                                         * 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 {
diff -r c14720774a3b -r 078741dade65 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Aug 29 10:52:47 2020 +0000
+++ b/usr.bin/make/parse.c      Sat Aug 29 11:13:43 2020 +0000
@@ -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 @@
 {
     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);
     }
diff -r c14720774a3b -r 078741dade65 usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Sat Aug 29 10:52:47 2020 +0000
+++ b/usr.bin/make/suff.c       Sat Aug 29 11:13:43 2020 +0000
@@ -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 @@
            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 @@
                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



Home | Main Index | Thread Index | Old Index