1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
24*0Sstevel@tonic-gate */
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate /*
27*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28*0Sstevel@tonic-gate * Use is subject to license terms.
29*0Sstevel@tonic-gate */
30*0Sstevel@tonic-gate
31*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate /*
34*0Sstevel@tonic-gate *
35*0Sstevel@tonic-gate * MODULE: dat_dictionary.c
36*0Sstevel@tonic-gate *
37*0Sstevel@tonic-gate * PURPOSE: dictionary data structure
38*0Sstevel@tonic-gate *
39*0Sstevel@tonic-gate * $Id: dat_dictionary.c,v 1.11 2003/08/05 19:01:48 jlentini Exp $
40*0Sstevel@tonic-gate */
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gate
43*0Sstevel@tonic-gate #include "dat_dictionary.h"
44*0Sstevel@tonic-gate
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate /*
47*0Sstevel@tonic-gate *
48*0Sstevel@tonic-gate * Structures
49*0Sstevel@tonic-gate *
50*0Sstevel@tonic-gate */
51*0Sstevel@tonic-gate
52*0Sstevel@tonic-gate typedef struct DAT_DICTIONARY_NODE
53*0Sstevel@tonic-gate {
54*0Sstevel@tonic-gate DAT_PROVIDER_INFO key;
55*0Sstevel@tonic-gate DAT_DICTIONARY_DATA data;
56*0Sstevel@tonic-gate struct DAT_DICTIONARY_NODE *prev;
57*0Sstevel@tonic-gate struct DAT_DICTIONARY_NODE *next;
58*0Sstevel@tonic-gate } DAT_DICTIONARY_NODE;
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate
61*0Sstevel@tonic-gate struct DAT_DICTIONARY
62*0Sstevel@tonic-gate {
63*0Sstevel@tonic-gate DAT_DICTIONARY_NODE *head;
64*0Sstevel@tonic-gate DAT_DICTIONARY_NODE *tail;
65*0Sstevel@tonic-gate DAT_COUNT size;
66*0Sstevel@tonic-gate };
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gate /*
69*0Sstevel@tonic-gate *
70*0Sstevel@tonic-gate * Function Declarations
71*0Sstevel@tonic-gate *
72*0Sstevel@tonic-gate */
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gate static DAT_RETURN
75*0Sstevel@tonic-gate dat_dictionary_key_dup(
76*0Sstevel@tonic-gate const DAT_PROVIDER_INFO *old_key,
77*0Sstevel@tonic-gate DAT_PROVIDER_INFO *new_key);
78*0Sstevel@tonic-gate
79*0Sstevel@tonic-gate static DAT_BOOLEAN
80*0Sstevel@tonic-gate dat_dictionary_key_is_equal(
81*0Sstevel@tonic-gate const DAT_PROVIDER_INFO *key_a,
82*0Sstevel@tonic-gate const DAT_PROVIDER_INFO *key_b);
83*0Sstevel@tonic-gate
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate /*
86*0Sstevel@tonic-gate *
87*0Sstevel@tonic-gate * External Functions
88*0Sstevel@tonic-gate *
89*0Sstevel@tonic-gate */
90*0Sstevel@tonic-gate
91*0Sstevel@tonic-gate
92*0Sstevel@tonic-gate /*
93*0Sstevel@tonic-gate * Function: dat_dictionary_create
94*0Sstevel@tonic-gate */
95*0Sstevel@tonic-gate
96*0Sstevel@tonic-gate DAT_RETURN
dat_dictionary_create(OUT DAT_DICTIONARY ** pp_dictionary)97*0Sstevel@tonic-gate dat_dictionary_create(
98*0Sstevel@tonic-gate OUT DAT_DICTIONARY **pp_dictionary)
99*0Sstevel@tonic-gate {
100*0Sstevel@tonic-gate DAT_DICTIONARY *p_dictionary;
101*0Sstevel@tonic-gate DAT_RETURN status;
102*0Sstevel@tonic-gate
103*0Sstevel@tonic-gate dat_os_assert(NULL != pp_dictionary);
104*0Sstevel@tonic-gate
105*0Sstevel@tonic-gate status = DAT_SUCCESS;
106*0Sstevel@tonic-gate
107*0Sstevel@tonic-gate /* create the dictionary */
108*0Sstevel@tonic-gate p_dictionary = dat_os_alloc(sizeof (DAT_DICTIONARY));
109*0Sstevel@tonic-gate if (NULL == p_dictionary) {
110*0Sstevel@tonic-gate status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
111*0Sstevel@tonic-gate DAT_RESOURCE_MEMORY);
112*0Sstevel@tonic-gate goto bail;
113*0Sstevel@tonic-gate }
114*0Sstevel@tonic-gate
115*0Sstevel@tonic-gate (void) dat_os_memset(p_dictionary, '\0', sizeof (DAT_DICTIONARY));
116*0Sstevel@tonic-gate
117*0Sstevel@tonic-gate /* create the head node */
118*0Sstevel@tonic-gate p_dictionary->head = dat_os_alloc(sizeof (DAT_DICTIONARY_NODE));
119*0Sstevel@tonic-gate if (NULL == p_dictionary->head) {
120*0Sstevel@tonic-gate status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
121*0Sstevel@tonic-gate DAT_RESOURCE_MEMORY);
122*0Sstevel@tonic-gate goto bail;
123*0Sstevel@tonic-gate }
124*0Sstevel@tonic-gate
125*0Sstevel@tonic-gate (void) dat_os_memset(p_dictionary->head, '\0',
126*0Sstevel@tonic-gate sizeof (DAT_DICTIONARY_NODE));
127*0Sstevel@tonic-gate
128*0Sstevel@tonic-gate /* create the tail node */
129*0Sstevel@tonic-gate p_dictionary->tail = dat_os_alloc(sizeof (DAT_DICTIONARY_NODE));
130*0Sstevel@tonic-gate if (NULL == p_dictionary->tail) {
131*0Sstevel@tonic-gate status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
132*0Sstevel@tonic-gate DAT_RESOURCE_MEMORY);
133*0Sstevel@tonic-gate goto bail;
134*0Sstevel@tonic-gate }
135*0Sstevel@tonic-gate
136*0Sstevel@tonic-gate (void) dat_os_memset(p_dictionary->tail, '\0',
137*0Sstevel@tonic-gate sizeof (DAT_DICTIONARY_NODE));
138*0Sstevel@tonic-gate
139*0Sstevel@tonic-gate p_dictionary->head->next = p_dictionary->tail;
140*0Sstevel@tonic-gate p_dictionary->tail->prev = p_dictionary->head;
141*0Sstevel@tonic-gate
142*0Sstevel@tonic-gate *pp_dictionary = p_dictionary;
143*0Sstevel@tonic-gate
144*0Sstevel@tonic-gate bail:
145*0Sstevel@tonic-gate if (DAT_SUCCESS != status) {
146*0Sstevel@tonic-gate if (NULL != p_dictionary) {
147*0Sstevel@tonic-gate dat_os_free(p_dictionary, sizeof (DAT_DICTIONARY));
148*0Sstevel@tonic-gate
149*0Sstevel@tonic-gate if (NULL != p_dictionary->head) {
150*0Sstevel@tonic-gate dat_os_free(p_dictionary->head,
151*0Sstevel@tonic-gate sizeof (DAT_DICTIONARY_NODE));
152*0Sstevel@tonic-gate }
153*0Sstevel@tonic-gate
154*0Sstevel@tonic-gate if (NULL != p_dictionary->tail) {
155*0Sstevel@tonic-gate dat_os_free(p_dictionary->tail,
156*0Sstevel@tonic-gate sizeof (DAT_DICTIONARY_NODE));
157*0Sstevel@tonic-gate }
158*0Sstevel@tonic-gate }
159*0Sstevel@tonic-gate }
160*0Sstevel@tonic-gate
161*0Sstevel@tonic-gate return (status);
162*0Sstevel@tonic-gate }
163*0Sstevel@tonic-gate
164*0Sstevel@tonic-gate
165*0Sstevel@tonic-gate /*
166*0Sstevel@tonic-gate * Function: dat_dictionary_destroy
167*0Sstevel@tonic-gate */
168*0Sstevel@tonic-gate
169*0Sstevel@tonic-gate DAT_RETURN
dat_dictionary_destroy(IN DAT_DICTIONARY * p_dictionary)170*0Sstevel@tonic-gate dat_dictionary_destroy(
171*0Sstevel@tonic-gate IN DAT_DICTIONARY *p_dictionary)
172*0Sstevel@tonic-gate {
173*0Sstevel@tonic-gate DAT_DICTIONARY_NODE *cur_node;
174*0Sstevel@tonic-gate
175*0Sstevel@tonic-gate dat_os_assert(NULL != p_dictionary);
176*0Sstevel@tonic-gate
177*0Sstevel@tonic-gate while (NULL != p_dictionary->head) {
178*0Sstevel@tonic-gate cur_node = p_dictionary->head;
179*0Sstevel@tonic-gate p_dictionary->head = cur_node->next;
180*0Sstevel@tonic-gate
181*0Sstevel@tonic-gate dat_os_free(cur_node, sizeof (DAT_DICTIONARY_NODE));
182*0Sstevel@tonic-gate }
183*0Sstevel@tonic-gate
184*0Sstevel@tonic-gate dat_os_free(p_dictionary, sizeof (DAT_DICTIONARY));
185*0Sstevel@tonic-gate
186*0Sstevel@tonic-gate return (DAT_SUCCESS);
187*0Sstevel@tonic-gate }
188*0Sstevel@tonic-gate
189*0Sstevel@tonic-gate
190*0Sstevel@tonic-gate /*
191*0Sstevel@tonic-gate * Function: dat_dictionary_size
192*0Sstevel@tonic-gate */
193*0Sstevel@tonic-gate
194*0Sstevel@tonic-gate DAT_RETURN
dat_dictionary_size(IN DAT_DICTIONARY * p_dictionary,OUT DAT_COUNT * p_size)195*0Sstevel@tonic-gate dat_dictionary_size(
196*0Sstevel@tonic-gate IN DAT_DICTIONARY *p_dictionary,
197*0Sstevel@tonic-gate OUT DAT_COUNT *p_size)
198*0Sstevel@tonic-gate {
199*0Sstevel@tonic-gate dat_os_assert(NULL != p_dictionary);
200*0Sstevel@tonic-gate dat_os_assert(NULL != p_size);
201*0Sstevel@tonic-gate
202*0Sstevel@tonic-gate *p_size = p_dictionary->size;
203*0Sstevel@tonic-gate
204*0Sstevel@tonic-gate return (DAT_SUCCESS);
205*0Sstevel@tonic-gate }
206*0Sstevel@tonic-gate
207*0Sstevel@tonic-gate
208*0Sstevel@tonic-gate /*
209*0Sstevel@tonic-gate * Function: dat_dictionary_entry_create
210*0Sstevel@tonic-gate */
211*0Sstevel@tonic-gate
212*0Sstevel@tonic-gate DAT_RETURN
dat_dictionary_entry_create(OUT DAT_DICTIONARY_ENTRY * p_entry)213*0Sstevel@tonic-gate dat_dictionary_entry_create(
214*0Sstevel@tonic-gate OUT DAT_DICTIONARY_ENTRY *p_entry)
215*0Sstevel@tonic-gate {
216*0Sstevel@tonic-gate DAT_DICTIONARY_NODE *node;
217*0Sstevel@tonic-gate DAT_RETURN dat_status;
218*0Sstevel@tonic-gate
219*0Sstevel@tonic-gate dat_os_assert(NULL != p_entry);
220*0Sstevel@tonic-gate
221*0Sstevel@tonic-gate dat_status = DAT_SUCCESS;
222*0Sstevel@tonic-gate
223*0Sstevel@tonic-gate node = dat_os_alloc(sizeof (DAT_DICTIONARY_NODE));
224*0Sstevel@tonic-gate if (NULL == node) {
225*0Sstevel@tonic-gate dat_status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
226*0Sstevel@tonic-gate DAT_RESOURCE_MEMORY);
227*0Sstevel@tonic-gate goto bail;
228*0Sstevel@tonic-gate }
229*0Sstevel@tonic-gate
230*0Sstevel@tonic-gate *p_entry = node;
231*0Sstevel@tonic-gate
232*0Sstevel@tonic-gate bail:
233*0Sstevel@tonic-gate return (dat_status);
234*0Sstevel@tonic-gate }
235*0Sstevel@tonic-gate
236*0Sstevel@tonic-gate
237*0Sstevel@tonic-gate /*
238*0Sstevel@tonic-gate * Function: dat_dictionary_entry_destroy
239*0Sstevel@tonic-gate */
240*0Sstevel@tonic-gate
241*0Sstevel@tonic-gate DAT_RETURN
dat_dictionary_entry_destroy(OUT DAT_DICTIONARY_ENTRY entry)242*0Sstevel@tonic-gate dat_dictionary_entry_destroy(
243*0Sstevel@tonic-gate OUT DAT_DICTIONARY_ENTRY entry)
244*0Sstevel@tonic-gate {
245*0Sstevel@tonic-gate dat_os_free(entry, sizeof (DAT_DICTIONARY_NODE));
246*0Sstevel@tonic-gate return (DAT_SUCCESS);
247*0Sstevel@tonic-gate }
248*0Sstevel@tonic-gate
249*0Sstevel@tonic-gate
250*0Sstevel@tonic-gate /*
251*0Sstevel@tonic-gate * Function: dat_dictionary_insert
252*0Sstevel@tonic-gate */
253*0Sstevel@tonic-gate
254*0Sstevel@tonic-gate DAT_RETURN
dat_dictionary_insert(IN DAT_DICTIONARY * p_dictionary,IN DAT_DICTIONARY_ENTRY entry,IN const DAT_PROVIDER_INFO * key,IN DAT_DICTIONARY_DATA data)255*0Sstevel@tonic-gate dat_dictionary_insert(
256*0Sstevel@tonic-gate IN DAT_DICTIONARY *p_dictionary,
257*0Sstevel@tonic-gate IN DAT_DICTIONARY_ENTRY entry,
258*0Sstevel@tonic-gate IN const DAT_PROVIDER_INFO *key,
259*0Sstevel@tonic-gate IN DAT_DICTIONARY_DATA data)
260*0Sstevel@tonic-gate {
261*0Sstevel@tonic-gate DAT_RETURN dat_status;
262*0Sstevel@tonic-gate DAT_DICTIONARY_NODE *cur_node, *prev_node, *next_node;
263*0Sstevel@tonic-gate
264*0Sstevel@tonic-gate dat_os_assert(NULL != p_dictionary);
265*0Sstevel@tonic-gate dat_os_assert(NULL != entry);
266*0Sstevel@tonic-gate
267*0Sstevel@tonic-gate cur_node = entry;
268*0Sstevel@tonic-gate
269*0Sstevel@tonic-gate if (DAT_SUCCESS == dat_dictionary_search(p_dictionary, key, NULL)) {
270*0Sstevel@tonic-gate dat_status = DAT_ERROR(DAT_PROVIDER_ALREADY_REGISTERED, 0);
271*0Sstevel@tonic-gate goto bail;
272*0Sstevel@tonic-gate }
273*0Sstevel@tonic-gate
274*0Sstevel@tonic-gate dat_status = dat_dictionary_key_dup(key, &cur_node->key);
275*0Sstevel@tonic-gate if (DAT_SUCCESS != dat_status) {
276*0Sstevel@tonic-gate goto bail;
277*0Sstevel@tonic-gate }
278*0Sstevel@tonic-gate
279*0Sstevel@tonic-gate /* insert node at end of list to preserve registration order */
280*0Sstevel@tonic-gate prev_node = p_dictionary->tail->prev;
281*0Sstevel@tonic-gate next_node = p_dictionary->tail;
282*0Sstevel@tonic-gate
283*0Sstevel@tonic-gate cur_node->data = data;
284*0Sstevel@tonic-gate cur_node->next = next_node;
285*0Sstevel@tonic-gate cur_node->prev = prev_node;
286*0Sstevel@tonic-gate
287*0Sstevel@tonic-gate prev_node->next = cur_node;
288*0Sstevel@tonic-gate next_node->prev = cur_node;
289*0Sstevel@tonic-gate
290*0Sstevel@tonic-gate p_dictionary->size++;
291*0Sstevel@tonic-gate
292*0Sstevel@tonic-gate bail:
293*0Sstevel@tonic-gate return (dat_status);
294*0Sstevel@tonic-gate }
295*0Sstevel@tonic-gate
296*0Sstevel@tonic-gate
297*0Sstevel@tonic-gate /*
298*0Sstevel@tonic-gate * Function: dat_dictionary_search
299*0Sstevel@tonic-gate */
300*0Sstevel@tonic-gate
301*0Sstevel@tonic-gate DAT_RETURN
dat_dictionary_search(IN DAT_DICTIONARY * p_dictionary,IN const DAT_PROVIDER_INFO * key,OUT DAT_DICTIONARY_DATA * p_data)302*0Sstevel@tonic-gate dat_dictionary_search(
303*0Sstevel@tonic-gate IN DAT_DICTIONARY *p_dictionary,
304*0Sstevel@tonic-gate IN const DAT_PROVIDER_INFO *key,
305*0Sstevel@tonic-gate OUT DAT_DICTIONARY_DATA *p_data)
306*0Sstevel@tonic-gate {
307*0Sstevel@tonic-gate DAT_DICTIONARY_NODE *cur_node;
308*0Sstevel@tonic-gate DAT_RETURN status;
309*0Sstevel@tonic-gate
310*0Sstevel@tonic-gate dat_os_assert(NULL != p_dictionary);
311*0Sstevel@tonic-gate
312*0Sstevel@tonic-gate status = DAT_ERROR(DAT_NAME_NOT_FOUND, 0);
313*0Sstevel@tonic-gate
314*0Sstevel@tonic-gate for (cur_node = p_dictionary->head->next;
315*0Sstevel@tonic-gate p_dictionary->tail != cur_node;
316*0Sstevel@tonic-gate cur_node = cur_node->next) {
317*0Sstevel@tonic-gate if (DAT_TRUE == dat_dictionary_key_is_equal(&cur_node->key,
318*0Sstevel@tonic-gate key)) {
319*0Sstevel@tonic-gate if (NULL != p_data) {
320*0Sstevel@tonic-gate *p_data = cur_node->data;
321*0Sstevel@tonic-gate }
322*0Sstevel@tonic-gate
323*0Sstevel@tonic-gate status = DAT_SUCCESS;
324*0Sstevel@tonic-gate goto bail;
325*0Sstevel@tonic-gate }
326*0Sstevel@tonic-gate }
327*0Sstevel@tonic-gate
328*0Sstevel@tonic-gate bail:
329*0Sstevel@tonic-gate return (status);
330*0Sstevel@tonic-gate }
331*0Sstevel@tonic-gate
332*0Sstevel@tonic-gate
333*0Sstevel@tonic-gate /*
334*0Sstevel@tonic-gate * Function: dat_dictionary_enumerate
335*0Sstevel@tonic-gate */
336*0Sstevel@tonic-gate
337*0Sstevel@tonic-gate DAT_RETURN
dat_dictionary_enumerate(IN DAT_DICTIONARY * p_dictionary,IN DAT_DICTIONARY_DATA array[],IN DAT_COUNT array_size)338*0Sstevel@tonic-gate dat_dictionary_enumerate(
339*0Sstevel@tonic-gate IN DAT_DICTIONARY *p_dictionary,
340*0Sstevel@tonic-gate IN DAT_DICTIONARY_DATA array[],
341*0Sstevel@tonic-gate IN DAT_COUNT array_size)
342*0Sstevel@tonic-gate {
343*0Sstevel@tonic-gate DAT_DICTIONARY_NODE *cur_node;
344*0Sstevel@tonic-gate DAT_COUNT i;
345*0Sstevel@tonic-gate DAT_RETURN status;
346*0Sstevel@tonic-gate
347*0Sstevel@tonic-gate dat_os_assert(NULL != p_dictionary);
348*0Sstevel@tonic-gate dat_os_assert(NULL != array);
349*0Sstevel@tonic-gate
350*0Sstevel@tonic-gate status = DAT_SUCCESS;
351*0Sstevel@tonic-gate
352*0Sstevel@tonic-gate if (array_size < p_dictionary->size) {
353*0Sstevel@tonic-gate status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES, 0);
354*0Sstevel@tonic-gate goto bail;
355*0Sstevel@tonic-gate }
356*0Sstevel@tonic-gate
357*0Sstevel@tonic-gate for (cur_node = p_dictionary->head->next, i = 0;
358*0Sstevel@tonic-gate p_dictionary->tail != cur_node;
359*0Sstevel@tonic-gate cur_node = cur_node->next, i++) {
360*0Sstevel@tonic-gate array[i] = cur_node->data;
361*0Sstevel@tonic-gate }
362*0Sstevel@tonic-gate
363*0Sstevel@tonic-gate bail:
364*0Sstevel@tonic-gate return (status);
365*0Sstevel@tonic-gate }
366*0Sstevel@tonic-gate
367*0Sstevel@tonic-gate
368*0Sstevel@tonic-gate /*
369*0Sstevel@tonic-gate * Function: dat_dictionary_remove
370*0Sstevel@tonic-gate */
371*0Sstevel@tonic-gate
372*0Sstevel@tonic-gate DAT_RETURN
dat_dictionary_remove(IN DAT_DICTIONARY * p_dictionary,IN DAT_DICTIONARY_ENTRY * p_entry,IN const DAT_PROVIDER_INFO * key,OUT DAT_DICTIONARY_DATA * p_data)373*0Sstevel@tonic-gate dat_dictionary_remove(
374*0Sstevel@tonic-gate IN DAT_DICTIONARY *p_dictionary,
375*0Sstevel@tonic-gate IN DAT_DICTIONARY_ENTRY *p_entry,
376*0Sstevel@tonic-gate IN const DAT_PROVIDER_INFO *key,
377*0Sstevel@tonic-gate OUT DAT_DICTIONARY_DATA *p_data)
378*0Sstevel@tonic-gate {
379*0Sstevel@tonic-gate DAT_DICTIONARY_NODE *cur_node, *prev_node, *next_node;
380*0Sstevel@tonic-gate DAT_RETURN status;
381*0Sstevel@tonic-gate
382*0Sstevel@tonic-gate dat_os_assert(NULL != p_dictionary);
383*0Sstevel@tonic-gate dat_os_assert(NULL != p_entry);
384*0Sstevel@tonic-gate
385*0Sstevel@tonic-gate status = DAT_ERROR(DAT_NAME_NOT_FOUND, 0);
386*0Sstevel@tonic-gate
387*0Sstevel@tonic-gate for (cur_node = p_dictionary->head->next;
388*0Sstevel@tonic-gate p_dictionary->tail != cur_node;
389*0Sstevel@tonic-gate cur_node = cur_node->next) {
390*0Sstevel@tonic-gate if (DAT_TRUE == dat_dictionary_key_is_equal(&cur_node->key,
391*0Sstevel@tonic-gate key)) {
392*0Sstevel@tonic-gate if (NULL != p_data) {
393*0Sstevel@tonic-gate *p_data = cur_node->data;
394*0Sstevel@tonic-gate }
395*0Sstevel@tonic-gate
396*0Sstevel@tonic-gate prev_node = cur_node->prev;
397*0Sstevel@tonic-gate next_node = cur_node->next;
398*0Sstevel@tonic-gate
399*0Sstevel@tonic-gate prev_node->next = next_node;
400*0Sstevel@tonic-gate next_node->prev = prev_node;
401*0Sstevel@tonic-gate
402*0Sstevel@tonic-gate *p_entry = cur_node;
403*0Sstevel@tonic-gate
404*0Sstevel@tonic-gate p_dictionary->size--;
405*0Sstevel@tonic-gate
406*0Sstevel@tonic-gate status = DAT_SUCCESS;
407*0Sstevel@tonic-gate goto bail;
408*0Sstevel@tonic-gate }
409*0Sstevel@tonic-gate }
410*0Sstevel@tonic-gate
411*0Sstevel@tonic-gate bail:
412*0Sstevel@tonic-gate return (status);
413*0Sstevel@tonic-gate }
414*0Sstevel@tonic-gate
415*0Sstevel@tonic-gate
416*0Sstevel@tonic-gate /*
417*0Sstevel@tonic-gate *
418*0Sstevel@tonic-gate * Internal Function Definitions
419*0Sstevel@tonic-gate *
420*0Sstevel@tonic-gate */
421*0Sstevel@tonic-gate
422*0Sstevel@tonic-gate
423*0Sstevel@tonic-gate /*
424*0Sstevel@tonic-gate * Function: dat_dictionary_key_create
425*0Sstevel@tonic-gate */
426*0Sstevel@tonic-gate
427*0Sstevel@tonic-gate DAT_RETURN
dat_dictionary_key_dup(const DAT_PROVIDER_INFO * old_key,DAT_PROVIDER_INFO * new_key)428*0Sstevel@tonic-gate dat_dictionary_key_dup(
429*0Sstevel@tonic-gate const DAT_PROVIDER_INFO *old_key,
430*0Sstevel@tonic-gate DAT_PROVIDER_INFO *new_key)
431*0Sstevel@tonic-gate {
432*0Sstevel@tonic-gate dat_os_assert(NULL != old_key);
433*0Sstevel@tonic-gate dat_os_assert(NULL != new_key);
434*0Sstevel@tonic-gate
435*0Sstevel@tonic-gate (void) dat_os_strncpy(new_key->ia_name, old_key->ia_name,
436*0Sstevel@tonic-gate DAT_NAME_MAX_LENGTH);
437*0Sstevel@tonic-gate new_key->dapl_version_major = old_key->dapl_version_major;
438*0Sstevel@tonic-gate new_key->dapl_version_minor = old_key->dapl_version_minor;
439*0Sstevel@tonic-gate new_key->is_thread_safe = old_key->is_thread_safe;
440*0Sstevel@tonic-gate
441*0Sstevel@tonic-gate return (DAT_SUCCESS);
442*0Sstevel@tonic-gate }
443*0Sstevel@tonic-gate
444*0Sstevel@tonic-gate
445*0Sstevel@tonic-gate /*
446*0Sstevel@tonic-gate * Function: dat_dictionary_key_is_equal
447*0Sstevel@tonic-gate */
448*0Sstevel@tonic-gate
449*0Sstevel@tonic-gate DAT_BOOLEAN
dat_dictionary_key_is_equal(const DAT_PROVIDER_INFO * key_a,const DAT_PROVIDER_INFO * key_b)450*0Sstevel@tonic-gate dat_dictionary_key_is_equal(
451*0Sstevel@tonic-gate const DAT_PROVIDER_INFO *key_a,
452*0Sstevel@tonic-gate const DAT_PROVIDER_INFO *key_b)
453*0Sstevel@tonic-gate {
454*0Sstevel@tonic-gate if ((dat_os_strlen(key_a->ia_name) == dat_os_strlen(key_b->ia_name)) &&
455*0Sstevel@tonic-gate (!dat_os_strncmp(key_a->ia_name, key_b->ia_name,
456*0Sstevel@tonic-gate dat_os_strlen(key_a->ia_name))) &&
457*0Sstevel@tonic-gate (key_a->dapl_version_major == key_b->dapl_version_major) &&
458*0Sstevel@tonic-gate (key_a->dapl_version_minor == key_b->dapl_version_minor) &&
459*0Sstevel@tonic-gate (key_a->is_thread_safe == key_b->is_thread_safe)) {
460*0Sstevel@tonic-gate return (DAT_TRUE);
461*0Sstevel@tonic-gate } else {
462*0Sstevel@tonic-gate return (DAT_FALSE);
463*0Sstevel@tonic-gate }
464*0Sstevel@tonic-gate }
465