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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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
回答2:
As Daniel said, or even just:
#ifdef CURLOPT_XOAUTH2_BEARER
/* This version supports this option */
#else
/* No, it doesn't */
#endif