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): add str_concat4 to make the other code...



details:   https://anonhg.NetBSD.org/src/rev/cea65757c10f
branches:  trunk
changeset: 974801:cea65757c10f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Aug 11 18:41:46 2020 +0000

description:
make(1): add str_concat4 to make the other code simpler

There's no need for arch.c to call strlen when there is a high-level API
for the same purpose.

diffstat:

 usr.bin/make/arch.c    |  12 ++++--------
 usr.bin/make/nonints.h |   3 ++-
 usr.bin/make/str.c     |  22 +++++++++++++++++++---
 3 files changed, 25 insertions(+), 12 deletions(-)

diffs (112 lines):

diff -r 10efd12e9780 -r cea65757c10f usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Tue Aug 11 15:48:42 2020 +0000
+++ b/usr.bin/make/arch.c       Tue Aug 11 18:41:46 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.81 2020/08/03 20:26:09 rillig Exp $ */
+/*     $NetBSD: arch.c,v 1.82 2020/08/11 18:41:46 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.81 2020/08/03 20:26:09 rillig Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.82 2020/08/11 18:41:46 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)arch.c     8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: arch.c,v 1.81 2020/08/03 20:26:09 rillig Exp $");
+__RCSID("$NetBSD: arch.c,v 1.82 2020/08/11 18:41:46 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -354,7 +354,6 @@
            char    *buf;
            char    *sacrifice;
            char    *oldMemName = memName;
-           size_t   sz;
 
            memName = Var_Subst(memName, ctxt, VARE_UNDEFERR | VARE_WANTRES);
 
@@ -363,10 +362,7 @@
             * variables and multi-word variable values.... The results
             * are just placed at the end of the nodeLst we're returning.
             */
-           sz = strlen(memName)+strlen(libName)+3;
-           buf = sacrifice = bmake_malloc(sz);
-
-           snprintf(buf, sz, "%s(%s)", libName, memName);
+           buf = sacrifice = str_concat4(libName, "(", memName, ")");
 
            if (strchr(memName, '$') && strcmp(memName, oldMemName) == 0) {
                /*
diff -r 10efd12e9780 -r cea65757c10f usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Tue Aug 11 15:48:42 2020 +0000
+++ b/usr.bin/make/nonints.h    Tue Aug 11 18:41:46 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.93 2020/08/10 19:53:19 rillig Exp $      */
+/*     $NetBSD: nonints.h,v 1.94 2020/08/11 18:41:46 rillig Exp $      */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -136,6 +136,7 @@
 /* str.c */
 char *str_concat2(const char *, const char *);
 char *str_concat3(const char *, const char *, const char *);
+char *str_concat4(const char *, const char *, const char *, const char *);
 char **brk_string(const char *, int *, Boolean, char **);
 char *Str_FindSubstring(const char *, const char *);
 Boolean Str_Match(const char *, const char *);
diff -r 10efd12e9780 -r cea65757c10f usr.bin/make/str.c
--- a/usr.bin/make/str.c        Tue Aug 11 15:48:42 2020 +0000
+++ b/usr.bin/make/str.c        Tue Aug 11 18:41:46 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: str.c,v 1.59 2020/08/10 19:53:19 rillig Exp $  */
+/*     $NetBSD: str.c,v 1.60 2020/08/11 18:41:46 rillig Exp $  */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: str.c,v 1.59 2020/08/10 19:53:19 rillig Exp $";
+static char rcsid[] = "$NetBSD: str.c,v 1.60 2020/08/11 18:41:46 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char     sccsid[] = "@(#)str.c  5.8 (Berkeley) 6/1/90";
 #else
-__RCSID("$NetBSD: str.c,v 1.59 2020/08/10 19:53:19 rillig Exp $");
+__RCSID("$NetBSD: str.c,v 1.60 2020/08/11 18:41:46 rillig Exp $");
 #endif
 #endif                         /* not lint */
 #endif
@@ -109,6 +109,22 @@
        return result;
 }
 
+/* Return the concatenation of s1, s2, s3 and s4, freshly allocated. */
+char *
+str_concat4(const char *s1, const char *s2, const char *s3, const char *s4)
+{
+       size_t len1 = strlen(s1);
+       size_t len2 = strlen(s2);
+       size_t len3 = strlen(s3);
+       size_t len4 = strlen(s4);
+       char *result = bmake_malloc(len1 + len2 + len3 + len4 + 1);
+       memcpy(result, s1, len1);
+       memcpy(result + len1, s2, len2);
+       memcpy(result + len1 + len2, s3, len3);
+       memcpy(result + len1 + len2 + len3, s4, len4 + 1);
+       return result;
+}
+
 /*-
  * brk_string --
  *     Fracture a string into an array of words (as delineated by tabs or



Home | Main Index | Thread Index | Old Index