summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2012-04-14 11:09:48 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2012-04-14 11:09:48 +0200
commit7d29ee5f1ef40171054886beefe39527f144dbc2 (patch)
tree943858ef36f1bc1602041987cd6b39e7413a190f
parent35ad901d7b6947e492911b0d5b672530cb645eb9 (diff)
New function td_list_entry_const()
-rw-r--r--src/dfxml.c2
-rw-r--r--src/dir.c4
-rw-r--r--src/filegen.c4
-rw-r--r--src/list.h3
-rw-r--r--src/ppartsel.c4
5 files changed, 10 insertions, 7 deletions
diff --git a/src/dfxml.c b/src/dfxml.c
index e9385a1..162833f 100644
--- a/src/dfxml.c
+++ b/src/dfxml.c
@@ -332,7 +332,7 @@ static void xml_log_file_recovered2_aux(const alloc_data_t *space, const alloc_d
uint64_t size=0;
for(tmp=&file->list; tmp!=&space->list; tmp=tmp->next)
{
- const alloc_data_t *element=td_list_entry(tmp, alloc_data_t, list);
+ const alloc_data_t *element=td_list_entry_const(tmp, const alloc_data_t, list);
if(size >= file_size)
return ;
if(element->data>0)
diff --git a/src/dir.c b/src/dir.c
index 3fe8cf1..b46de5f 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -340,8 +340,8 @@ int dir_whole_partition_log(disk_t *disk, const partition_t *partition, dir_data
int filesort(const struct td_list_head *a, const struct td_list_head *b)
{
- const file_info_t *file_a=td_list_entry(a, file_info_t, list);
- const file_info_t *file_b=td_list_entry(b, file_info_t, list);
+ const file_info_t *file_a=td_list_entry_const(a, const file_info_t, list);
+ const file_info_t *file_b=td_list_entry_const(b, const file_info_t, list);
/* Directories must be listed before files */
const int res=((file_b->stat.st_mode&LINUX_S_IFDIR)-(file_a->stat.st_mode&LINUX_S_IFDIR));
if(res)
diff --git a/src/filegen.c b/src/filegen.c
index a1eef80..7e81653 100644
--- a/src/filegen.c
+++ b/src/filegen.c
@@ -48,8 +48,8 @@ static unsigned int index_header_check(void);
static int file_check_cmp(const struct td_list_head *a, const struct td_list_head *b)
{
- const file_check_t *fc_a=td_list_entry(a, const file_check_t, list);
- const file_check_t *fc_b=td_list_entry(b, const file_check_t, list);
+ const file_check_t *fc_a=td_list_entry_const(a, const file_check_t, list);
+ const file_check_t *fc_b=td_list_entry_const(b, const file_check_t, list);
int res;
if(fc_a->length==0 && fc_b->length!=0)
return -1;
diff --git a/src/list.h b/src/list.h
index c0ca51f..392adc3 100644
--- a/src/list.h
+++ b/src/list.h
@@ -231,6 +231,9 @@ static inline void td_list_splice_init(struct td_list_head *list,
#define td_list_entry(ptr, type, member) \
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
+#define td_list_entry_const(ptr, type, member) \
+ ((type *)((const char *)(ptr)-(unsigned long)(&((type *)0)->member)))
+
/**
* __td_list_for_each - iterate over a list
* @pos: the &struct td_list_head to use as a loop counter.
diff --git a/src/ppartsel.c b/src/ppartsel.c
index eb914af..028338f 100644
--- a/src/ppartsel.c
+++ b/src/ppartsel.c
@@ -59,8 +59,8 @@ enum { INIT_SPACE_WHOLE, INIT_SPACE_PREINIT, INIT_SPACE_EXT2_GROUP, INIT_SPACE_E
static int spacerange_cmp(const struct td_list_head *a, const struct td_list_head *b)
{
- const alloc_data_t *space_a=td_list_entry(a, const alloc_data_t, list);
- const alloc_data_t *space_b=td_list_entry(b, const alloc_data_t, list);
+ const alloc_data_t *space_a=td_list_entry_const(a, const alloc_data_t, list);
+ const alloc_data_t *space_b=td_list_entry_const(b, const alloc_data_t, list);
if(space_a->start < space_b->start)
return -1;
if(space_a->start > space_b->start)