diff options
author | Tobias Brunner <tobias@strongswan.org> | 2011-06-09 09:49:28 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2011-07-06 09:43:46 +0200 |
commit | 2bf9d39da64382e143b7201ec12888e42279da93 (patch) | |
tree | 236da89468b4e1d786d08abdf0f45450b1500e1d /src/libstrongswan/utils/linked_list.c | |
parent | c225f9b5585e1589d98a77b089924a8d4a70e216 (diff) | |
download | strongswan-2bf9d39da64382e143b7201ec12888e42279da93.tar.bz2 strongswan-2bf9d39da64382e143b7201ec12888e42279da93.tar.xz |
Make sure the enumerator stops after all items have been enumerated.
This also changes how insert_before behaves, before enumeration items
are inserted first, after enumeration last.
Diffstat (limited to 'src/libstrongswan/utils/linked_list.c')
-rw-r--r-- | src/libstrongswan/utils/linked_list.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/libstrongswan/utils/linked_list.c b/src/libstrongswan/utils/linked_list.c index aaea530bb..e4c1a3308 100644 --- a/src/libstrongswan/utils/linked_list.c +++ b/src/libstrongswan/utils/linked_list.c @@ -110,11 +110,20 @@ struct private_enumerator_t { * current item */ element_t *current; + + /** + * enumerator has enumerated all items + */ + bool finished; }; METHOD(enumerator_t, enumerate, bool, private_enumerator_t *this, void **item) { + if (this->finished) + { + return FALSE; + } if (!this->current) { this->current = this->list->first; @@ -125,6 +134,7 @@ METHOD(enumerator_t, enumerate, bool, } if (!this->current) { + this->finished = TRUE; return FALSE; } *item = this->current->value; @@ -151,6 +161,7 @@ METHOD(linked_list_t, reset_enumerator, void, private_linked_list_t *this, private_enumerator_t *enumerator) { enumerator->current = NULL; + enumerator->finished = FALSE; } METHOD(linked_list_t, get_count, int, @@ -267,7 +278,14 @@ METHOD(linked_list_t, insert_before, void, current = enumerator->current; if (!current) { - this->public.insert_last(&this->public, item); + if (enumerator->finished) + { + this->public.insert_last(&this->public, item); + } + else + { + this->public.insert_first(&this->public, item); + } return; } element = element_create(item); |