---
name: "libalpm_list"
section: "3"
platform: "linux"
package: "pacman"
version: "7.1.0.r9.g54d9411-3"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libalpm_list"
---

# libalpm\_list(3)

libalpm\_list(3)

## NAME

libalpm\_list - [libalpm\_list(3)](/libalpm_list/3.md)

## SYNOPSIS

### Data Structures

struct **alpm\_list\_t**\
 A doubly linked list.

### Macros

\#define **FREELIST**(p)\
 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\_t** \* **alpm\_list\_add** (**alpm\_list\_t** \*list, void \*data)\
 Add a new item to the end of the list.  **alpm\_list\_t** \* **alpm\_list\_append** (**alpm\_list\_t** \*\*list, void \*data)\
 Add a new item to the end of the list.  **alpm\_list\_t** \* **alpm\_list\_append\_strdup** (**alpm\_list\_t** \*\*list, const char \*data)\
 Duplicate and append a string to a list.  **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.  **alpm\_list\_t** \* **alpm\_list\_join** (**alpm\_list\_t** \*first, **alpm\_list\_t** \*second)\
 Join two lists.  **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.  **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.  **alpm\_list\_t** \* **alpm\_list\_remove\_item** (**alpm\_list\_t** \*haystack, **alpm\_list\_t** \*item)\
 Remove an item from the list.  **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.  **alpm\_list\_t** \* **alpm\_list\_remove\_str** (**alpm\_list\_t** \*haystack, const char \*needle, char \*\*data)\
 Remove a string from a list.  **alpm\_list\_t** \* **alpm\_list\_remove\_dupes** (const **alpm\_list\_t** \*list)\
 Create a new list without any duplicates.  **alpm\_list\_t** \* **alpm\_list\_strdup** (const **alpm\_list\_t** \*list)\
 Copy a string list, including data.  **alpm\_list\_t** \* **alpm\_list\_copy** (const **alpm\_list\_t** \*list)\
 Copy a list, without copying data.  **alpm\_list\_t** \* **alpm\_list\_copy\_data** (const **alpm\_list\_t** \*list, size\_t size)\
 Copy a list and copy the data.  **alpm\_list\_t** \* **alpm\_list\_reverse** (**alpm\_list\_t** \*list)\
 Create a new list in reverse order.  **alpm\_list\_t** \* **alpm\_list\_nth** (const **alpm\_list\_t** \*list, size\_t n)\
 Return nth element from list (starting from 0).  **alpm\_list\_t** \* **alpm\_list\_next** (const **alpm\_list\_t** \*list)\
 Get the next element of a list.  **alpm\_list\_t** \* **alpm\_list\_previous** (const **alpm\_list\_t** \*list)\
 Get the previous element of a list.  **alpm\_list\_t** \* **alpm\_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\_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.  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

## 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

### #define FREELIST( p)

**Value:**

```
do { alpm_list_free_inner(p, free); alpm_list_free(p); p = NULL; } while(0)
```

Frees a list and its contents.

## Typedef Documentation

### typedef int(\*) alpm\_list\_fn\_cmp(const void \*, const void \*)

item comparison callback

### typedef void(\*) alpm\_list\_fn\_free(void \*item)

item deallocation callback.

**Parameters**

*item* the item to free

## Function Documentation

### alpm\_list\_t \* alpm\_list\_add (alpm\_list\_t \* list, void \* data)

Add a new item to the end of the list.

**Parameters**

*list* the list to add to \
 *data* the new item to be added to the list

**Returns**

the resultant list

References **alpm\_list\_add()**.

Referenced by **alpm\_list\_add()**.

### 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**

*list* the list to add to \
 *data* the new item to be added to the list \
 *fn* the comparison function to use to determine order

**Returns**

the resultant list

References **alpm\_list\_add\_sorted()**.

Referenced by **alpm\_list\_add\_sorted()**.

### alpm\_list\_t \* alpm\_list\_append (alpm\_list\_t \*\* list, void \* data)

Add a new item to the end of the list.

**Parameters**

*list* the list to add to \
 *data* the new item to be added to the list

**Returns**

the newly added item

References **alpm\_list\_append()**.

Referenced by **alpm\_list\_append()**.

### alpm\_list\_t \* alpm\_list\_append\_strdup (alpm\_list\_t \*\* list, const char \* data)

Duplicate and append a string to a list.

**Parameters**

*list* the list to append to \
 *data* the string to duplicate and append

**Returns**

the newly added item

References **alpm\_list\_append\_strdup()**.

Referenced by **alpm\_list\_append\_strdup()**.

### 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**

*left* the first list \
 *right* the second list \
 *fn* the comparison function

**Returns**

1 if the lists are equal, 0 if not equal, -1 on error.

References **alpm\_list\_cmp\_unsorted()**.

Referenced by **alpm\_list\_cmp\_unsorted()**.

### alpm\_list\_t \* alpm\_list\_copy (const alpm\_list\_t \* list)

Copy a list, without copying data.

**Parameters**

*list* the list to copy

**Returns**

a copy of the original list

References **alpm\_list\_copy()**.

Referenced by **alpm\_list\_copy()**.

### 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**

*list* the list to copy \
 *size* the size of each data element

**Returns**

a copy of the original list, data copied as well

References **alpm\_list\_copy\_data()**.

Referenced by **alpm\_list\_copy\_data()**.

### size\_t alpm\_list\_count (const alpm\_list\_t \* list)

Get the number of items in a list.

**Parameters**

*list* the list

**Returns**

the number of list items

References **alpm\_list\_count()**.

Referenced by **alpm\_list\_count()**.

### 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**

*lhs* the first list \
 *rhs* the second list \
 *fn* the comparison function

