---
name: "libwget-list"
section: "3"
platform: "linux"
package: "wget2-dev"
version: "2.2.0+ds-1+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/libwget-list"
---

# libwget-list(3)

Circular doubly linked list

## NAME

libwget-list - Circular doubly linked list

## SYNOPSIS

### Data Structures

struct **wget\_list\_st**\

### Typedefs

typedef struct **wget\_list\_st** **wget\_list**\

### Functions

void \* **wget\_list\_append** (**wget\_list** \*\*list, const void \*data, size\_t size)\
 void \* **wget\_list\_prepend** (**wget\_list** \*\*list, const void \*data, size\_t size)\
 void **wget\_list\_remove** (**wget\_list** \*\*list, void \*elem)\
 void \* **wget\_list\_getfirst** (const **wget\_list** \*list)\
 void \* **wget\_list\_getlast** (const **wget\_list** \*list)\
 void \* **wget\_list\_getnext** (const void \*elem)\
 int **wget\_list\_browse** (const **wget\_list** \*list, wget\_list\_browse\_fn \*browse, void \*context)\
 void **wget\_list\_free** (**wget\_list** \*\*list)\

## Detailed Description

Circular doubly linked lists provide fast insertion, removal and iteration in either direction.

Each element has pointers to the next and the previous element.\
\
  Iteration can be done by calling the **wget\_list\_browse()** function, so the list structure doesn't need to be exposed.

This datatype is used by the Wget2 tool to implement the job queue (append and remove).

See **wget\_list\_append()** for an example on how to use lists.

## Typedef Documentation

### typedef struct wget\_list\_st wget\_list

Type for double linked lists and list entries.

## Function Documentation

### void \* wget\_list\_append (wget\_list \*\* list, const void \* data, size\_t size)

**Parameters**

*list* Pointer to Pointer to a circular doubly linked list \
 *data* Pointer to data to be inserted \
 *size* Size of data in bytes

**Returns**

Pointer to the new element or NULL if memory allocation failed

Append an element to the end of the list.\
\
  `size` bytes at `data` will be copied and appended to the list.

A pointer to the new element will be returned.

**Note**

The returned pointer must be freed by **wget\_list\_remove()** or implicitly by **wget\_list\_free()**.

Example:

```
wget_list *list = NULL;
struct mystruct mydata1 = { .x = 1, .y = 25 };
struct mystruct mydata2 = { .x = 5, .y = 99 };
struct mystruct *data;
wget_list_append(&list, &mydata1, sizeof(mydata1)); // append mydata1 to list
wget_list_append(&list, &mydata2, sizeof(mydata2)); // append mydata2 to list
data = wget_list_getfirst(list);
printf("data=(%d,%d)\n", data->x, data->y); // prints 'data=(1,25)'
wget_list_remove(&list, data);
data = wget_list_getfirst(list);
printf("data=(%d,%d)\n", data->x, data->y); // prints 'data=(5,99)'
wget_list_free(&list);
```

### void \* wget\_list\_prepend (wget\_list \*\* list, const void \* data, size\_t size)

**Parameters**

*list* Pointer to Pointer to a circular doubly linked list \
 *data* Pointer to data to be inserted \
 *size* Size of data in bytes

**Returns**

Pointer to the new element or NULL if memory allocation failed

Insert an entry at the beginning of the list. `size` bytes at `data` will be copied and prepended to the list.

A pointer to the new element will be returned. It must be freed by **wget\_list\_remove()** or implicitly by **wget\_list\_free()**.

### void wget\_list\_remove (wget\_list \*\* list, void \* elem)

**Parameters**

*list* Pointer to Pointer to a circular doubly linked list \
 *elem* Pointer to a list element returned by **wget\_list\_append()** or **wget\_list\_prepend()**

Remove an element from the list.

### void \* wget\_list\_getfirst (const wget\_list \* list)

**Parameters**

*list* Pointer to a circular doubly linked list

**Returns**

Pointer to the first element of the list or NULL if the list is empty

Get the first element of a list.

### void \* wget\_list\_getlast (const wget\_list \* list)

**Parameters**

*list* Pointer to a circular doubly linked list

**Returns**

Pointer to the last element of the list or NULL if the list is empty

Get the last element of a list.

### void \* wget\_list\_getnext (const void \* elem)

**Parameters**

*elem* Pointer to an element of a linked list

**Returns**

Pointer to the next element of the list or NULL if the list is empty

Get the next element of a list.

### int wget\_list\_browse (const wget\_list \* list, wget\_list\_browse\_fn \* browse, void \* context)

**Parameters**

*list* Pointer to a circular doubly linked list \
 *browse* Pointer to callback function which is called for every element in the list. If the callback functions returns a value not equal to zero, browsing is stopped and this value will be returned by wget\_list\_browse. \
 *context* The context handle that will be passed to the callback function

**Returns**

The return value of the last call to the browse function or -1 if `list` is NULL (empty)

Iterate through all entries of the `list` and call the function `browse` for each.

```
// assume that list contains C strings.
wget_list *list = NULL;
static int print_elem(void *context, const char *elem)
{
   printf("%s\n",elem);
   return 0;
}
void dump(WGET_LIST *list)
{
   wget_list_browse(list, (wget_list_browse_t)print_elem, NULL);
}
```

### void wget\_list\_free (wget\_list \*\* list)

**Parameters**

*list* Pointer to Pointer to a circular doubly linked list

Freeing the list and it's entry.

## Author

Generated automatically by Doxygen for wget2 from the source code.
