⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list.c

📁 This piece of software was written as a replacement and extension for Tripwire. Tripwire is an exce
💻 C
字号:
/* aide, Advanced Intrusion Detection Environment * * Copyright (C) 1999,2000,2001,2002 Rami Lehti,Pablo Virolainen * $Header: /cvs-root-aide/aide2/src/list.c,v 1.5 2002/05/29 08:04:27 rammer Exp $ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include <stdlib.h>#include "list.h"#include "report.h"/*for locale support*/#include "locale-aide.h"/*for locale support*//* list * limitations: * Only the head knows where the tail is * Every item knows where the head is  * And that is not true anymore.  * Now list has header which knows head and tail. * Every irem knows header.  *//* list_append() * append an item to list * returns the head * The first argument is the head of the list * The second argument is the data to be added * Returns list head *//*  * Some way to handle mallocs failure would be nice. Now it say abort(). */list* list_append(list* listp,void*data){  list* newitem=NULL;  newitem=(list*)malloc(sizeof(list));  if (newitem==NULL) {    error(0,"Not enough memory to add a new item to list.\n");    abort();  }    if(listp==NULL){    list_header* header=(list_header*)malloc(sizeof(list_header));        if (header==NULL){      error(0,"Not enough memory for list header allocation\n");      abort();    }        newitem->data=data;    newitem->header=header;    newitem->next=NULL;    newitem->prev=NULL;    header->head=newitem;    header->tail=newitem;    return newitem;  }else {        /* We have nonempthy list.     * add to last     */        newitem->prev=listp->header->tail;    newitem->next=NULL;    newitem->data=data;    newitem->header=listp->header;        listp->header->tail->next=newitem;    listp->header->tail=newitem;    return listp;  }  /* Not reached */  return NULL;}/* * new_list_item() * create a new list item with data *//*obsoletelist* new_list_item(void* data){  list* item=NULL;  item=(list*)malloc(sizeof(list));  item->prev=NULL;  item->next=NULL;  item->head=item;  item->tail=item;  item->data=data;    abort();  return NULL;}*//* * delete_list_item() * delete a item from list * returns head of a list. */list* list_delete_item(list* item){  list* r;  if (item==NULL) {    error(200,"Tried to remove from empthy list\n");    return item;  }    if (item->header->head==item->header->tail) {    /*     * Ollaan poistamassa listan ainoaa alkiota.     * T鋖l鰅n palautetaan NULL     */    free(item->header);    free(item);    return NULL;  }    /*    * Nyt meill

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -