1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
/*
** Copyright (C) 2006 Olivier DEMBOUR
** $Id: list.c,v 1.3 2009/04/30 14:04:59 dembour 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 <string.h>
#include "dns.h"
#include "list.h"
#include "myerror.h"
/**
* @brief create an empty list
* @retval list
* @retval 0 on error
* @retval list on success
**/
t_simple_list *list_create_simple_cell(void)
{
t_simple_list *list;
if (!(list = malloc(sizeof(t_simple_list))))
return (0);
memset(list, 0, sizeof(t_simple_list));
return (list);
}
/**
* @brief create a cell
* @retval cell
* @retval 0 on error
* @retval list on success
**/
t_list *list_create_cell(void)
{
t_list *list;
if (!(list = malloc(sizeof(t_list))))
return (0);
list->next = 0;
list->status = FREE;
return (list);
}
/**
* @brief add the simple cell to the list
* @param[in] list simple list
* @param[in] cell
* @retval 0 on error
* @retval 1 on success
**/
int list_add_simple_cell(t_simple_list *list, t_simple_list *cell)
{
t_simple_list *ptr;
if (!list)
return (-1);
ptr = list;
while (ptr->next)
ptr = ptr->next;
ptr->next = cell;
return (1);
}
/**
* @brief add the cell to the simple list struct
* @param[in] list list
* @param[in] cell
* @retval 0 on error
* @retval 1 on success
**/
int list_add_cell(t_list *list, t_list *cell)
{
t_list *ptr;
if (!list)
return (-1);
ptr = list;
while (ptr->next)
ptr = ptr->next;
ptr->next = cell;
return (1);
}
/**
* @brief free cell in list
* @param[in] cell
**/
int list_destroy_cell(t_list *cell)
{
if (!cell)
return (-1);
free(cell);
cell=0;
return (0);
}
/**
* @brief free simple cell in list
* @param[in] cell
**/
int list_destroy_simple_cell(t_simple_list *cell)
{
if (!cell)
return (-1);
free(cell);
cell=0;
return (0);
}
|