CURLOPT_ERRORBUFFER.3 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. .\" generated by cd2nroff 0.1 from CURLOPT_ERRORBUFFER.md
  2. .TH CURLOPT_ERRORBUFFER 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_ERRORBUFFER \- error buffer for error messages
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_ERRORBUFFER, char *buf);
  9. .fi
  10. .SH DESCRIPTION
  11. Pass a char pointer to a buffer that libcurl may use to store human readable
  12. error messages on failures or problems. This may be more helpful than just the
  13. return code from \fIcurl_easy_perform(3)\fP and related functions. The buffer must
  14. be at least \fBCURL_ERROR_SIZE\fP bytes big.
  15. You must keep the associated buffer available until libcurl no longer needs
  16. it. Failing to do so might cause odd behavior or even crashes. libcurl might
  17. need it until you call \fIcurl_easy_cleanup(3)\fP or you set the same option
  18. again to use a different pointer.
  19. Do not rely on the contents of the buffer unless an error code was returned.
  20. Since 7.60.0 libcurl initializes the contents of the error buffer to an empty
  21. string before performing the transfer. For earlier versions if an error code
  22. was returned but there was no error detail then the buffer was untouched.
  23. Consider \fICURLOPT_VERBOSE(3)\fP and \fICURLOPT_DEBUGFUNCTION(3)\fP to better
  24. debug and trace why errors happen.
  25. .SH DEFAULT
  26. NULL
  27. .SH PROTOCOLS
  28. This functionality affects all supported protocols
  29. .SH EXAMPLE
  30. .nf
  31. #include <string.h> /* for strlen() */
  32. int main(void)
  33. {
  34. CURL *curl = curl_easy_init();
  35. if(curl) {
  36. CURLcode res;
  37. char errbuf[CURL_ERROR_SIZE];
  38. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  39. /* provide a buffer to store errors in */
  40. curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
  41. /* set the error buffer as empty before performing a request */
  42. errbuf[0] = 0;
  43. /* perform the request */
  44. res = curl_easy_perform(curl);
  45. /* if the request did not complete correctly, show the error
  46. information. if no detailed error information was written to errbuf
  47. show the more generic information from curl_easy_strerror instead.
  48. */
  49. if(res != CURLE_OK) {
  50. size_t len = strlen(errbuf);
  51. fprintf(stderr, "\\nlibcurl: (%d) ", res);
  52. if(len)
  53. fprintf(stderr, "%s%s", errbuf,
  54. ((errbuf[len - 1] != '\\n') ? "\\n" : ""));
  55. else
  56. fprintf(stderr, "%s\\n", curl_easy_strerror(res));
  57. }
  58. }
  59. }
  60. .fi
  61. .SH AVAILABILITY
  62. Added in curl 7.1
  63. .SH RETURN VALUE
  64. Returns CURLE_OK
  65. .SH SEE ALSO
  66. .BR CURLOPT_DEBUGFUNCTION (3),
  67. .BR CURLOPT_VERBOSE (3),
  68. .BR curl_easy_strerror (3),
  69. .BR curl_multi_strerror (3),
  70. .BR curl_share_strerror (3),
  71. .BR curl_url_strerror (3)