diff options
author | Alessandro Ghedini <alessandro@ghedini.me> | 2015-08-12 10:34:59 +0200 |
---|---|---|
committer | Alessandro Ghedini <alessandro@ghedini.me> | 2015-08-12 10:34:59 +0200 |
commit | 9456f51adb76b83ceb4b95c8481325de62b25ad2 (patch) | |
tree | e5cfc1f4bc28cd81e93a96f9707a0efb143d278a /docs/libcurl/opts/CURLOPT_ERRORBUFFER.html | |
parent | dbada9f3efae6d9d47b24d0fc06b31d5c48e59a9 (diff) |
Imported Upstream version 7.44.0
Diffstat (limited to 'docs/libcurl/opts/CURLOPT_ERRORBUFFER.html')
-rw-r--r-- | docs/libcurl/opts/CURLOPT_ERRORBUFFER.html | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/docs/libcurl/opts/CURLOPT_ERRORBUFFER.html b/docs/libcurl/opts/CURLOPT_ERRORBUFFER.html index 7d45d29f..519891a7 100644 --- a/docs/libcurl/opts/CURLOPT_ERRORBUFFER.html +++ b/docs/libcurl/opts/CURLOPT_ERRORBUFFER.html @@ -63,15 +63,33 @@ p.roffit { <p class="level0"><pre class="level0"> curl = curl_easy_init(); if(curl) { - char error[CURL_ERROR_SIZE] + CURLcode res; + char errbuf[CURL_ERROR_SIZE]; curl_easy_setopt(curl, CURLOPT_URL, "<a href="http://example.com">http://example.com</a>"); /* provide a buffer to store errors in */ - curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); - /* Perform the request */ - curl_easy_perform(curl); + /* set the error buffer as empty before performing a request */ + errbuf[0] = 0; + + /* perform the request */ + res = curl_easy_perform(curl); + + /* if the request did not complete correctly, show the error + information. if no detailed error information was written to errbuf + show the more generic information from curl_easy_strerror instead. + */ + if(res != CURLE_OK) { + size_t len = strlen(errbuf); + fprintf(stderr, "\nlibcurl: (%d) ", res); + if(len) + fprintf(stderr, "%s%s", errbuf, + ((errbuf[len - 1] != '\n') ? "\n" : "")); + else + fprintf(stderr, "%s\n", curl_easy_strerror(res)); + } } </pre> |