summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2000-06-23 16:41:54 +0000
committerMarc Espie <espie@cvs.openbsd.org>2000-06-23 16:41:54 +0000
commitd28ec3966301e814d9c63030a3afc07ea45eb8a3 (patch)
treea5804d34291cf64df0ccce5efe32488eb6b921ca
parent24e587ef0180ad05ade69686b231161109c81738 (diff)
This patch replaces str_concat with a slightly unobfuscated version.
In particular, Dir_MakeFlags is abusing str_concat, and works much better with buffers.
-rw-r--r--usr.bin/make/dir.c29
-rw-r--r--usr.bin/make/extern.h4
-rw-r--r--usr.bin/make/job.c6
-rw-r--r--usr.bin/make/parse.c6
-rw-r--r--usr.bin/make/str.c62
-rw-r--r--usr.bin/make/suff.c6
6 files changed, 49 insertions, 64 deletions
diff --git a/usr.bin/make/dir.c b/usr.bin/make/dir.c
index 5b225383077..0d48b31f5f4 100644
--- a/usr.bin/make/dir.c
+++ b/usr.bin/make/dir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dir.c,v 1.22 2000/06/23 16:15:49 espie Exp $ */
+/* $OpenBSD: dir.c,v 1.23 2000/06/23 16:41:52 espie Exp $ */
/* $NetBSD: dir.c,v 1.14 1997/03/29 16:51:26 christos Exp $ */
/*
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)dir.c 8.2 (Berkeley) 1/2/94";
#else
-static char rcsid[] = "$OpenBSD: dir.c,v 1.22 2000/06/23 16:15:49 espie Exp $";
+static char rcsid[] = "$OpenBSD: dir.c,v 1.23 2000/06/23 16:41:52 espie Exp $";
#endif
#endif /* not lint */
@@ -379,8 +379,7 @@ DirMatchFiles (pattern, p, expansions)
{
Lst_AtEnd(expansions,
(isDot ? estrdup(entry->name) :
- str_concat(p->name, entry->name,
- STR_ADDSLASH)));
+ str_concat(p->name, entry->name, '/')));
}
}
return (0);
@@ -749,7 +748,7 @@ Dir_FindFile (name, path)
continue;
}
}
- file = str_concat (p->name, cp, STR_ADDSLASH);
+ file = str_concat(p->name, cp, '/');
if (DEBUG(DIR)) {
printf("returning %s\n", file);
}
@@ -806,7 +805,7 @@ Dir_FindFile (name, path)
while ((ln = Lst_Next (path)) != NULL) {
p = (Path *)Lst_Datum(ln);
if (p != dot) {
- file = str_concat (p->name, name, STR_ADDSLASH);
+ file = str_concat(p->name, name, '/');
} else {
/*
* Checking in dot -- DON'T put a leading ./ on the thing.
@@ -1135,22 +1134,18 @@ Dir_MakeFlags(flag, path)
char *flag; /* flag which should precede each directory */
Lst path; /* list of directories */
{
- char *str; /* the string which will be returned */
- char *tstr; /* the current directory preceded by 'flag' */
LstNode ln; /* the node of the current directory */
- Path *p; /* the structure describing the current directory */
+ BUFFER buf;
- str = estrdup("");
+ Buf_Init(&buf, 0);
- Lst_Open(path);
- while ((ln = Lst_Next(path)) != NULL) {
- p = (Path *)Lst_Datum(ln);
- tstr = str_concat(flag, p->name, 0);
- str = str_concat(str, tstr, STR_ADDSPACE | STR_DOFREE);
+ for (ln = Lst_First(path); ln != NULL; ln = Lst_Adv(ln)) {
+ Buf_AddString(&buf, flag);
+ Buf_AddString(&buf, ((Path *)Lst_Datum(ln))->name);
+ Buf_AddSpace(&buf);
}
- Lst_Close(path);
- return str;
+ return Buf_Retrieve(&buf);
}
/*-
diff --git a/usr.bin/make/extern.h b/usr.bin/make/extern.h
index 0b6a00b1bd5..2efad9e9c89 100644
--- a/usr.bin/make/extern.h
+++ b/usr.bin/make/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.26 2000/06/23 16:23:26 espie Exp $ */
+/* $OpenBSD: extern.h,v 1.27 2000/06/23 16:41:53 espie Exp $ */
/* $NetBSD: nonints.h,v 1.12 1996/11/06 17:59:19 christos Exp $ */
/*-
@@ -103,7 +103,7 @@ const char *Parse_Getfilename __P((void));
/* str.c */
void str_init __P((void));
void str_end __P((void));
-char *str_concat __P((char *, char *, int));
+char *str_concat __P((const char *, const char *, char));
char **brk_string __P((char *, int *, Boolean, char **));
int Str_Match __P((char *, char *));
char *Str_SYSVMatch __P((char *, char *, int *len));
diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c
index 534176c84a2..13f0c59ce4a 100644
--- a/usr.bin/make/job.c
+++ b/usr.bin/make/job.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: job.c,v 1.32 2000/06/23 16:20:01 espie Exp $ */
+/* $OpenBSD: job.c,v 1.33 2000/06/23 16:41:53 espie Exp $ */
/* $NetBSD: job.c,v 1.16 1996/11/06 17:59:08 christos Exp $ */
/*
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94";
#else
-static char rcsid[] = "$OpenBSD: job.c,v 1.32 2000/06/23 16:20:01 espie Exp $";
+static char rcsid[] = "$OpenBSD: job.c,v 1.33 2000/06/23 16:41:53 espie Exp $";
#endif
#endif /* not lint */
@@ -2433,7 +2433,7 @@ Job_Init(maxproc, maxlocal)
* All default shells are located in _PATH_DEFSHELLDIR.
*/
shellName = commandShell->name;
- shellPath = str_concat(_PATH_DEFSHELLDIR, shellName, STR_ADDSLASH);
+ shellPath = str_concat(_PATH_DEFSHELLDIR, shellName, '/');
}
if (commandShell->exit == NULL) {
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index a13b4e90935..9946bf0c75a 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.51 2000/06/23 16:40:50 espie Exp $ */
+/* $OpenBSD: parse.c,v 1.52 2000/06/23 16:41:53 espie Exp $ */
/* $NetBSD: parse.c,v 1.29 1997/03/10 21:20:04 christos Exp $ */
/*
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
#else
-static char rcsid[] = "$OpenBSD: parse.c,v 1.51 2000/06/23 16:40:50 espie Exp $";
+static char rcsid[] = "$OpenBSD: parse.c,v 1.52 2000/06/23 16:41:53 espie Exp $";
#endif
#endif /* not lint */
@@ -1601,7 +1601,7 @@ ParseLookupIncludeFile(spec, endSpec, isSystem)
char *base, *newName;
base = interval_dup(Parse_Getfilename(), slash);
- newName = str_concat(base, file, STR_ADDSLASH);
+ newName = str_concat(base, file, '/');
free(base);
fullname = Dir_FindFile(newName, &parseIncPath);
if (fullname == NULL)
diff --git a/usr.bin/make/str.c b/usr.bin/make/str.c
index 04bded83f89..7eb7fcca207 100644
--- a/usr.bin/make/str.c
+++ b/usr.bin/make/str.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: str.c,v 1.11 1999/12/09 18:18:24 espie Exp $ */
+/* $OpenBSD: str.c,v 1.12 2000/06/23 16:41:53 espie Exp $ */
/* $NetBSD: str.c,v 1.13 1996/11/06 17:59:23 christos Exp $ */
/*-
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)str.c 5.8 (Berkeley) 6/1/90";
#else
-static char rcsid[] = "$OpenBSD: str.c,v 1.11 1999/12/09 18:18:24 espie Exp $";
+static char rcsid[] = "$OpenBSD: str.c,v 1.12 2000/06/23 16:41:53 espie Exp $";
#endif
#endif /* not lint */
@@ -51,48 +51,38 @@ static char rcsid[] = "$OpenBSD: str.c,v 1.11 1999/12/09 18:18:24 espie Exp $";
/*-
* str_concat --
- * concatenate the two strings, inserting a space or slash between them,
- * freeing them if requested.
+ * concatenate the two strings, possibly inserting a separator
*
* returns --
* the resulting string in allocated space.
*/
char *
-str_concat(s1, s2, flags)
- char *s1, *s2;
- int flags;
+str_concat(s1, s2, sep)
+ const char *s1, *s2;
+ char sep;
{
- register int len1, len2;
- register char *result;
-
- /* get the length of both strings */
- len1 = strlen(s1);
- len2 = strlen(s2);
-
- /* allocate length plus separator plus EOS */
- result = emalloc((u_int)(len1 + len2 + 2));
-
- /* copy first string into place */
- memcpy(result, s1, len1);
-
- /* add separator character */
- if (flags & STR_ADDSPACE) {
- result[len1] = ' ';
- ++len1;
- } else if (flags & STR_ADDSLASH) {
- result[len1] = '/';
- ++len1;
- }
+ size_t len1, len2;
+ char *result;
- /* copy second string plus EOS into place */
- memcpy(result + len1, s2, len2 + 1);
+ /* get the length of both strings */
+ len1 = strlen(s1);
+ len2 = strlen(s2);
- /* free original strings */
- if (flags & STR_DOFREE) {
- (void)free(s1);
- (void)free(s2);
- }
- return(result);
+ /* space for separator */
+ if (sep)
+ len1++;
+ result = emalloc(len1 + len2 + 1);
+
+ /* copy first string into place */
+ memcpy(result, s1, len1);
+
+ /* add separator character */
+ if (sep)
+ result[len1-1] = sep;
+
+ /* copy second string plus EOS into place */
+ memcpy(result + len1, s2, len2 + 1);
+ return result;
}
/*-
diff --git a/usr.bin/make/suff.c b/usr.bin/make/suff.c
index 0050a68be41..e504afa7725 100644
--- a/usr.bin/make/suff.c
+++ b/usr.bin/make/suff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: suff.c,v 1.34 2000/06/23 16:21:43 espie Exp $ */
+/* $OpenBSD: suff.c,v 1.35 2000/06/23 16:41:53 espie Exp $ */
/* $NetBSD: suff.c,v 1.13 1996/11/06 17:59:25 christos Exp $ */
/*
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94";
#else
-static char rcsid[] = "$OpenBSD: suff.c,v 1.34 2000/06/23 16:21:43 espie Exp $";
+static char rcsid[] = "$OpenBSD: suff.c,v 1.35 2000/06/23 16:41:53 espie Exp $";
#endif
#endif /* not lint */
@@ -992,7 +992,7 @@ SuffAddSrc(sp, lsp)
#endif
}
s2 = (Src *) emalloc (sizeof (Src));
- s2->file = str_concat (targ->pref, s->name, 0);
+ s2->file = str_concat(targ->pref, s->name, 0);
s2->pref = targ->pref;
s2->parent = targ;
s2->node = NULL;