**Returns**

a list containing all items in lhs not present in rhs

References **alpm\_list\_diff()**.

Referenced by **alpm\_list\_diff()**.

### 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**

*left* the first list \
 *right* the second list \
 *fn* the comparison function \
 *onlyleft* pointer to the first result list \
 *onlyright* pointer to the second result list

References **alpm\_list\_diff\_sorted()**.

Referenced by **alpm\_list\_diff\_sorted()**.

### void \* alpm\_list\_find (const alpm\_list\_t \* haystack, const void \* needle, alpm\_list\_fn\_cmp fn)

Find an item in a list.

**Parameters**

*needle* the item to search \
 *haystack* the list \
 *fn* the comparison function for searching (!= NULL)

**Returns**

needle if found, NULL otherwise

References **alpm\_list\_find()**.

Referenced by **alpm\_list\_find()**.

### 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**

*needle* the data to search for (== comparison) \
 *haystack* the list

**Returns**

needle if found, NULL otherwise

References **alpm\_list\_find\_ptr()**.

Referenced by **alpm\_list\_find\_ptr()**.

### char \* alpm\_list\_find\_str (const alpm\_list\_t \* haystack, const char \* needle)

Find a string in a list.

**Parameters**

*needle* the string to search for \
 *haystack* the list

**Returns**

needle if found, NULL otherwise

References **alpm\_list\_find\_str()**.

Referenced by **alpm\_list\_find\_str()**.

### void alpm\_list\_free (alpm\_list\_t \* list)

Free a list, but not the contained data.

**Parameters**

*list* the list to free

References **alpm\_list\_free()**.

Referenced by **alpm\_list\_free()**.

### 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**

*list* the list to free \
 *fn* a free function for the internal data

References **alpm\_list\_free\_inner()**.

Referenced by **alpm\_list\_free\_inner()**.

### 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**

*first* the first list \
 *second* the second list

**Returns**

the resultant joined list

References **alpm\_list\_join()**.

Referenced by **alpm\_list\_join()**.

### alpm\_list\_t \* alpm\_list\_last (const alpm\_list\_t \* list)

Get the last item in the list.

**Parameters**

*list* the list

**Returns**

the last element in the list

References **alpm\_list\_last()**.

Referenced by **alpm\_list\_last()**.

### 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**

*left* the first list \
 *right* the second list \
 *fn* comparison function for determining merge order

**Returns**

the resultant list

References **alpm\_list\_mmerge()**.

Referenced by **alpm\_list\_mmerge()**.

### 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**

*list* the list to sort \
 *n* the size of the list \
 *fn* the comparison function for determining order

**Returns**

the resultant list

References **alpm\_list\_msort()**.

Referenced by **alpm\_list\_msort()**.

### alpm\_list\_t \* alpm\_list\_next (const alpm\_list\_t \* list)

Get the next element of a list.

**Parameters**

*list* the list node

**Returns**

the next element, or NULL when no more elements exist

References **alpm\_list\_next()**.

Referenced by **alpm\_list\_next()**.

### alpm\_list\_t \* alpm\_list\_nth (const alpm\_list\_t \* list, size\_t n)

Return nth element from list (starting from 0).

**Parameters**

*list* the list \
 *n* the 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\_nth()**.

Referenced by **alpm\_list\_nth()**.

### alpm\_list\_t \* alpm\_list\_previous (const alpm\_list\_t \* list)

Get the previous element of a list.

**Parameters**

*list* the list head

**Returns**

the previous element, or NULL when no previous element exist

References **alpm\_list\_previous()**.

Referenced by **alpm\_list\_previous()**.

### 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**

*haystack* the list to remove the item from \
 *needle* the data member of the item we're removing \
 *fn* the comparison function for searching \
 *data* output parameter containing data of the removed item

**Returns**

the resultant list

References **alpm\_list\_remove()**.

Referenced by **alpm\_list\_remove()**.

### 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**

*list* the list to copy

**Returns**

a new list containing non-duplicate items

References **alpm\_list\_remove\_dupes()**.

Referenced by **alpm\_list\_remove\_dupes()**.

### 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**

*haystack* the list to remove the item from \
 *item* the item to remove from the list

**Returns**

the resultant list

References **alpm\_list\_remove\_item()**.

Referenced by **alpm\_list\_remove\_item()**.

### alpm\_list\_t \* alpm\_list\_remove\_str (alpm\_list\_t \* haystack, const char \* needle, char \*\* data)

Remove a string from a list.

**Parameters**

*haystack* the list to remove the item from \
 *needle* the data member of the item we're removing \
 *data* output parameter containing data of the removed item

**Returns**

the resultant list

References **alpm\_list\_remove\_str()**.

Referenced by **alpm\_list\_remove\_str()**.

### alpm\_list\_t \* alpm\_list\_reverse (alpm\_list\_t \* list)

Create a new list in reverse order.

**Parameters**

*list* the list to copy

**Returns**

a new list in reverse order

References **alpm\_list\_reverse()**.

Referenced by **alpm\_list\_reverse()**.

### alpm\_list\_t \* alpm\_list\_strdup (const alpm\_list\_t \* list)

Copy a string list, including data.

**Parameters**

*list* the list to copy

**Returns**

a copy of the original list

References **alpm\_list\_strdup()**.

Referenced by **alpm\_list\_strdup()**.

### 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**

*list* the list to copy \
 *n* the size of the list \
 *size* the size of each data element

**Returns**

an array version of the original list, data copied as well

References **alpm\_list\_to\_array()**.

Referenced by **alpm\_list\_to\_array()**.

## Author

Generated automatically by Doxygen for libalpm from the source code.
