Commit 0bdcca68 by Richard Henderson Committed by Richard Henderson

concat.c: Include string.h.

        * concat.c: Include string.h.  Fix int vs size_t usage.
        Simplify the iteration loops.  Use memcpy.

From-SVN: r43149
parent 33a1b84b
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> 2001-05-16 Matt Kraai <kraai@alumni.carnegiemellon.edu>
* partition.c: Fix misspelling of `implementation'. * partition.c: Fix misspelling of `implementation'.
......
/* Concatenate variable number of strings. /* 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 Written by Fred Fish @ Cygnus Support
This file is part of the libiberty library. This file is part of the libiberty library.
...@@ -62,14 +62,13 @@ NOTES ...@@ -62,14 +62,13 @@ NOTES
#include <varargs.h> #include <varargs.h>
#endif #endif
#ifdef __STDC__ # if HAVE_STRING_H
#include <stddef.h> # include <string.h>
extern size_t strlen (const char *s); # else
#else # if HAVE_STRINGS_H
extern int strlen (); # include <strings.h>
#endif # endif
# endif
#define NULLP (char *)0
/* VARARGS */ /* VARARGS */
#ifdef ANSI_PROTOTYPES #ifdef ANSI_PROTOTYPES
...@@ -81,7 +80,7 @@ concat (va_alist) ...@@ -81,7 +80,7 @@ concat (va_alist)
va_dcl va_dcl
#endif #endif
{ {
register int length; register size_t length;
register char *newstr; register char *newstr;
register char *end; register char *end;
register const char *arg; register const char *arg;
...@@ -90,8 +89,7 @@ concat (va_alist) ...@@ -90,8 +89,7 @@ concat (va_alist)
const char *first; const char *first;
#endif #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 #ifdef ANSI_PROTOTYPES
va_start (args, first); va_start (args, first);
#else #else
...@@ -99,53 +97,37 @@ concat (va_alist) ...@@ -99,53 +97,37 @@ concat (va_alist)
first = va_arg (args, const char *); first = va_arg (args, const char *);
#endif #endif
if (first == NULLP) length = 0;
length = 0; for (arg = first; arg ; arg = va_arg (args, const char *))
else length += strlen (arg);
{
length = strlen (first);
while ((arg = va_arg (args, const char *)) != NULLP)
{
length += strlen (arg);
}
}
newstr = (char *) xmalloc (length + 1);
va_end (args); 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 #ifdef ANSI_PROTOTYPES
va_start (args, first); va_start (args, first);
#else #else
va_start (args); va_start (args);
first = va_arg (args, const char *); first = va_arg (args, const char *);
#endif #endif
end = newstr;
if (first != NULLP) end = newstr;
{ for (arg = first; arg ; arg = va_arg (args, const char *))
arg = first; {
while (*arg) length = strlen (arg);
{ memcpy (end, arg, length);
*end++ = *arg++; end += length;
}
while ((arg = va_arg (args, const char *)) != NULLP)
{
while (*arg)
{
*end++ = *arg++;
}
}
}
*end = '\000';
va_end (args);
} }
*end = '\000';
va_end (args);
return (newstr); return newstr;
} }
#ifdef MAIN #ifdef MAIN
#define NULLP (char *)0
/* Simple little test driver. */ /* Simple little test driver. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment