curl_slist_append(3)
π curl_slist_append(3) β the libcurl glow-up for your string list π
okay so bestie, we're in the libcurl manual, section 3 (that's the library functions girlies β¨), and today's main character is curl_slist_append. she's lowkey the icon who just adds a string to your slist. periodt.
πΈ NAME πΈ
curl_slist_append β add a string to an slist π
π¦ SYNOPSIS π¦
#include <curl/curl.h>
struct curl_slist *curl_slist_append(struct curl_slist *list,
const char *string);
β¨ DESCRIPTION β¨
okay so curl_slist_append(3) is literally out here appending a string to a linked list of strings. that's the whole vibe. π
you pass the existing list in as the first argument, and this function hands you back the new list. wanna create a brand new list? just pass in NULL in the list argument, easy. by the time this function returns, your specified string has been appended β she ate and left no crumbs. π₯
also important: curl_slist_append(3) copies the string. so it's not out here borrowing your pointer, it makes its own copy, no cap. but the string argument must be a valid string pointer and absolutely cannot be NULL β that's a hard no, bestie. π«
once you're done using it, the list should be freed with curl_slist_free_all(3). and listen β its nodes and the content they point to may not be altered outside this function. hands off, she's not yours anymore. π
π PROTOCOLS π
this functionality affects all supported protocols. all of them. every single one. we love a queen with range. π
π EXAMPLE π
int main(void)
{
CURL *handle = curl_easy_init();
struct curl_slist *slist = NULL;
struct curl_slist *temp = NULL;
slist = curl_slist_append(slist, "pragma:");
if(!slist)
return -1;
temp = curl_slist_append(slist, "Accept:");
if(!temp) {
curl_slist_free_all(slist);
return -1;
}
slist = temp;
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);
curl_easy_perform(handle);
curl_slist_free_all(slist); /* free the list again */
}
like look at her go β she's appending "pragma:", checking for NULL like a responsible icon, then grabbing "Accept:" through a temp variable (iykyk, more on that down in return value π), setting CURLOPT_HTTPHEADER, performing, and then freeing the list again at the end because she cleans up after herself. we stan. π
π§ AVAILABILITY π§
added in curl 7.1 β an og, fr fr. β
π RETURN VALUE π
if anything went wrong, you get a null pointer back. otherwise? the new list pointer, slay. π
β οΈ important bestie warning: to avoid overwriting an existing non-empty list on failure, the new list should be returned to a temporary variable which you can test forNULLbefore updating the original list pointer. that's literally whattempwas doing in the example above β she's not just cute, she's protecting your data. ππ«Ά
π SEE ALSO π
curl_slist_free_all(3)β the one who cleans up. the responsible bestie. π§Ή
π and that's the tea! written for the libcurl girlies, dated 2026-10-12, version info courtesy of libcurl itself. go forth and append responsibly, mwah πβ¨π¦
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms