brianp 02/05/11 17:56:26
Modified: include apr_strings.h
strings apr_strings.c
Log:
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.
Revision Changes Path
1.25 +13 -0 apr/include/apr_strings.h
Index: apr_strings.h
===================================================================
RCS file: /home/cvs/apr/include/apr_strings.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- apr_strings.h 13 Mar 2002 20:39:15 -0000 1.24
+++ apr_strings.h 12 May 2002 00:56:26 -0000 1.25
@@ -81,6 +81,8 @@
#include "apr.h"
#include "apr_errno.h"
#include "apr_pools.h"
+#define APR_WANT_IOVEC
+#include "apr_want.h"
#if APR_HAVE_STDARG_H
#include <stdarg.h>
@@ -168,6 +170,17 @@
* @return The new string
*/
APR_DECLARE_NONSTD(char *) apr_pstrcat(apr_pool_t *p, ...);
+
+/**
+ * Concatenate multiple strings specified in a writev-style vector
+ * @param p The pool from which to allocate
+ * @param vec The strings to concatenate
+ * @param nvec The number of strings to concatenate
+ * @param nbytes (output) strlen of new string (pass in NULL to omit)
+ * @return The new string
+ */
+APR_DECLARE_NONSTD(char *) apr_pstrcatv(apr_pool_t *p, const struct iovec
*vec,
+ apr_size_t nvec, apr_size_t *nbytes);
/**
* printf-style style printing routine. The data is output to a string
1.26 +38 -0 apr/strings/apr_strings.c
Index: apr_strings.c
===================================================================
RCS file: /home/cvs/apr/strings/apr_strings.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- apr_strings.c 8 May 2002 05:22:04 -0000 1.25
+++ apr_strings.c 12 May 2002 00:56:26 -0000 1.26
@@ -177,6 +177,44 @@
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)
{