• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_slist_append
5Section: 3
6Source: libcurl
7See-also:
8  - curl_slist_free_all (3)
9---
10
11# NAME
12
13curl_slist_append - add a string to an slist
14
15# SYNOPSIS
16
17~~~c
18#include <curl/curl.h>
19
20struct curl_slist *curl_slist_append(struct curl_slist *list,
21                                     const char *string);
22~~~
23
24# DESCRIPTION
25
26curl_slist_append(3) appends a string to a linked list of strings. The
27existing **list** should be passed as the first argument and the new list is
28returned from this function. Pass in NULL in the **list** argument to create
29a new list. The specified **string** has been appended when this function
30returns. curl_slist_append(3) copies the string.
31
32The list should be freed again (after usage) with
33curl_slist_free_all(3).
34
35# EXAMPLE
36
37~~~c
38int main(void)
39{
40  CURL *handle;
41  struct curl_slist *slist = NULL;
42  struct curl_slist *temp = NULL;
43
44  slist = curl_slist_append(slist, "pragma:");
45
46  if(!slist)
47    return -1;
48
49  temp = curl_slist_append(slist, "Accept:");
50
51  if(!temp) {
52    curl_slist_free_all(slist);
53    return -1;
54  }
55
56  slist = temp;
57
58  curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);
59
60  curl_easy_perform(handle);
61
62  curl_slist_free_all(slist); /* free the list again */
63}
64~~~
65
66# AVAILABILITY
67
68Always
69
70# RETURN VALUE
71
72A null pointer is returned if anything went wrong, otherwise the new list
73pointer is returned. To avoid overwriting an existing non-empty list on
74failure, the new list should be returned to a temporary variable which can
75be tested for NULL before updating the original list pointer.
76