libalpm
Arch Linux Package Manager Library
libalpm_list(3)
Collaboration diagram for libalpm_list(3):

Data Structures

struct  alpm_list_t
 A doubly linked list. More...
 

Macros

#define FREELIST(p)   do { alpm_list_free_inner(p, free); alpm_list_free(p); p = NULL; } while(0)
 Frees a list and its contents.
 

Typedefs

typedef void(* alpm_list_fn_free) (void *item)
 item deallocation callback.
 
typedef int(* alpm_list_fn_cmp) (const void *, const void *)
 item comparison callback
 

Functions

void alpm_list_free (alpm_list_t *list)
 Free a list, but not the contained data.
 
void alpm_list_free_inner (alpm_list_t *list, alpm_list_fn_free fn)
 Free the internal data of a list structure but not the list itself.
 
alpm_list_talpm_list_add (alpm_list_t *list, void *data)
 Add a new item to the end of the list.
 
alpm_list_talpm_list_append (alpm_list_t **list, void *data)
 Add a new item to the end of the list.
 
alpm_list_talpm_list_append_strdup (alpm_list_t **list, const char *data)
 Duplicate and append a string to a list.
 
alpm_list_talpm_list_add_sorted (alpm_list_t *list, void *data, alpm_list_fn_cmp fn)
 Add items to a list in sorted order.
 
alpm_list_talpm_list_join (alpm_list_t *first, alpm_list_t *second)
 Join two lists.
 
alpm_list_talpm_list_mmerge (alpm_list_t *left, alpm_list_t *right, alpm_list_fn_cmp fn)
 Merge the two sorted sublists into one sorted list.
 
alpm_list_talpm_list_msort (alpm_list_t *list, size_t n, alpm_list_fn_cmp fn)
 Sort a list of size n using mergesort algorithm.
 
alpm_list_talpm_list_remove_item (alpm_list_t *haystack, alpm_list_t *item)
 Remove an item from the list.
 
alpm_list_talpm_list_remove (alpm_list_t *haystack, const void *needle, alpm_list_fn_cmp fn, void **data)
 Remove an item from the list.
 
alpm_list_talpm_list_remove_str (alpm_list_t *haystack, const char *needle, char **data)
 Remove a string from a list.
 
alpm_list_talpm_list_remove_dupes (const alpm_list_t *list)
 Create a new list without any duplicates.
 
alpm_list_talpm_list_strdup (const alpm_list_t *list)
 Copy a string list, including data.
 
alpm_list_talpm_list_copy (const alpm_list_t *list)
 Copy a list, without copying data.
 
alpm_list_talpm_list_copy_data (const alpm_list_t *list, size_t size)
 Copy a list and copy the data.
 
alpm_list_talpm_list_reverse (alpm_list_t *list)
 Create a new list in reverse order.
 
alpm_list_talpm_list_nth (const alpm_list_t *list, size_t n)
 Return nth element from list (starting from 0).
 
alpm_list_talpm_list_next (const alpm_list_t *list)
 Get the next element of a list.
 
alpm_list_talpm_list_previous (const alpm_list_t *list)
 Get the previous element of a list.
 
alpm_list_talpm_list_last (const alpm_list_t *list)
 Get the last item in the list.
 
size_t alpm_list_count (const alpm_list_t *list)
 Get the number of items in a list.
 
void * alpm_list_find (const alpm_list_t *haystack, const void *needle, alpm_list_fn_cmp fn)
 Find an item in a list.
 
void * alpm_list_find_ptr (const alpm_list_t *haystack, const void *needle)
 Find an item in a list.
 
char * alpm_list_find_str (const alpm_list_t *haystack, const char *needle)
 Find a string in a list.
 
int alpm_list_cmp_unsorted (const alpm_list_t *left, const alpm_list_t *right, alpm_list_fn_cmp fn)
 Check if two lists contain the same data, ignoring order.
 
void alpm_list_diff_sorted (const alpm_list_t *left, const alpm_list_t *right, alpm_list_fn_cmp fn, alpm_list_t **onlyleft, alpm_list_t **onlyright)
 Find the differences between list left and list right
 
alpm_list_talpm_list_diff (const alpm_list_t *lhs, const alpm_list_t *rhs, alpm_list_fn_cmp fn)
 Find the items in list lhs that are not present in list rhs.
 
void * alpm_list_to_array (const alpm_list_t *list, size_t n, size_t size)
 Copy a list and data into a standard C array of fixed length.
 

