1 /* 2 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 #pragma ident "%Z%%M% %I% %E% SMI" 7 8 /* 9 * Copyright 1995 by OpenVision Technologies, Inc. 10 * 11 * Permission to use, copy, modify, distribute, and sell this software 12 * and its documentation for any purpose is hereby granted without fee, 13 * provided that the above copyright notice appears in all copies and 14 * that both that copyright notice and this permission notice appear in 15 * supporting documentation, and that the name of OpenVision not be used 16 * in advertising or publicity pertaining to distribution of the software 17 * without specific, written prior permission. OpenVision makes no 18 * representations about the suitability of this software for any 19 * purpose. It is provided "as is" without express or implied warranty. 20 * 21 * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 22 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 23 * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR 24 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF 25 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 26 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 27 * PERFORMANCE OF THIS SOFTWARE. 28 */ 29 30 /* 31 * $Id: util_set.c 16165 2004-03-14 05:31:43Z raeburn $ 32 */ 33 34 #include <mechglueP.h> /* SUNW15resync - for MALLOC/FREE */ 35 #include "gssapiP_generic.h" 36 37 struct _g_set_elt { 38 void *key; 39 void *value; 40 struct _g_set_elt *next; 41 }; 42 43 int g_set_init(g_set_elt *s) 44 { 45 *s = NULL; 46 47 return(0); 48 } 49 50 #if 0 51 int g_set_destroy(g_set_elt *s) 52 { 53 g_set next; 54 55 while (*s) { 56 next = (*s)->next; 57 FREE(*s, sizeof(struct _g_set)); 58 *s = next; 59 } 60 61 return(0); 62 } 63 #endif 64 65 int g_set_entry_add(g_set_elt *s, void *key, void *value) 66 { 67 g_set_elt first; 68 69 if ((first = (struct _g_set_elt *) MALLOC(sizeof(struct _g_set_elt))) == NULL) 70 return(ENOMEM); 71 72 first->key = key; 73 first->value = value; 74 first->next = *s; 75 76 *s = first; 77 78 return(0); 79 } 80 81 int g_set_entry_delete(g_set_elt *s, void *key) 82 { 83 g_set_elt *p; 84 85 for (p=s; *p; p = &((*p)->next)) { 86 if ((*p)->key == key) { 87 g_set_elt next = (*p)->next; 88 FREE(*p, sizeof(struct _g_set_elt)); 89 *p = next; 90 91 return(0); 92 } 93 } 94 95 return(-1); 96 } 97 98 int g_set_entry_get(g_set_elt *s, void *key, void **value) 99 { 100 g_set_elt p; 101 102 for (p = *s; p; p = p->next) { 103 if (p->key == key) { 104 *value = p->value; 105 106 return(0); 107 } 108 } 109 110 *value = NULL; 111 112 return(-1); 113 } 114