int main(void) { apr_initialize(); apr_pool_t *pool; apr_pool_create(&pool, NULL); apr_hash_t *hash = apr_hash_make(pool); apr_hash_set(hash, "php", APR_HASH_KEY_STRING, "Hello, PHP"); apr_hash_set(hash, "apache", APR_HASH_KEY_STRING, "Hello, Apache"); apr_hash_set(hash, "mysql", APR_HASH_KEY_STRING, "hello, mysql"); apr_hash_do(print_hash_item, "first_print", hash); printf("apr_hash_count(hash) = %d\n", apr_hash_count(hash)); printf("apr_hash_get(hash, \"apache\", APR_HASH_KEY_STRING) = %s\n", apr_hash_get(hash, "apache", APR_HASH_KEY_STRING)); apr_pool_destroy(pool); apr_terminate(); return 0; }
svn_error_t * svn_iter_apr_hash(svn_boolean_t *completed, apr_hash_t *hash, svn_iter_apr_hash_cb_t func, void *baton, apr_pool_t *pool) { #if APR_VERSION_AT_LEAST(1, 4, 0) struct hash_do_baton hdb; svn_boolean_t error_received; hdb.func = func; hdb.baton = baton; hdb.iterpool = svn_pool_create(pool); error_received = !apr_hash_do(hash_do_callback, &hdb, hash); svn_pool_destroy(hdb.iterpool); if (completed) *completed = !error_received; if (!error_received) return SVN_NO_ERROR; if (hdb.err->apr_err == SVN_ERR_ITER_BREAK && hdb.err != &internal_break_error) { /* Errors - except those created by svn_iter_break() - need to be cleared when not further propagated. */ svn_error_clear(hdb.err); hdb.err = SVN_NO_ERROR; } return hdb.err; #else svn_error_t *err = SVN_NO_ERROR; apr_pool_t *iterpool = svn_pool_create(pool); apr_hash_index_t *hi; for (hi = apr_hash_first(pool, hash); ! err && hi; hi = apr_hash_next(hi)) { const void *key; void *val; apr_ssize_t len; svn_pool_clear(iterpool); apr_hash_this(hi, &key, &len, &val); err = (*func)(baton, key, len, val, iterpool); } if (completed) *completed = ! err; if (err && err->apr_err == SVN_ERR_ITER_BREAK) { if (err != &internal_break_error) /* Errors - except those created by svn_iter_break() - need to be cleared when not further propagated. */ svn_error_clear(err); err = SVN_NO_ERROR; } /* Clear iterpool, because callers may clear the error but have no way to clear the iterpool with potentially lots of allocated memory */ svn_pool_destroy(iterpool); return err; #endif }