Detailed Description

Functions to manipulate alpm_list_t lists.

These functions are designed to create, destroy, and modify lists of type alpm_list_t. This is an internal list type used by libalpm that is publicly exposed for use by frontends if desired.

It is exposed so front ends can use it to prevent the need to reimplement lists of their own; however, it is not required that the front end uses it.


Data Structure Documentation

◆ alpm_list_t

struct alpm_list_t

A doubly linked list.

Data Fields
void * data data held by the list node
struct _alpm_list_t * next pointer to the next node
struct _alpm_list_t * prev pointer to the previous node

Macro Definition Documentation

◆ FREELIST

Typedef Documentation

◆ alpm_list_fn_cmp

typedef int(* alpm_list_fn_cmp) (const void *, const void *)

item comparison callback

◆ alpm_list_fn_free

typedef void(* alpm_list_fn_free) (void *item)

item deallocation callback.

Parameters
itemthe item to free

Function Documentation

◆ alpm_list_add()

◆ alpm_list_add_sorted()

alpm_list_t * alpm_list_add_sorted ( alpm_list_t * list,
void * data,
alpm_list_fn_cmp fn )

Add items to a list in sorted order.

Parameters
listthe list to add to
datathe new item to be added to the list
fnthe comparison function to use to determine order
Returns
the resultant list

References alpm_list_add(), alpm_list_t::data, alpm_list_t::next, and alpm_list_t::prev.

◆ alpm_list_append()

alpm_list_t * alpm_list_append ( alpm_list_t ** list,
void * data )

Add a new item to the end of the list.

Parameters
listthe list to add to
datathe new item to be added to the list
Returns
the newly added item

References alpm_list_last(), alpm_list_t::data, alpm_list_t::next, and alpm_list_t::prev.

Referenced by alpm_fetch_pkgurl(), alpm_list_add(), alpm_list_append_strdup(), alpm_list_copy(), alpm_list_copy_data(), alpm_list_remove_dupes(), alpm_list_reverse(), find_server_errors(), local_db_read(), parse_descfile(), and sync_db_read().

◆ alpm_list_append_strdup()

alpm_list_t * alpm_list_append_strdup ( alpm_list_t ** list,
const char * data )

Duplicate and append a string to a list.

Parameters
listthe list to append to
datathe string to duplicate and append
Returns
the newly added item

References alpm_list_append().

Referenced by alpm_list_strdup().

◆ alpm_list_cmp_unsorted()

int alpm_list_cmp_unsorted ( const alpm_list_t * left,
const alpm_list_t * right,
alpm_list_fn_cmp fn )

Check if two lists contain the same data, ignoring order.

Lists are considered equal if they both contain the same data regardless of order.

Parameters
leftthe first list
rightthe second list
fnthe comparison function
Returns
1 if the lists are equal, 0 if not equal, -1 on error.

References alpm_list_count(), alpm_list_t::data, and alpm_list_t::next.

Referenced by check_pkg_field_matches_db().

◆ alpm_list_copy()

alpm_list_t * alpm_list_copy ( const alpm_list_t * list)

Copy a list, without copying data.

Parameters
listthe list to copy
Returns
a copy of the original list

References alpm_list_append(), alpm_list_free(), alpm_list_t::data, and alpm_list_t::next.

Referenced by alpm_list_diff().

◆ alpm_list_copy_data()

alpm_list_t * alpm_list_copy_data ( const alpm_list_t * list,
size_t size )

Copy a list and copy the data.

Note that the data elements to be copied should not contain pointers and should also be of constant size.

Parameters
listthe list to copy
sizethe size of each data element
Returns
a copy of the original list, data copied as well

References alpm_list_append(), alpm_list_t::data, FREELIST, and alpm_list_t::next.

◆ alpm_list_count()

size_t alpm_list_count ( const alpm_list_t * list)

Get the number of items in a list.

Parameters
listthe list
Returns
the number of list items

References alpm_list_t::next.

Referenced by alpm_fetch_pkgurl(), alpm_list_cmp_unsorted(), alpm_list_diff(), check_keyring(), compute_requiredby(), curl_download_internal(), download_files(), mount_point_list(), resolvedep(), and sync_db_populate().

◆ alpm_list_diff()

alpm_list_t * alpm_list_diff ( const alpm_list_t * lhs,
const alpm_list_t * rhs,
alpm_list_fn_cmp fn )

