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