Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get and compare libcurl version?

Tags:

c

version

libcurl

I am using libcurl setting OAuth 2.0 access token. Since libcurl 7.33 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_XOAUTH2_BEARER, char *token); option was added. Now I need to get the libcurl version and compare it with 7.33. In case where version is 7.33 or higher I will use CURLOPT_XOAUTH2_BEARER otherwise I will do something else. I know I should somehow use curl_version_info_data *curl_version_info( CURLversion type ); but I have no idea, how the data in struct look like and how to compare them to 7.33 version. Can someone help me?

like image 627
user3737648 Avatar asked Oct 24 '25 04:10

user3737648


1 Answers

If you want to detect version at run-time, you can use curl_version_info() in a style like this:

curl_version_info_data *d = curl_version_info(CURLVERSION_NOW);

/* compare with the 24 bit hex number in 8 bit fields */
if(d->version_num >= 0x072100) {
  /* this is libcurl 7.33.0 or later */
  printf("Succcess\n");
}
else {
  printf("A too old version\n");
}

If you prefer to do the detection build-time, you can use a preprocessor #if expression like this:

#include <curl/curl.h>
#if LIBCURL_VERSION_NUM >= 0x072100
 /* this is 7.33.0 or later */
#else
 /* work-around for older libcurls */
#endif
like image 140
Daniel Stenberg Avatar answered Oct 26 '25 20:10

Daniel Stenberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!