Find the items in list lhs that are not present in list rhs.

Parameters
lhsthe first list
rhsthe second list
fnthe comparison function
Returns
a list containing all items in lhs not present in rhs

References alpm_list_copy(), alpm_list_count(), alpm_list_diff_sorted(), alpm_list_free(), and alpm_list_msort().

Referenced by dep_graph_init().

◆ alpm_list_diff_sorted()

void alpm_list_diff_sorted ( const alpm_list_t * left,
const alpm_list_t * right,
alpm_list_fn_cmp fn,
alpm_list_t ** onlyleft,
alpm_list_t ** onlyright )

Find the differences between list left and list right

The two lists must be sorted. Items only in list left are added to the onlyleft list. Items only in list right are added to the onlyright list.

Parameters
leftthe first list
rightthe second list
fnthe comparison function
onlyleftpointer to the first result list
onlyrightpointer to the second result list

References alpm_list_add(), alpm_list_t::data, and alpm_list_t::next.

Referenced by alpm_list_diff().

◆ alpm_list_find()

void * alpm_list_find ( const alpm_list_t * haystack,
const void * needle,
alpm_list_fn_cmp fn )

Find an item in a list.

Parameters
needlethe item to search
haystackthe list
fnthe comparison function for searching (!= NULL)
Returns
needle if found, NULL otherwise

References alpm_list_t::data, and alpm_list_t::next.

Referenced by alpm_list_find_ptr(), alpm_list_find_str(), alpm_pkg_should_ignore(), and check_keyring().

◆ alpm_list_find_ptr()

void * alpm_list_find_ptr ( const alpm_list_t * haystack,
const void * needle )

Find an item in a list.

Search for the item whose data matches that of the needle.

Parameters
needlethe data to search for (== comparison)
haystackthe list
Returns
needle if found, NULL otherwise

References alpm_list_find(), and ptr_cmp().

Referenced by alpm_list_remove_dupes(), and load_grpcache().

◆ alpm_list_find_str()

char * alpm_list_find_str ( const alpm_list_t * haystack,
const char * needle )

Find a string in a list.

Parameters
needlethe string to search for
haystackthe list
Returns
needle if found, NULL otherwise

References alpm_list_find().

Referenced by find_requiredby(), and should_skip_file().

◆ alpm_list_free()

◆ alpm_list_free_inner()

void alpm_list_free_inner ( alpm_list_t * list,
alpm_list_fn_free fn )

Free the internal data of a list structure but not the list itself.

Parameters
listthe list to free
fna free function for the internal data

References alpm_list_t::data, and alpm_list_t::next.

Referenced by alpm_db_update(), alpm_fetch_pkgurl(), alpm_option_set_assumeinstalled(), download_files(), free_deplist(), remove_prepare_cascade(), and remove_prepare_keep_needed().

◆ alpm_list_join()

alpm_list_t * alpm_list_join ( alpm_list_t * first,
alpm_list_t * second )

Join two lists.

The two lists must be independent. Do not free the original lists after calling this function, as this is not a copy operation. The list pointers passed in should be considered invalid after calling this function.

Parameters
firstthe first list
secondthe second list
Returns
the resultant joined list

References alpm_list_t::next, and alpm_list_t::prev.

Referenced by alpm_sync_sysupgrade(), and pkghash_add_pkg().

◆ alpm_list_last()

alpm_list_t * alpm_list_last ( const alpm_list_t * list)

Get the last item in the list.

Parameters
listthe list
Returns
the last element in the list

References alpm_list_t::prev.

Referenced by alpm_list_append(), and alpm_list_reverse().

◆ alpm_list_mmerge()

alpm_list_t * alpm_list_mmerge ( alpm_list_t * left,
alpm_list_t * right,
alpm_list_fn_cmp fn )

Merge the two sorted sublists into one sorted list.

Parameters
leftthe first list
rightthe second list
fncomparison function for determining merge order
Returns
the resultant list

References alpm_list_t::data, alpm_list_t::next, and alpm_list_t::prev.

Referenced by alpm_list_msort(), and pkghash_add_pkg().

◆ alpm_list_msort()

alpm_list_t * alpm_list_msort ( alpm_list_t * list,
size_t n,
alpm_list_fn_cmp fn )

Sort a list of size n using mergesort algorithm.

Parameters
listthe list to sort
nthe size of the list
fnthe comparison function for determining order
Returns
the resultant list

