gnurl_slist_append(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

gnurl_slist_append(3) πŸŽ€

okay so this page is from the libgnurl Manual, and it's giving β€œtiny helper, huge slay” energy. No cap, bestie: it's all about adding a string to an slist. Let's go. ✨

🌸 NAME 🌸

curl_slist_append β€” add a string to an slist

✨ SYNOPSIS ✨

copy-paste this exactly, okay? 🫢

#include <gnurl/curl.h>

struct curl_slist *curl_slist_append(struct curl_slist *list, const char
* string);

πŸ’… DESCRIPTION πŸ’…

okay so curl_slist_append(3) appends a string to a linked list of strings. The existing list should be passed as the first argument, and the new list is returned from this function. Pass in NULL in the list argument to create a new list. The specified string has been appended when this function returns. curl_slist_append(3) copies the string. iconic. πŸ¦‹

The list should be freed again (after usage) with curl_slist_free_all(3). don't forget, bestie β€” that's the cleanup era. 🧹

πŸ”₯ RETURN VALUE πŸ”₯

A null pointer is returned if anything went wrong, otherwise the new list pointer is returned. red flag alert: to avoid overwriting an existing non-empty list on failure, the new list should be returned to a temporary variable which can be tested for NULL before updating the original list pointer. literally protect the original list at all costs. 😭

🧚 EXAMPLE 🧚

here's the example. keep the code exactly as it is β€” yes, every line. πŸ’–

CURL *handle;
struct curl_slist *slist=NULL;
struct curl_slist *temp=NULL;

slist = curl_slist_append(slist, "pragma:");

if (slist == NULL)
  return -1;

temp = curl_slist_append(slist, "Accept:")

if (temp == NULL) {
  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 */

🌈 SEE ALSO 🌈

that's the whole SEE ALSO, periodt. πŸ‘‘


mwah πŸ’‹ β€” signed off from libcurl 7.10.4, dated 19 Jun 2003, and filed under gnurl_slist_append(3). periodt. πŸ‘‘

πŸ“¦ where this page comes from