diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2017-05-12 21:28:01 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2017-05-12 21:28:01 (GMT) |
commit | 5fce21379baac06b7b9359c4b0fcb7fb3867c301 (patch) | |
tree | 19bf2943fe5a8a46bae227b8863bc9714fb3ec66 /src/common/array.c | |
parent | 8ee7fc5db965adaa835ca87bb3d2e2d43e52fbbb (diff) |
Added the ELF strings to the preloaded instruction list.
Diffstat (limited to 'src/common/array.c')
-rw-r--r-- | src/common/array.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/common/array.c b/src/common/array.c index f520d1d..dcb9344 100644 --- a/src/common/array.c +++ b/src/common/array.c @@ -215,6 +215,87 @@ void reset_flat_array(flat_array_t **array) /****************************************************************************** * * +* Paramètres : src = tableau compressé à consulter. * +* dest = tableau compressé à constituer. [OUT] * +* size = taille de ce nouvel élément. * +* notify = éventuelle fonction à appeler sur chaque élément. * +* * +* Description : Copie le contenu d'un tableau d'éléments dans un autre. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void copy_flat_array_items(flat_array_t **src, flat_array_t **dest, size_t size, item_notify_cb notify) +{ + void *item; /* Elément manipulé */ + ext_flat_array_t *extended; /* Version de tableau étendue */ + ext_flat_array_t *new; /* Nouvelle copie créée */ + size_t i; /* Boucle de parcours */ + + assert(!FLAT_ARRAY_IS_LOCKED(*src)); + assert(!FLAT_ARRAY_IS_LOCKED(*dest)); + + lock_flat_array(src); + lock_flat_array(dest); + + assert(FLAT_ARRAY_IS_EMPTY(*dest)); + + if (FLAT_ARRAY_IS_EMPTY(*src)) + goto cfai_done; + + if (FLAT_ARRAY_HAS_NO_INDEX(*src)) + { + item = GET_LONELY_ITEM(*src); + + if (notify != NULL) + notify(item); + + *dest = malloc(size); + memcpy(*dest, item, size); + + lock_flat_array(dest); + + } + + else + { + extended = EXTENDED_ARRAY(*src); + + new = (ext_flat_array_t *)malloc(sizeof(ext_flat_array_t)); + + new->items = malloc(extended->count * size); + new->count = extended->count; + + memcpy(new->items, extended->items, new->count * size); + + if (notify != NULL) + for (i = 0; i < new->count; i++) + { + item = (void *)(((char *)new->items) + i * size); + notify(item); + } + + FLAT_ARRAY_SET_INDEX(new); + + *dest = (flat_array_t *)new; + + lock_flat_array(dest); + + } + + cfai_done: + + unlock_flat_array(src); + unlock_flat_array(dest); + +} + + +/****************************************************************************** +* * * Paramètres : array = tableau compressé à consulter. * * * * Description : Indique la quantité d'éléments présents dans le tableau. * |