diff options
author | Martin Nagy <mnagy@redhat.com> | 2009-02-11 20:37:59 +0100 |
---|---|---|
committer | Martin Nagy <mnagy@redhat.com> | 2009-02-11 20:37:59 +0100 |
commit | f50ae72ec3417cae55dd4e085991c01af9fdc5f1 (patch) | |
tree | 0e36c9a3320f6d068df93d3ff6d84b821d23db40 /bin/tests/lwresconf_test.c | |
download | bind_dynamic-f50ae72ec3417cae55dd4e085991c01af9fdc5f1.tar.gz bind_dynamic-f50ae72ec3417cae55dd4e085991c01af9fdc5f1.tar.xz bind_dynamic-f50ae72ec3417cae55dd4e085991c01af9fdc5f1.zip |
Initial commitstart
Diffstat (limited to 'bin/tests/lwresconf_test.c')
-rw-r--r-- | bin/tests/lwresconf_test.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/bin/tests/lwresconf_test.c b/bin/tests/lwresconf_test.c new file mode 100644 index 0000000..48e839f --- /dev/null +++ b/bin/tests/lwresconf_test.c @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2000, 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: lwresconf_test.c,v 1.13 2007/06/19 23:46:59 tbox Exp $ */ + +#include <config.h> + +#include <stdlib.h> + +#include <isc/mem.h> +#include <isc/util.h> + +#include <lwres/lwres.h> + +#define USE_ISC_MEM + +static inline void +CHECK(int val, const char *msg) { + if (val != 0) { + fprintf(stderr, "%s returned %d\n", msg, val); + exit(1); + } +} + +#ifdef USE_ISC_MEM +/* + * Wrappers around our memory management stuff, for the lwres functions. + */ +static void * +mem_alloc(void *arg, size_t size) { + return (isc_mem_get(arg, size)); +} + +static void +mem_free(void *arg, void *mem, size_t size) { + isc_mem_put(arg, mem, size); +} +#endif + +int +main(int argc, char *argv[]) { + lwres_context_t *ctx; + const char *file = "/etc/resolv.conf"; + int ret; +#ifdef USE_ISC_MEM + isc_mem_t *mem; + isc_result_t result; +#endif + + if (argc > 1) { + file = argv[1]; + } + +#ifdef USE_ISC_MEM + mem = NULL; + result = isc_mem_create(0, 0, &mem); + INSIST(result == ISC_R_SUCCESS); +#endif + + ctx = NULL; +#ifdef USE_ISC_MEM + ret = lwres_context_create(&ctx, mem, mem_alloc, mem_free, 0); +#else + ret = lwres_context_create(&ctx, NULL, NULL, NULL, 0); +#endif + CHECK(ret, "lwres_context_create"); + + lwres_conf_init(ctx); + if (lwres_conf_parse(ctx, file) == 0) { + lwres_conf_print(ctx, stderr); + } else { + perror("lwres_conf_parse"); + } + + lwres_conf_clear(ctx); + lwres_context_destroy(&ctx); + +#ifdef USE_ISC_MEM + isc_mem_stats(mem, stdout); + isc_mem_destroy(&mem); +#endif + + return (0); +} |