diff options
author | Davi Arnaut <davi@apache.org> | 2007-06-30 22:48:52 +0000 |
---|---|---|
committer | Davi Arnaut <davi@apache.org> | 2007-06-30 22:48:52 +0000 |
commit | 8e8fdb279b054f6c0e2c993af540b1e2478cdd93 (patch) | |
tree | 7f0a6c2a6e04a0eb2ce28d4895da736455edcfa4 /tables | |
parent | 728dc1a0f21a68acdc5b02744ca12c9cc9aaae88 (diff) | |
download | apr-8e8fdb279b054f6c0e2c993af540b1e2478cdd93.tar.gz |
Add table cloning (deep copy) convenience function named apr_table_clone().
The function copies all fields of the table, and makes copies of dynamically
allocated memory pointed to by the fields.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@552223 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'tables')
-rw-r--r-- | tables/apr_tables.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tables/apr_tables.c b/tables/apr_tables.c index 9a25e366e..51b23407c 100644 --- a/tables/apr_tables.c +++ b/tables/apr_tables.c @@ -423,6 +423,20 @@ APR_DECLARE(apr_table_t *) apr_table_copy(apr_pool_t *p, const apr_table_t *t) return new; } +APR_DECLARE(apr_table_t *) apr_table_clone(apr_pool_t *p, const apr_table_t *t) +{ + const apr_array_header_t *array = apr_table_elts(t); + apr_table_entry_t *elts = (apr_table_entry_t *) array->elts; + apr_table_t *new = apr_table_make(p, array->nelts); + int i; + + for (i = 0; i < array->nelts; i++) { + apr_table_add(new, elts[i].key, elts[i].val); + } + + return new; +} + static void table_reindex(apr_table_t *t) { int i; |