diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 10:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 10:49:50 +0000 |
commit | 74b60c5712f2a84904b95d008953c140a9bd5dd2 (patch) | |
tree | dd12cc58c6d4cfb5e2c1183f47757295ce3b5662 /lib/appendstr.c | |
parent | Initial commit. (diff) | |
download | man-db-74b60c5712f2a84904b95d008953c140a9bd5dd2.tar.xz man-db-74b60c5712f2a84904b95d008953c140a9bd5dd2.zip |
Adding upstream version 2.9.4.upstream/2.9.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | lib/appendstr.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/appendstr.c b/lib/appendstr.c new file mode 100644 index 0000000..ef07ce8 --- /dev/null +++ b/lib/appendstr.c @@ -0,0 +1,55 @@ +/* appendstr.c -- append to a dynamically allocated string + Copyright (C) 1994 Markus Armbruster + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Library Public License + as published by the Free Software Foundation; either version 2, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING.LIB. If not, write + to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA + 02139, USA. */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <string.h> +#include <stdarg.h> + +#include "manconfig.h" + +/* append strings to first argument, which is realloced to the correct size + first arg may be NULL */ +char *appendstr (char *str, ...) +{ + va_list ap; + size_t len, newlen; + char *next, *end; + + len = str ? strlen (str) : 0; + + va_start (ap, str); + newlen = len + 1; + while ((next = va_arg (ap, char *))) + newlen += strlen (next); + va_end (ap); + + str = xrealloc (str, newlen); + end = str + len; + + va_start (ap, str); + while ((next = va_arg (ap, char *))) { + strcpy (end, next); + end += strlen (next); + } + va_end (ap); + + return str; +} |