curl_slist_append.3 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2022, 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. .TH curl_slist_append 3 "19 Jun 2003" "libcurl 7.10.4" "libcurl Manual"
  25. .SH NAME
  26. curl_slist_append - add a string to an slist
  27. .SH SYNOPSIS
  28. .nf
  29. #include <curl/curl.h>
  30. struct curl_slist *curl_slist_append(struct curl_slist *list,
  31. const char *string);
  32. .fi
  33. .SH DESCRIPTION
  34. \fIcurl_slist_append(3)\fP appends a string to a linked list of strings. The
  35. existing \fBlist\fP should be passed as the first argument and the new list is
  36. returned from this function. Pass in NULL in the \fBlist\fP argument to create
  37. a new list. The specified \fBstring\fP has been appended when this function
  38. returns. \fIcurl_slist_append(3)\fP copies the string.
  39. The list should be freed again (after usage) with
  40. \fIcurl_slist_free_all(3)\fP.
  41. .SH EXAMPLE
  42. .nf
  43. CURL *handle;
  44. struct curl_slist *slist=NULL;
  45. struct curl_slist *temp=NULL;
  46. slist = curl_slist_append(slist, "pragma:");
  47. if (slist == NULL)
  48. return -1;
  49. temp = curl_slist_append(slist, "Accept:")
  50. if (temp == NULL) {
  51. curl_slist_free_all(slist);
  52. return -1;
  53. }
  54. slist = temp;
  55. curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);
  56. curl_easy_perform(handle);
  57. curl_slist_free_all(slist); /* free the list again */
  58. .fi
  59. .SH AVAILABILITY
  60. Always
  61. .SH RETURN VALUE
  62. A null pointer is returned if anything went wrong, otherwise the new list
  63. pointer is returned. To avoid overwriting an existing non-empty list on
  64. failure, the new list should be returned to a temporary variable which can
  65. be tested for NULL before updating the original list pointer.
  66. .SH "SEE ALSO"
  67. .BR curl_slist_free_all "(3), "