aboutsummaryrefslogtreecommitdiff
path: root/libiberty
diff options
context:
space:
mode:
authorDJ Delorie <dj@redhat.com>2001-06-11 00:07:54 +0000
committerDJ Delorie <dj@redhat.com>2001-06-11 00:07:54 +0000
commitd42dae6cb26969ad6b1b901d89ff678d1b8c31b8 (patch)
tree15c0ac2964ff06c2d3860535da70fa209b1f86c5 /libiberty
parent4e67fe297f9e293703ebeb2a604d319bfe19ac98 (diff)
downloadgdb-d42dae6cb26969ad6b1b901d89ff678d1b8c31b8.zip
gdb-d42dae6cb26969ad6b1b901d89ff678d1b8c31b8.tar.gz
gdb-d42dae6cb26969ad6b1b901d89ff678d1b8c31b8.tar.bz2
merge from gcc
Diffstat (limited to 'libiberty')
-rw-r--r--libiberty/ChangeLog5
-rw-r--r--libiberty/concat.c78
2 files changed, 35 insertions, 48 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index 25ab13e..12b17ee 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,8 @@
+2001-06-10 Richard Henderson <rth@redhat.com>
+
+ * concat.c: Include string.h. Fix int vs size_t usage.
+ Simplify the iteration loops. Use memcpy.
+
2001-05-16 Matt Kraai <kraai@alumni.carnegiemellon.edu>
* partition.c: Fix misspelling of `implementation'.
diff --git a/libiberty/concat.c b/libiberty/concat.c
index 5b132c8..8e6838f 100644
--- a/libiberty/concat.c
+++ b/libiberty/concat.c
@@ -1,5 +1,5 @@
/* Concatenate variable number of strings.
- Copyright (C) 1991, 1994 Free Software Foundation, Inc.
+ Copyright (C) 1991, 1994, 2001 Free Software Foundation, Inc.
Written by Fred Fish @ Cygnus Support
This file is part of the libiberty library.
@@ -62,14 +62,13 @@ NOTES
#include <varargs.h>
#endif
-#ifdef __STDC__
-#include <stddef.h>
-extern size_t strlen (const char *s);
-#else
-extern int strlen ();
-#endif
-
-#define NULLP (char *)0
+# if HAVE_STRING_H
+# include <string.h>
+# else
+# if HAVE_STRINGS_H
+# include <strings.h>
+# endif
+# endif
/* VARARGS */
#ifdef ANSI_PROTOTYPES
@@ -81,7 +80,7 @@ concat (va_alist)
va_dcl
#endif
{
- register int length;
+ register size_t length;
register char *newstr;
register char *end;
register const char *arg;
@@ -90,8 +89,7 @@ concat (va_alist)
const char *first;
#endif
- /* First compute the size of the result and get sufficient memory. */
-
+ /* First compute the size of the result and get sufficient memory. */
#ifdef ANSI_PROTOTYPES
va_start (args, first);
#else
@@ -99,53 +97,37 @@ concat (va_alist)
first = va_arg (args, const char *);
#endif
- if (first == NULLP)
- length = 0;
- else
- {
- length = strlen (first);
- while ((arg = va_arg (args, const char *)) != NULLP)
- {
- length += strlen (arg);
- }
- }
- newstr = (char *) xmalloc (length + 1);
+ length = 0;
+ for (arg = first; arg ; arg = va_arg (args, const char *))
+ length += strlen (arg);
+
va_end (args);
- /* Now copy the individual pieces to the result string. */
+ newstr = (char *) xmalloc (length + 1);
- if (newstr != NULLP)
- {
+ /* Now copy the individual pieces to the result string. */
#ifdef ANSI_PROTOTYPES
- va_start (args, first);
+ va_start (args, first);
#else
- va_start (args);
- first = va_arg (args, const char *);
+ va_start (args);
+ first = va_arg (args, const char *);
#endif
- end = newstr;
- if (first != NULLP)
- {
- arg = first;
- while (*arg)
- {
- *end++ = *arg++;
- }
- while ((arg = va_arg (args, const char *)) != NULLP)
- {
- while (*arg)
- {
- *end++ = *arg++;
- }
- }
- }
- *end = '\000';
- va_end (args);
+
+ end = newstr;
+ for (arg = first; arg ; arg = va_arg (args, const char *))
+ {
+ length = strlen (arg);
+ memcpy (end, arg, length);
+ end += length;
}
+ *end = '\000';
+ va_end (args);
- return (newstr);
+ return newstr;
}
#ifdef MAIN
+#define NULLP (char *)0
/* Simple little test driver. */