1curl_slist_append(3) libcurl Manual curl_slist_append(3)
2
3
4
6 curl_slist_append - add a string to an slist
7
9 #include <curl/curl.h>
10
11 struct curl_slist *curl_slist_append(struct curl_slist *list, const
12 char * string);
13
15 curl_slist_append(3) appends a string to a linked list of strings. The
16 existing list should be passed as the first argument and the new list
17 is returned from this function. Pass in NULL in the list argument to
18 create a new list. The specified string has been appended when this
19 function returns. curl_slist_append(3) copies the string.
20
21 The list should be freed again (after usage) with
22 curl_slist_free_all(3).
23
25 A null pointer is returned if anything went wrong, otherwise the new
26 list pointer is returned. To avoid overwriting an existing non-empty
27 list on failure, the new list should be returned to a temporary vari‐
28 able which can be tested for NULL before updating the original list
29 pointer.
30
32 CURL *handle;
33 struct curl_slist *slist=NULL;
34 struct curl_slist *temp=NULL;
35
36 slist = curl_slist_append(slist, "pragma:");
37
38 if (slist == NULL)
39 return -1;
40
41 temp = curl_slist_append(slist, "Accept:")
42
43 if (temp == NULL) {
44 curl_slist_free_all(slist);
45 return -1;
46 }
47
48 slist = temp;
49
50 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);
51
52 curl_easy_perform(handle);
53
54 curl_slist_free_all(slist); /* free the list again */
55
57 curl_slist_free_all(3),
58
59
60
61libcurl 7.79.1 November 05, 2020 curl_slist_append(3)