slist_wc.c 2.0 KB

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