References alpm_list_mmerge(), alpm_list_msort(), alpm_list_t::next, and alpm_list_t::prev.

Referenced by alpm_list_diff(), alpm_list_msort(), compute_requiredby(), curl_download_internal(), local_db_populate(), mount_point_list(), and sync_db_populate().

◆ alpm_list_next()

alpm_list_t * alpm_list_next ( const alpm_list_t * list)
inline

Get the next element of a list.

Parameters
listthe list node
Returns
the next element, or NULL when no more elements exist

References alpm_list_t::next.

Referenced by local_db_read(), and remove_notify_needed_optdepends().

◆ alpm_list_nth()

alpm_list_t * alpm_list_nth ( const alpm_list_t * list,
size_t n )

Return nth element from list (starting from 0).

Parameters
listthe list
nthe index of the item to find (n < alpm_list_count(list) IS needed)
Returns
an alpm_list_t node for index n

References alpm_list_t::next.

Referenced by resolvedep().

◆ alpm_list_previous()

alpm_list_t * alpm_list_previous ( const alpm_list_t * list)
inline

Get the previous element of a list.

Parameters
listthe list head
Returns
the previous element, or NULL when no previous element exist

References alpm_list_t::prev.

◆ alpm_list_remove()

alpm_list_t * alpm_list_remove ( alpm_list_t * haystack,
const void * needle,
alpm_list_fn_cmp fn,
void ** data )

Remove an item from the list.

Parameters
haystackthe list to remove the item from
needlethe data member of the item we're removing
fnthe comparison function for searching
dataoutput parameter containing data of the removed item
Returns
the resultant list

References alpm_list_remove_item(), alpm_list_t::data, and alpm_list_t::next.

Referenced by alpm_db_unregister(), alpm_list_remove_str(), alpm_option_remove_assumeinstalled(), and remove_prepare_keep_needed().

◆ alpm_list_remove_dupes()

alpm_list_t * alpm_list_remove_dupes ( const alpm_list_t * list)

Create a new list without any duplicates.

This does NOT copy data members.

Parameters
listthe list to copy
Returns
a new list containing non-duplicate items

References alpm_list_append(), alpm_list_find_ptr(), alpm_list_free(), alpm_list_t::data, and alpm_list_t::next.

◆ alpm_list_remove_item()

alpm_list_t * alpm_list_remove_item ( alpm_list_t * haystack,
alpm_list_t * item )

Remove an item from the list.

item is not freed; this is the responsibility of the caller.

Parameters
haystackthe list to remove the item from
itemthe item to remove from the list
Returns
the resultant list

References alpm_list_t::next, and alpm_list_t::prev.

Referenced by alpm_list_remove(), and dep_graph_init().

◆ alpm_list_remove_str()

alpm_list_t * alpm_list_remove_str ( alpm_list_t * haystack,
const char * needle,
char ** data )

Remove a string from a list.

Parameters
haystackthe list to remove the item from
needlethe data member of the item we're removing
dataoutput parameter containing data of the removed item
Returns
the resultant list

References alpm_list_remove().

Referenced by alpm_db_remove_cache_server(), alpm_db_remove_server(), alpm_option_remove_architecture(), alpm_option_remove_cachedir(), and alpm_option_remove_hookdir().

◆ alpm_list_reverse()

alpm_list_t * alpm_list_reverse ( alpm_list_t * list)

Create a new list in reverse order.

Parameters
listthe list to copy
Returns
a new list in reverse order

References alpm_list_append(), alpm_list_free(), alpm_list_last(), alpm_list_t::data, and alpm_list_t::prev.

◆ alpm_list_strdup()

alpm_list_t * alpm_list_strdup ( const alpm_list_t * list)

Copy a string list, including data.

Parameters
listthe list to copy
Returns
a copy of the original list

References alpm_list_append_strdup(), alpm_list_t::data, FREELIST, and alpm_list_t::next.

Referenced by alpm_option_set_architectures().

◆ alpm_list_to_array()

void * alpm_list_to_array ( const alpm_list_t * list,
size_t n,
size_t size )

Copy a list and data into a standard C array of fixed length.

Note that the data elements are shallow copied so any contained pointers will point to the original data.

Parameters
listthe list to copy
nthe size of the list
sizethe size of each data element
Returns
an array version of the original list, data copied as well

References alpm_list_t::data, and alpm_list_t::next.