slist_wc.c 2.0 KB

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