diff options
author | brianp <brianp@13f79535-47bb-0310-9956-ffa450edef68> | 2002-05-12 00:56:26 +0000 |
---|---|---|
committer | brianp <brianp@13f79535-47bb-0310-9956-ffa450edef68> | 2002-05-12 00:56:26 +0000 |
commit | 62a6e2245ef52c3fd075247f773bd4b2f941bb4a (patch) | |
tree | 93031aa7afbcf946cee3263957beecac576ae9f9 /strings | |
parent | 152527c1a461d39bc17481ca239be873b950cf0b (diff) | |
download | libapr-62a6e2245ef52c3fd075247f773bd4b2f941bb4a.tar.gz |
Added apr_strcatv(), a string concatenation function that
uses writev-style arguments. It's a faster alternative to
apr_strcat() in situations where the caller knows the lengths
of the strings to be concatenated.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@63387 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'strings')
-rw-r--r-- | strings/apr_strings.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/strings/apr_strings.c b/strings/apr_strings.c index 2bce20e38..407ea1a84 100644 --- a/strings/apr_strings.c +++ b/strings/apr_strings.c @@ -177,6 +177,44 @@ APR_DECLARE_NONSTD(char *) apr_pstrcat(apr_pool_t *a, ...) return res; } +APR_DECLARE_NONSTD(char *) apr_pstrcatv(apr_pool_t *a, const struct iovec *vec, + apr_size_t nvec, apr_size_t *nbytes) +{ + apr_size_t i; + apr_size_t len; + const struct iovec *src; + char *res; + char *dst; + + /* Pass one --- find length of required string */ + len = 0; + src = vec; + for (i = nvec; i; i--) { + len += src->iov_len; + src++; + } + if (nbytes) { + *nbytes = len; + } + + /* Allocate the required string */ + res = (char *) apr_palloc(a, len + 1); + + /* Pass two --- copy the argument strings into the result space */ + src = vec; + dst = res; + for (i = nvec; i; i--) { + memcpy(dst, src->iov_base, src->iov_len); + dst += src->iov_len; + src++; + } + + /* Return the result string */ + *dst = '\0'; + + return res; +} + #if (!APR_HAVE_MEMCHR) void *memchr(const void *s, int c, size_t n) { |