[insert project logo here (125x200px max)] Navigator Mailinglists Please report any errors or ommissions you find to our `Help' mailinglist, or post a message in the Forums. Copyright and Licensing Information Snap is (c) Jonathan T. Moore, 1999-2002 and licensed under the GNU General Public License (GPL). All other parts of Splash are (c) Willem de Bruijn, 2002-2003 and licensed under the BSD Open Source License. All sourcecode is made publicly available. Acknowledgement Splash and the Splash website are hosted by SourceForge.net |
Splash - DocumentationSNMP Plus a Lightweight API for SNAP Handlingsnap-1.1-wjdb/lib/snap_list.cGo to the documentation of this file.00001 /* snap-1.0. Copyright (C) 2000 by Jonathan T. Moore and Michael Hicks. 00002 * 00003 * list.c : routines for manipulating SNAP lists 00004 * 00005 * $Id: snap_list.c,v 1.1.1.1 2002/12/04 18:59:42 wdebruij Exp $ 00006 */ 00007 00008 #ifdef __KERNEL__ 00009 #include <linux/slab.h> 00010 #include <snap/list.h> 00011 #else 00012 #include "list.h" 00013 #include "memalloc.h" 00014 #endif /* __KERNEL__ */ 00015 00016 #ifndef _SNAP_LIST_T 00017 typedef struct l { 00018 void *v; 00019 struct l *next; 00020 } list_t; 00021 #define _SNAP_LIST_T 00022 #endif /* !_SNAP_LIST_T */ 00023 00024 list_t *cons(void *v, list_t *next) { 00025 list_t *cell; 00026 00027 #ifdef __KERNEL__ 00028 cell = (list_t *)kmalloc(sizeof(list_t),GFP_ATOMIC); 00029 if (!cell) { 00030 printk(KERN_WARNING "%s:%d: kmalloc failed\n",__FILE__,__LINE__); 00031 return NULL; 00032 } 00033 #else 00034 memalloc(cell,list_t *,sizeof(list_t)); 00035 #endif /* __KERNEL__ */ 00036 cell->v = v; 00037 cell->next = next; 00038 return cell; 00039 } 00040 00041 void free_list(list_t *list) { 00042 list_t *iter = list, *tmp; 00043 while (iter != NULL) { 00044 tmp = iter; 00045 #ifdef __KERNEL__ 00046 kfree(iter); 00047 #else 00048 free(iter); 00049 #endif /* __KERNEL__ */ 00050 iter = tmp->next; 00051 } 00052 } 00053 00054 int length_list(list_t *list) { 00055 int i = 0; 00056 list_t *iter = list; 00057 while (iter != NULL) { 00058 i++; 00059 iter = iter->next; 00060 } 00061 return i; 00062 } 00063 |