summaryrefslogtreecommitdiffstats
path: root/src/list.c
blob: d64c3eb8fa8e20a99f36592787e18c753dd5f30f (plain)
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
/*

    File: list.c

    Copyright (C) 2006-2008 Christophe GRENIER <grenier@cgsecurity.org>
  
    This software 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 the Free Software Foundation, Inc., 51
    Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include "types.h"
#include "common.h"
#include "list.h"

void list_truncate(alloc_list_t *list, const uint64_t file_size)
{
  struct td_list_head *tmp;
  struct td_list_head *next;
  uint64_t size=0;
  td_list_for_each_safe(tmp, next, &list->list)
  {
    alloc_list_t *element=td_list_entry(tmp, alloc_list_t, list);
    if(size>=file_size)
    {
      td_list_del(tmp);
      free(element);
    }
    else if(element->data>0)
    {
      size+=(element->end-element->start+1);
      if(size>=file_size)
	element->end-=(size-file_size);
    }
  }
}