Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / libbind / dist / irs / lcl.c
blob94b0b974a4c4f89001ea281df4b09f3c6bdc39ed
1 /* $NetBSD$ */
3 /*
4 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (c) 1996-1999 by Internet Software Consortium.
7 * Permission to use, copy, modify, and 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
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #if !defined(LINT) && !defined(CODECENTER)
21 static const char rcsid[] = "Id: lcl.c,v 1.4 2005/04/27 04:56:30 sra Exp";
22 #endif
24 /* Imports */
26 #include "port_before.h"
28 #include <stdlib.h>
29 #include <errno.h>
30 #include <string.h>
32 #include <sys/types.h>
33 #include <netinet/in.h>
34 #include <arpa/nameser.h>
35 #include <resolv.h>
37 #include <isc/memcluster.h>
39 #include <irs.h>
41 #include "port_after.h"
43 #include "irs_p.h"
44 #include "lcl_p.h"
46 /* Forward. */
48 static void lcl_close(struct irs_acc *);
49 static struct __res_state * lcl_res_get(struct irs_acc *);
50 static void lcl_res_set(struct irs_acc *, struct __res_state *,
51 void (*)(void *));
53 /* Public */
55 struct irs_acc *
56 irs_lcl_acc(const char *options) {
57 struct irs_acc *acc;
58 struct lcl_p *lcl;
60 UNUSED(options);
62 if (!(acc = memget(sizeof *acc))) {
63 errno = ENOMEM;
64 return (NULL);
66 memset(acc, 0x5e, sizeof *acc);
67 if (!(lcl = memget(sizeof *lcl))) {
68 errno = ENOMEM;
69 free(acc);
70 return (NULL);
72 memset(lcl, 0x5e, sizeof *lcl);
73 lcl->res = NULL;
74 lcl->free_res = NULL;
75 acc->private = lcl;
76 #ifdef WANT_IRS_GR
77 acc->gr_map = irs_lcl_gr;
78 #else
79 acc->gr_map = NULL;
80 #endif
81 #ifdef WANT_IRS_PW
82 acc->pw_map = irs_lcl_pw;
83 #else
84 acc->pw_map = NULL;
85 #endif
86 acc->sv_map = irs_lcl_sv;
87 acc->pr_map = irs_lcl_pr;
88 acc->ho_map = irs_lcl_ho;
89 acc->nw_map = irs_lcl_nw;
90 acc->ng_map = irs_lcl_ng;
91 acc->res_get = lcl_res_get;
92 acc->res_set = lcl_res_set;
93 acc->close = lcl_close;
94 return (acc);
97 /* Methods */
98 static struct __res_state *
99 lcl_res_get(struct irs_acc *this) {
100 struct lcl_p *lcl = (struct lcl_p *)this->private;
102 if (lcl->res == NULL) {
103 struct __res_state *res;
104 res = (struct __res_state *)malloc(sizeof *res);
105 if (res == NULL)
106 return (NULL);
107 memset(res, 0, sizeof *res);
108 lcl_res_set(this, res, free);
111 if ((lcl->res->options & RES_INIT) == 0U &&
112 res_ninit(lcl->res) < 0)
113 return (NULL);
115 return (lcl->res);
118 static void
119 lcl_res_set(struct irs_acc *this, struct __res_state *res,
120 void (*free_res)(void *)) {
121 struct lcl_p *lcl = (struct lcl_p *)this->private;
123 if (lcl->res && lcl->free_res) {
124 res_nclose(lcl->res);
125 (*lcl->free_res)(lcl->res);
128 lcl->res = res;
129 lcl->free_res = free_res;
132 static void
133 lcl_close(struct irs_acc *this) {
134 struct lcl_p *lcl = (struct lcl_p *)this->private;
136 if (lcl) {
137 if (lcl->free_res)
138 (*lcl->free_res)(lcl->res);
139 memput(lcl, sizeof *lcl);
141 memput(this, sizeof *this);
144 /*! \file */