etc/services - sync with NetBSD-8
[minix.git] / external / bsd / bind / dist / bin / tests / lwresconf_test.c
blob15415c4aaed1baa5096a97c70e3ee778b10c65a5
1 /* $NetBSD: lwresconf_test.c,v 1.6 2014/12/10 04:37:53 christos Exp $ */
3 /*
4 * Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2000, 2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: lwresconf_test.c,v 1.13 2007/06/19 23:46:59 tbox Exp */
22 #include <config.h>
24 #include <stdlib.h>
26 #include <isc/mem.h>
27 #include <isc/util.h>
29 #include <lwres/lwres.h>
31 #define USE_ISC_MEM
33 static inline void
34 CHECK(int val, const char *msg) {
35 if (val != 0) {
36 fprintf(stderr, "%s returned %d\n", msg, val);
37 exit(1);
41 #ifdef USE_ISC_MEM
43 * Wrappers around our memory management stuff, for the lwres functions.
45 static void *
46 mem_alloc(void *arg, size_t size) {
47 return (isc_mem_get(arg, size));
50 static void
51 mem_free(void *arg, void *mem, size_t size) {
52 isc_mem_put(arg, mem, size);
54 #endif
56 int
57 main(int argc, char *argv[]) {
58 lwres_context_t *ctx;
59 const char *file = "/etc/resolv.conf";
60 int ret;
61 #ifdef USE_ISC_MEM
62 isc_mem_t *mem;
63 isc_result_t result;
64 #endif
66 if (argc > 1) {
67 file = argv[1];
70 #ifdef USE_ISC_MEM
71 mem = NULL;
72 result = isc_mem_create(0, 0, &mem);
73 INSIST(result == ISC_R_SUCCESS);
74 #endif
76 ctx = NULL;
77 #ifdef USE_ISC_MEM
78 ret = lwres_context_create(&ctx, mem, mem_alloc, mem_free, 0);
79 #else
80 ret = lwres_context_create(&ctx, NULL, NULL, NULL, 0);
81 #endif
82 CHECK(ret, "lwres_context_create");
84 lwres_conf_init(ctx);
85 if (lwres_conf_parse(ctx, file) == 0) {
86 lwres_conf_print(ctx, stderr);
87 } else {
88 perror("lwres_conf_parse");
91 lwres_conf_clear(ctx);
92 lwres_context_destroy(&ctx);
94 #ifdef USE_ISC_MEM
95 isc_mem_stats(mem, stdout);
96 isc_mem_destroy(&mem);
97 #endif
99 return (0);