diff options
author | Pali Rohár <pali.rohar@gmail.com> | 2012-08-07 20:52:37 +0200 |
---|---|---|
committer | Pali Rohár <pali.rohar@gmail.com> | 2012-08-07 20:52:37 +0200 |
commit | 3fed685e79da924dbb7f4de0ffef51027937a0de (patch) | |
tree | fa85cc53eed42bcab39dae251c7542a1d1dba99f /src/image.c | |
parent | ef4a506905c11708c0183f46178b9fc40e8850db (diff) | |
download | 0xFFFF-3fed685e79da924dbb7f4de0ffef51027937a0de.tar.bz2 |
image: function image_list_add will add image to the end of list
Diffstat (limited to 'src/image.c')
-rw-r--r-- | src/image.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/image.c b/src/image.c index 224468f..fb54d61 100644 --- a/src/image.c +++ b/src/image.c @@ -317,21 +317,22 @@ size_t image_read(struct image * image, void * buf, size_t count) { void image_list_add(struct image_list ** list, struct image * image) { IMAGE_CHECK(image); - struct image_list * first = calloc(1, sizeof(struct image_list)); - if ( ! first ) + struct image_list * last = calloc(1, sizeof(struct image_list)); + if ( ! last ) return; - first->image = image; - first->next = *list; + last->image = image; - if ( *list ) { - first->prev = (*list)->prev; - if ( (*list)->prev ) - (*list)->prev->next = first; - (*list)->prev = first; + if ( ! *list ) { + *list = last; + return; } - *list = first; + while ( (*list)->next ) + list = &((*list)->next); + + last->prev = *list; + (*list)->next = last; } |