📄 snap_list.c
字号:
/* snap-1.0. Copyright (C) 2000 by Jonathan T. Moore and Michael Hicks. * * list.c : routines for manipulating SNAP lists * * $Id: snap_list.c,v 1.2 2003/09/17 11:26:10 tmoerlan Exp $ */#ifdef __KERNEL__#include <linux/slab.h>#include <snap/list.h>#else#include "list.h"#include "memalloc.h"#endif /* __KERNEL__ */#ifndef _SNAP_LIST_Ttypedef struct l { void *v; struct l *next;} list_t;#define _SNAP_LIST_T#endif /* !_SNAP_LIST_T */list_t *cons(void *v, list_t *next) { list_t *cell; #ifdef __KERNEL__ cell = (list_t *)kmalloc(sizeof(list_t),GFP_ATOMIC); if (!cell) { printk(KERN_WARNING "%s:%d: kmalloc failed\n",__FILE__,__LINE__); return NULL; }#else memalloc(cell,list_t *,sizeof(list_t));#endif /* __KERNEL__ */ cell->v = v; cell->next = next; return cell;}void free_list(list_t *list) { list_t *iter = list, *tmp; while (iter != NULL) { tmp = iter;#ifdef __KERNEL__ kfree(iter);#else free(iter);#endif /* __KERNEL__ */ iter = tmp->next; }}int length_list(list_t *list) { int i = 0; list_t *iter = list; while (iter != NULL) { i++; iter = iter->next; } return i;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -