cURL / Mailing Lists / curl-library / Single Mail

curl-library

return value check needed for curl_easy_setopt and curl_slist_append

From: Shivanand <centrio_at_gmail.com>
Date: Sat, 21 Mar 2009 17:25:43 +0530

Hi,
I am using libcurl for getting web response from HTTP URLs. I am using
curl_easy_setopt and curl_slist_append APIs.

Libcurl documentation specifies that curl_easy_setopt APIs returns CURLE_OK
if it is successful else returns a non zero value.

I would like to know if really this API can fail? Under what circumstances
it can fail?
Is the return value needs to be checked for these APIs. SInce my code has
20-30 set-opts and the code becomes lengthy.
If i ensure the curlHandle is valid before Using these APIs, is it possible
to avoid return value check

status = curl_easy_setopt(curlHandle, CURLOPT_FOLLOWLOCATION, 1);

if (CURLE_OK != status)

{

throw RuntimeExcpetion("curl_easy_setopt() could not set
CURLOPT_FOLLOWLOCATION");

}

Same problem is with curl_slist_append. Do i need to check the pointer
returned by this API? I have many places at which this APIs is used.

requestHeaders = curl_slist_append(requestHeaders,"Accept: */*");

if (0 == requestHeaders)

{

throw RuntimeException("curl_slist_append() could not set Accept");

}
Received on 2009-03-21