1CURLOPT_ERRORBUFFER(3) curl_easy_setopt options CURLOPT_ERRORBUFFER(3)
2
3
4
6 CURLOPT_ERRORBUFFER - error buffer for error messages
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_ERRORBUFFER, char *buf);
12
14 Pass a char * to a buffer that libcurl may store human readable error
15 messages on failures or problems. This may be more helpful than just
16 the return code from curl_easy_perform(3) and related functions. The
17 buffer must be at least CURL_ERROR_SIZE bytes big.
18
19 You must keep the associated buffer available until libcurl no longer
20 needs it. Failing to do so will cause odd behavior or even crashes.
21 libcurl will need it until you call curl_easy_cleanup(3) or you set the
22 same option again to use a different pointer.
23
24 Do not rely on the contents of the buffer unless an error code was re‐
25 turned. Since 7.60.0 libcurl will initialize the contents of the error
26 buffer to an empty string before performing the transfer. For earlier
27 versions if an error code was returned but there was no error detail
28 then the buffer is untouched.
29
30 Consider CURLOPT_VERBOSE(3) and CURLOPT_DEBUGFUNCTION(3) to better de‐
31 bug and trace why errors happen.
32
34 NULL
35
37 All
38
40 curl = curl_easy_init();
41 if(curl) {
42 CURLcode res;
43 char errbuf[CURL_ERROR_SIZE];
44
45 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
46
47 /* provide a buffer to store errors in */
48 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
49
50 /* set the error buffer as empty before performing a request */
51 errbuf[0] = 0;
52
53 /* perform the request */
54 res = curl_easy_perform(curl);
55
56 /* if the request did not complete correctly, show the error
57 information. if no detailed error information was written to errbuf
58 show the more generic information from curl_easy_strerror instead.
59 */
60 if(res != CURLE_OK) {
61 size_t len = strlen(errbuf);
62 fprintf(stderr, "\nlibcurl: (%d) ", res);
63 if(len)
64 fprintf(stderr, "%s%s", errbuf,
65 ((errbuf[len - 1] != '\n') ? "\n" : ""));
66 else
67 fprintf(stderr, "%s\n", curl_easy_strerror(res));
68 }
69 }
70
72 Always
73
75 Returns CURLE_OK
76
78 CURLOPT_DEBUGFUNCTION(3), CURLOPT_VERBOSE(3), curl_easy_strerror(3),
79 curl_multi_strerror(3), curl_share_strerror(3), curl_url_strerror(3)
80
81
82
83libcurl 8.0.1 January 02, 2023 CURLOPT_ERRORBUFFER(3)