quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

curl_slist_append.md (1705B)


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