1CURLOPT_ERRORBUFFER(3)     curl_easy_setopt options     CURLOPT_ERRORBUFFER(3)
2
3
4

NAME

6       CURLOPT_ERRORBUFFER - error buffer for error messages
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLcode curl_easy_setopt(CURL *handle, CURLOPT_ERRORBUFFER, char *buf);
12

DESCRIPTION

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

DEFAULT

34       NULL
35

PROTOCOLS

37       All
38

EXAMPLE

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

AVAILABILITY

72       Always
73

RETURN VALUE

75       Returns CURLE_OK
76

SEE ALSO

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 7.85.0                   May 17, 2022           CURLOPT_ERRORBUFFER(3)
Impressum