summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2013-02-27 14:54:05 -0800
committerRuss Allbery <rra@stanford.edu>2013-02-27 16:52:57 -0800
commit93e566f6f9ae8a767d2188ad1fb1520c9c2d303a (patch)
tree470252615c14d94be07cf1c985cca4cee54c5b8e /util
parent4d11772001f65264bf714711550acdbb05900f4c (diff)
Drop use of concat in favor of xasprintf
Change-Id: I6a84920b0c0dc1849af8a34ecf8f3fb70b45e17c Reviewed-on: https://gerrit.stanford.edu/843 Reviewed-by: Russ Allbery <rra@stanford.edu> Tested-by: Russ Allbery <rra@stanford.edu>
Diffstat (limited to 'util')
-rw-r--r--util/concat.c85
-rw-r--r--util/concat.h36
2 files changed, 0 insertions, 121 deletions
diff --git a/util/concat.c b/util/concat.c
deleted file mode 100644
index bdbd836..0000000
--- a/util/concat.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Concatenate strings with dynamic memory allocation.
- *
- * Usage:
- *
- * string = concat(string1, string2, ..., (char *) 0);
- * path = concatpath(base, name);
- *
- * Dynamically allocates (using xmalloc) sufficient memory to hold all of the
- * strings given and then concatenates them together into that allocated
- * memory, returning a pointer to it. Caller is responsible for freeing.
- * Assumes xmalloc is available. The last argument must be a null pointer (to
- * a char *, if you actually find a platform where it matters).
- *
- * concatpath is similar, except that it only takes two arguments. If the
- * second argument begins with / or ./, a copy of it is returned; otherwise,
- * the first argument, a slash, and the second argument are concatenated
- * together and returned. This is useful for building file names where names
- * that aren't fully qualified are qualified with some particular directory.
- *
- * Written by Russ Allbery <rra@stanford.edu>
- * This work is hereby placed in the public domain by its author.
- */
-
-#include <config.h>
-#include <portable/system.h>
-
-#include <util/concat.h>
-#include <util/xmalloc.h>
-
-/* Abbreviation for cleaner code. */
-#define VA_NEXT(var, type) ((var) = (type) va_arg(args, type))
-
-
-/*
- * Concatenate all of the arguments into a newly allocated string. ANSI C
- * requires at least one named parameter, but it's not treated any different
- * than the rest.
- */
-char *
-concat(const char *first, ...)
-{
- va_list args;
- char *result, *p;
- const char *string;
- size_t length = 0;
-
- /* Find the total memory required. */
- va_start(args, first);
- for (string = first; string != NULL; VA_NEXT(string, const char *))
- length += strlen(string);
- va_end(args);
- length++;
-
- /*
- * Create the string. Doing the copy ourselves avoids useless string
- * traversals of result, if using strcat, or string, if using strlen to
- * increment a pointer into result, at the cost of losing the native
- * optimization of strcat if any.
- */
- result = xmalloc(length);
- p = result;
- va_start(args, first);
- for (string = first; string != NULL; VA_NEXT(string, const char *))
- while (*string != '\0')
- *p++ = *string++;
- va_end(args);
- *p = '\0';
-
- return result;
-}
-
-
-/*
- * Concatenate name with base, unless name begins with / or ./. Return the
- * new string in newly allocated memory.
- */
-char *
-concatpath(const char *base, const char *name)
-{
- if (name[0] == '/' || (name[0] == '.' && name[1] == '/'))
- return xstrdup(name);
- else
- return concat(base != NULL ? base : ".", "/", name, (char *) 0);
-}
diff --git a/util/concat.h b/util/concat.h
deleted file mode 100644
index ef8b38d..0000000
--- a/util/concat.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Prototypes for string concatenation with dynamic memory allocation.
- *
- * Written by Russ Allbery <rra@stanford.edu>
- * This work is hereby placed in the public domain by its author.
- */
-
-#ifndef UTIL_CONCAT_H
-#define UTIL_CONCAT_H 1
-
-#include <config.h>
-#include <portable/macros.h>
-
-BEGIN_DECLS
-
-/* Default to a hidden visibility for all util functions. */
-#pragma GCC visibility push(hidden)
-
-/* Concatenate NULL-terminated strings into a newly allocated string. */
-char *concat(const char *first, ...)
- __attribute__((__malloc__, __nonnull__(1)));
-
-/*
- * Given a base path and a file name, create a newly allocated path string.
- * The name will be appended to base with a / between them. Exceptionally, if
- * name begins with a slash, it will be strdup'd and returned as-is.
- */
-char *concatpath(const char *base, const char *name)
- __attribute__((__malloc__, __nonnull__(2)));
-
-/* Undo default visibility change. */
-#pragma GCC visibility pop
-
-END_DECLS
-
-#endif /* UTIL_CONCAT_H */