libwget-list(3)
π libwget-list π β ok so this is the libwget-list(3) manual, bestie
hi hi hiiii π you're looking at the libwget-list(3) page from the Library Functions Manual, and honestly? it's giving "data structure that ate and left no crumbs". it's all about the circular doubly linked list in libwget. grab a snack, we're going in. π¦
β¨ 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 π
so circular doubly linked lists provide fast insertion, removal and iteration in either direction. like, both ways. bi panic but make it pointers. π
every element has pointers to the next and the previous element. you can do your iteration by calling the wget_list_browse() function, so the list structure doesn't need to be exposed β she's mysterious, she's private, we respect her privacy. π
this datatype is used by the Wget2 tool to implement the job queue (append and remove). iconic behaviour fr fr.
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. that's it, that's the whole vibe. periodt.
π₯ 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 listdataβ Pointer to data to be insertedsizeβ 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. she's new here and she's already handing you her number. β¨
Note β the returned pointer must be freed bywget_list_remove()or implicitly bywget_list_free(). no ghosting, ok? clean up after yourself. π§Ή
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 listdataβ Pointer to data to be insertedsizeβ 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(). yes bestie, same rules as append, the list is egalitarian. π«Ά
β void wget_list_remove (wget_list ** list, void * elem)
Parameters
listβ Pointer to Pointer to a circular doubly linked listelemβ Pointer to a list element returned bywget_list_append()orwget_list_prepend()
Remove an element from the list. bye bitch, respectfully. ππ
β 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. she's first for a reason. π
β 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. someone has to be last and it's her, no shade. πΈ
β 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. moving on, as she should. π
β int wget_list_browse (const wget_list * list, wget_list_browse_fn * browse, void * context)
Parameters
listβ Pointer to a circular doubly linked listbrowseβ 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 bywget_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. it's a little meet-and-greet for every single element, and the callback can shut the whole thing down by returning nonzero. main character energy honestly. π
// 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. all of it, gone, cleared, no lingering situationships with leaked memory. πβ¨
π AUTHOR π
Generated automatically by Doxygen for wget2 from the source code. (not a human, not a girlie, just a doc generator doing her best π«Ά)
ok that's the whole page bestie, you ate, go write some linked lists. this was wget2, Version 2.3.0, on the libwget-list(3) page β mwah, bye! πππ¦
π¦ where this page comes from
- fedora 43: wget2-devel 2.3.0-2.fc43 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND GFDL-1.3-or-later
- fedora 43: wget2-devel 2.3.0-2.fc43 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND GFDL-1.3-or-later
- fedora 44: wget2-devel 2.3.0-1.fc44
- fedora 44: wget2-devel 2.3.0-1.fc44
- fedora 44: wget2-devel 2.3.0-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND GFDL-1.3-or-later
- fedora 44: wget2-devel 2.3.0-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND GFDL-1.3-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms