2
0

CURLOPT_ERRORBUFFER.3 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2020, 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. .\" **************************************************************************
  22. .\"
  23. .TH CURLOPT_ERRORBUFFER 3 "17 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options"
  24. .SH NAME
  25. CURLOPT_ERRORBUFFER \- set error buffer for error messages
  26. .SH SYNOPSIS
  27. #include <curl/curl.h>
  28. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_ERRORBUFFER, char *buf);
  29. .SH DESCRIPTION
  30. Pass a char * to a buffer that libcurl \fBmay\fP store human readable error
  31. messages on failures or problems. This may be more helpful than just the
  32. return code from \fIcurl_easy_perform(3)\fP and related functions. The buffer
  33. \fBmust be at least CURL_ERROR_SIZE bytes big\fP.
  34. You must keep the associated buffer available until libcurl no longer needs
  35. it. Failing to do so will cause very odd behavior or even crashes. libcurl
  36. will need it until you call \fIcurl_easy_cleanup(3)\fP or you set the same
  37. option again to use a different pointer.
  38. Do not rely on the contents of the buffer unless an error code was returned.
  39. Since 7.60.0 libcurl will initialize the contents of the error buffer to an
  40. empty string before performing the transfer. For earlier versions if an error
  41. code was returned but there was no error detail then the buffer is untouched.
  42. Consider \fICURLOPT_VERBOSE(3)\fP and \fICURLOPT_DEBUGFUNCTION(3)\fP to better
  43. debug and trace why errors happen.
  44. .SH DEFAULT
  45. NULL
  46. .SH PROTOCOLS
  47. All
  48. .SH EXAMPLE
  49. .nf
  50. curl = curl_easy_init();
  51. if(curl) {
  52. CURLcode res;
  53. char errbuf[CURL_ERROR_SIZE];
  54. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  55. /* provide a buffer to store errors in */
  56. curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
  57. /* set the error buffer as empty before performing a request */
  58. errbuf[0] = 0;
  59. /* perform the request */
  60. res = curl_easy_perform(curl);
  61. /* if the request did not complete correctly, show the error
  62. information. if no detailed error information was written to errbuf
  63. show the more generic information from curl_easy_strerror instead.
  64. */
  65. if(res != CURLE_OK) {
  66. size_t len = strlen(errbuf);
  67. fprintf(stderr, "\\nlibcurl: (%d) ", res);
  68. if(len)
  69. fprintf(stderr, "%s%s", errbuf,
  70. ((errbuf[len - 1] != '\\n') ? "\\n" : ""));
  71. else
  72. fprintf(stderr, "%s\\n", curl_easy_strerror(res));
  73. }
  74. }
  75. .fi
  76. .SH AVAILABILITY
  77. Always
  78. .SH RETURN VALUE
  79. Returns CURLE_OK
  80. .SH "SEE ALSO"
  81. .BR CURLOPT_DEBUGFUNCTION "(3), " CURLOPT_VERBOSE "(3), "
  82. .BR curl_easy_strerror "(3), " curl_multi_strerror "(3), "
  83. .BR curl_share_strerror "(3) "