1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2015, 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.haxx.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 ***************************************************************************/
22
23 #include "tool_setup.h"
24
25 #ifndef CURL_DISABLE_LIBCURL_OPTION
26
27 #include "slist_wc.h"
28
29 /* The last #include files should be: */
30 #include "memdebug.h"
31
32 /*
33 * slist_wc_append() appends a string to the linked list. This function can be
34 * used as an initialization function as well as an append function.
35 */
slist_wc_append(struct slist_wc * list,const char * data)36 struct slist_wc *slist_wc_append(struct slist_wc *list,
37 const char *data)
38 {
39 struct curl_slist *new_item = curl_slist_append(NULL, data);
40
41 if(!new_item)
42 return NULL;
43
44 if(!list) {
45 list = malloc(sizeof(struct slist_wc));
46
47 if(!list) {
48 curl_slist_free_all(new_item);
49 return NULL;
50 }
51
52 list->first = new_item;
53 list->last = new_item;
54 return list;
55 }
56
57 list->last->next = new_item;
58 list->last = list->last->next;
59 return list;
60 }
61
62 /* be nice and clean up resources */
slist_wc_free_all(struct slist_wc * list)63 void slist_wc_free_all(struct slist_wc *list)
64 {
65 if(!list)
66 return;
67
68 curl_slist_free_all(list->first);
69 free(list);
70 }
71
72 #endif /* CURL_DISABLE_LIBCURL_OPTION */
73