xref: /curl/src/slist_wc.c (revision 2bc1d775)
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at https://curl.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  * SPDX-License-Identifier: curl
22  *
23  ***************************************************************************/
24 
25 #include "tool_setup.h"
26 
27 #ifndef CURL_DISABLE_LIBCURL_OPTION
28 
29 #include "slist_wc.h"
30 
31 /* The last #include files should be: */
32 #include "memdebug.h"
33 
34 /*
35  * slist_wc_append() appends a string to the linked list. This function can be
36  * used as an initialization function as well as an append function.
37  */
slist_wc_append(struct slist_wc * list,const char * data)38 struct slist_wc *slist_wc_append(struct slist_wc *list,
39                                  const char *data)
40 {
41   struct curl_slist *new_item = curl_slist_append(NULL, data);
42 
43   if(!new_item)
44     return NULL;
45 
46   if(!list) {
47     list = malloc(sizeof(struct slist_wc));
48 
49     if(!list) {
50       curl_slist_free_all(new_item);
51       return NULL;
52     }
53 
54     list->first = new_item;
55     list->last = new_item;
56     return list;
57   }
58 
59   list->last->next = new_item;
60   list->last = list->last->next;
61   return list;
62 }
63 
64 /* be nice and clean up resources */
slist_wc_free_all(struct slist_wc * list)65 void slist_wc_free_all(struct slist_wc *list)
66 {
67   if(!list)
68     return;
69 
70   curl_slist_free_all(list->first);
71   free(list);
72 }
73 
74 #endif /* CURL_DISABLE_LIBCURL_OPTION */
75