diff options
-rw-r--r-- | dynotify.c | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -1,5 +1,5 @@ // curl: -// man curl_easy_init CURLOPT_URL curl_easy_setopt CURLOPT_WRITEFUNCTION +// man curl_easy_init CURLOPT_URL curl_easy_setopt CURLOPT_WRITEFUNCTION libcurl-errors curl_easy_strerror // https://curl.se/libcurl/ // https://curl.se/libcurl/c/ // https://curl.se/libcurl/c/libcurl-tutorial.html @@ -79,8 +79,8 @@ static size_t cb(char *data, size_t size, size_t nmemb, void *clientp) int main (void) { - // https://curl.se/libcurl/c/libcurl-errors.html - //CURLcode res; + // man libcurl-errors + CURLcode res; // `man curl_easy_init`: "It is encouraged to reuse easy handles for repeated transfers.", so I choose to reuse it CURL *curl = curl_easy_init(); NotifyNotification *n; @@ -100,8 +100,14 @@ int main (void) curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cb); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); - //res = curl_easy_perform(curl); - curl_easy_perform(curl); + res = curl_easy_perform(curl); + // man curl_easy_strerror + if(res != CURLE_OK) + { + fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); + free(chunk.response); + break; + } //printf("%s\n",chunk.response); json_object *root; |