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

NAME

6       CURLOPT_ERRORBUFFER - set error buffer for error messages
7

SYNOPSIS

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

DESCRIPTION

15       Pass a char * to a buffer that libcurl may store human  readable  error
16       messages  on  failures  or problems. This may be more helpful than just
17       the return code from curl_easy_perform(3) and  related  functions.  The
18       buffer must be at least CURL_ERROR_SIZE bytes big.
19
20       You  must  keep the associated buffer available until libcurl no longer
21       needs it. Failing to do  so  will  cause  very  odd  behavior  or  even
22       crashes.  libcurl  will  need it until you call curl_easy_cleanup(3) or
23       you set the same option again to use a different pointer.
24
25       Do not rely on the contents of the buffer  unless  an  error  code  was
26       returned.   Since  7.60.0  libcurl  will initialize the contents of the
27       error buffer to an empty string before  performing  the  transfer.  For
28       earlier  versions  if an error code was returned but there was no error
29       detail then the buffer is untouched.
30
31       Consider  CURLOPT_VERBOSE(3)  and  CURLOPT_DEBUGFUNCTION(3)  to  better
32       debug and trace why errors happen.
33

DEFAULT

35       NULL
36

PROTOCOLS

38       All
39

EXAMPLE

41       curl = curl_easy_init();
42       if(curl) {
43         CURLcode res;
44         char errbuf[CURL_ERROR_SIZE];
45
46         curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
47
48         /* provide a buffer to store errors in */
49         curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
50
51         /* set the error buffer as empty before performing a request */
52         errbuf[0] = 0;
53
54         /* perform the request */
55         res = curl_easy_perform(curl);
56
57         /* if the request did not complete correctly, show the error
58         information. if no detailed error information was written to errbuf
59         show the more generic information from curl_easy_strerror instead.
60         */
61         if(res != CURLE_OK) {
62           size_t len = strlen(errbuf);
63           fprintf(stderr, "\nlibcurl: (%d) ", res);
64           if(len)
65             fprintf(stderr, "%s%s", errbuf,
66                     ((errbuf[len - 1] != '\n') ? "\n" : ""));
67           else
68             fprintf(stderr, "%s\n", curl_easy_strerror(res));
69         }
70       }
71

AVAILABILITY

73       Always
74

RETURN VALUE

76       Returns CURLE_OK
77

SEE ALSO

79       CURLOPT_DEBUGFUNCTION(3),   CURLOPT_VERBOSE(3),  curl_easy_strerror(3),
80       curl_multi_strerror(3), curl_share_strerror(3)
81
82
83
84libcurl 7.64.0                  March 13, 2018          CURLOPT_ERRORBUFFER(3)
Impressum