wickr-crypto-c
Functions
wickr_array_t

Functions

wickr_array_t * wickr_array_new (uint32_t item_count, uint8_t item_type, wickr_array_copy_func item_copy_func, wickr_array_destroy_func item_destroy_func)
 
uint32_t wickr_array_get_item_count (const wickr_array_t *array)
 
bool wickr_array_set_item (wickr_array_t *array, uint32_t index, void *item, bool copy)
 
void * wickr_array_fetch_item (const wickr_array_t *array, uint32_t index, bool copy)
 
wickr_array_t * wickr_array_copy (const wickr_array_t *array, bool deep_copy)
 
void wickr_array_destroy (wickr_array_t **array, bool destroy_items)
 

Detailed Description

Function Documentation

◆ wickr_array_copy()

wickr_array_t* wickr_array_copy ( const wickr_array_t *  array,
bool  deep_copy 
)

Make a copy

Parameters
arraythe array that is being copied
deep_copyif true, items inserted into the copied array will be a deep copy of items in the original array. If false, items in the original array will be inserted into the new array without transferring ownership
Returns
a copy of the array, or NULL if either allocating the copied array fails, or the deep_copy flag is set, and the copy operation fails on one of the items in the source array

◆ wickr_array_destroy()

void wickr_array_destroy ( wickr_array_t **  array,
bool  destroy_items 
)

Free an array

Parameters
arraythe array to destroy
destroy_itemsif true, the destroy function specified in 'wickr_array_create' will be called on each item in the array before destroying the array itself

◆ wickr_array_fetch_item()

void* wickr_array_fetch_item ( const wickr_array_t *  array,
uint32_t  index,
bool  copy 
)

Fetch an item at a specified index

Parameters
arraythe array from which an item will be fetched
indexthe position in the array the item will be fetched from
copyif true, a deep copy will be made and returned instead of the item stored in the array
Returns
the item in the array at position 'index'. NULL is returned if the index is not within the bounds of the array, if the item at position 'index' is NULL because it was never set with 'wickr_array_set_item', or because copy was true and the copy operation failed

◆ wickr_array_get_item_count()

uint32_t wickr_array_get_item_count ( const wickr_array_t *  array)

Fetch the size of the array

Note that null values in the array, or uninitialized values in the array will still be counted. The size of the array remains static after it has been created with wickr_array_new. Increasing or decreasing the size of the array is not yet supported

Parameters
arrayan array to get the item count of
Returns
the number of items contained in the array

◆ wickr_array_new()

wickr_array_t* wickr_array_new ( uint32_t  item_count,
uint8_t  item_type,
wickr_array_copy_func  item_copy_func,
wickr_array_destroy_func  item_destroy_func 
)

Create a new array

Parameters
item_countnumber of items the array will hold
item_typean integer that will designate the type of item the array will hold. All items in the array must be of the same type
item_copy_funca function that will provide a deep copy of an item in the array
item_destroy_funca function that will provide freeing memory consumed by an item in the array
Returns
a newly allocated array

◆ wickr_array_set_item()

bool wickr_array_set_item ( wickr_array_t *  array,
uint32_t  index,
void *  item,
bool  copy 
)

Assign an item to a specified index in the array

Parameters
arraythe array the item is being set into
indexthe position in the array the item is being set into
itemthe item that will be set in the array at the specified index
copyif true, a deep copy of the item will be made, and the copy will be inserted into the array
Returns
true if the index is within the bounds of the array, and item points to a valid pointer, will return false if copy is set and the copy operation fails