Module Name:    src
Committed By:   rillig
Date:           Tue Aug 11 18:41:46 UTC 2020

Modified Files:
        src/usr.bin/make: arch.c nonints.h str.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/make/arch.c
cvs rdiff -u -r1.93 -r1.94 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.59 -r1.60 src/usr.bin/make/str.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/arch.c
diff -u src/usr.bin/make/arch.c:1.81 src/usr.bin/make/arch.c:1.82
--- src/usr.bin/make/arch.c:1.81	Mon Aug  3 20:26:09 2020
+++ src/usr.bin/make/arch.c	Tue Aug 11 18:41:46 2020
@@ -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 @@ Arch_ParseArchive(char **linePtr, Lst no
 	    char    *buf;
 	    char    *sacrifice;
 	    char    *oldMemName = memName;
-	    size_t   sz;
 
 	    memName = Var_Subst(memName, ctxt, VARE_UNDEFERR | VARE_WANTRES);
 
@@ -363,10 +362,7 @@ Arch_ParseArchive(char **linePtr, Lst no
 	     * 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) {
 		/*

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.93 src/usr.bin/make/nonints.h:1.94
--- src/usr.bin/make/nonints.h:1.93	Mon Aug 10 19:53:19 2020
+++ src/usr.bin/make/nonints.h	Tue Aug 11 18:41:46 2020
@@ -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 @@ Lst Parse_MainName(void);
 /* 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 *);

Index: src/usr.bin/make/str.c
diff -u src/usr.bin/make/str.c:1.59 src/usr.bin/make/str.c:1.60
--- src/usr.bin/make/str.c:1.59	Mon Aug 10 19:53:19 2020
+++ src/usr.bin/make/str.c	Tue Aug 11 18:41:46 2020
@@ -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 @@ str_concat3(const char *s1, const char *
 	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

Reply via email to