CURLOPT: drop redundant long casts

Also:
- CURLOPT_HSTS_CTRL.md: sync macro definitions with `curl/curl.h`.
  Perhaps it'd be better to delete copies like this?
- keep existing casts within the documentation to make sure it applies
  to older curl versions as well.
- CURLOPT_IPRESOLVE.md: re-add a long cast to man page, for consistency
  with the above.

Closes #17791
This commit is contained in:
Viktor Szakats 2025-07-01 11:31:01 +02:00
parent fc98a630cf
commit 5debe7cb34
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
32 changed files with 43 additions and 46 deletions

View file

@ -142,7 +142,7 @@ int main(int argc, char **argv)
/* tell libcurl we can use "any" auth, which lets the lib pick one, but it
also costs one extra round-trip and possibly sending of all the PUT
data twice!!! */
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
/* set user name and password for the authentication */
curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password");

View file

@ -66,7 +66,7 @@
#include <curl/curl.h>
#define MSG_OUT g_print /* Change to "g_error" to write to stderr */
#define SHOW_VERBOSE 0 /* Set to non-zero for libcurl messages */
#define SHOW_VERBOSE 0L /* Set to non-zero for libcurl messages */
#define SHOW_PROGRESS 0 /* Set to non-zero to enable progress callback */
/* Global information, common to all connections */
@ -311,7 +311,7 @@ static void new_conn(const char *url, struct GlobalInfo *g)
curl_easy_setopt(conn->easy, CURLOPT_URL, conn->url);
curl_easy_setopt(conn->easy, CURLOPT_WRITEFUNCTION, write_cb);
curl_easy_setopt(conn->easy, CURLOPT_WRITEDATA, &conn);
curl_easy_setopt(conn->easy, CURLOPT_VERBOSE, (long)SHOW_VERBOSE);
curl_easy_setopt(conn->easy, CURLOPT_VERBOSE, SHOW_VERBOSE);
curl_easy_setopt(conn->easy, CURLOPT_ERRORBUFFER, conn->error);
curl_easy_setopt(conn->easy, CURLOPT_PRIVATE, conn);
curl_easy_setopt(conn->easy, CURLOPT_NOPROGRESS, SHOW_PROGRESS ? 0L : 1L);

View file

@ -87,7 +87,7 @@ int main(void)
struct state st = {0};
/* enable HSTS for this handle */
curl_easy_setopt(curl, CURLOPT_HSTS_CTRL, (long)CURLHSTS_ENABLE);
curl_easy_setopt(curl, CURLOPT_HSTS_CTRL, CURLHSTS_ENABLE);
/* function to call at first to populate the cache before the transfer */
curl_easy_setopt(curl, CURLOPT_HSTSREADFUNCTION, hstsread);

View file

@ -38,8 +38,7 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* Use HTTP/3 but fallback to earlier HTTP if necessary */
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION,
(long)CURL_HTTP_VERSION_3);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_3);
/* Perform the request, res gets the return code */
res = curl_easy_perform(curl);

View file

@ -57,7 +57,7 @@ int main(void)
* of using CURLUSESSL_TRY here, because if TLS upgrade fails, the
* transfer continues anyway - see the security discussion in the libcurl
* tutorial for more details. */
curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
/* If your server does not have a valid certificate, then you can disable
* part of the Transport Layer Security protection by setting the

View file

@ -56,7 +56,7 @@ int main(void)
* using CURLUSESSL_TRY here, because if TLS upgrade fails, the transfer
* continues anyway - see the security discussion in the libcurl tutorial
* for more details. */
curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
/* If your server does not have a valid certificate, then you can disable
* part of the Transport Layer Security protection by setting the

View file

@ -110,7 +110,7 @@ int main(void)
* of using CURLUSESSL_TRY here, because if TLS upgrade fails, the
* transfer continues anyway - see the security discussion in the libcurl
* tutorial for more details. */
curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
/* If your server does not have a valid certificate, then you can disable
* part of the Transport Layer Security protection by setting the

View file

@ -23,8 +23,8 @@ CURLOPT_HSTS_CTRL - control HSTS behavior
~~~c
#include <curl/curl.h>
#define CURLHSTS_ENABLE (1<<0)
#define CURLHSTS_READONLYFILE (1<<1)
#define CURLHSTS_ENABLE (long)(1<<0)
#define CURLHSTS_READONLYFILE (long)(1<<1)
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HSTS_CTRL, long bitmask);
~~~

View file

@ -105,8 +105,7 @@ int main(void)
if(curl) {
CURLcode ret;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION,
(long)CURL_HTTP_VERSION_2TLS);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS);
ret = curl_easy_perform(curl);
if(ret == CURLE_HTTP_RETURNED_ERROR) {
/* an HTTP response error problem */

View file

@ -66,7 +66,7 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
/* of all addresses example.com resolves to, only IPv6 ones are used */
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, (long)CURL_IPRESOLVE_V6);
res = curl_easy_perform(curl);

View file

@ -751,7 +751,7 @@ static CURLcode proxy_setopts(struct OperationConfig *config, CURL *curl)
/* new in libcurl 7.10.6 */
if(config->proxyanyauth)
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
else if(config->proxynegotiate)
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH, CURLAUTH_GSSNEGOTIATE);
else if(config->proxyntlm)

View file

@ -129,7 +129,7 @@ static int setup_hx_download(CURL *hnd, const char *url, struct transfer_d *t,
curl_easy_setopt(hnd, CURLOPT_XFERINFOFUNCTION, my_progress_d_cb);
curl_easy_setopt(hnd, CURLOPT_XFERINFODATA, t);
if(use_earlydata)
curl_easy_setopt(hnd, CURLOPT_SSL_OPTIONS, (long)CURLSSLOPT_EARLYDATA);
curl_easy_setopt(hnd, CURLOPT_SSL_OPTIONS, CURLSSLOPT_EARLYDATA);
if(forbid_reuse_d)
curl_easy_setopt(hnd, CURLOPT_FORBID_REUSE, 1L);
if(host)

View file

@ -149,7 +149,7 @@ static int setup_hx_upload(CURL *hnd, const char *url, struct transfer_u *t,
curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, my_write_u_cb);
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, t);
if(use_earlydata)
curl_easy_setopt(hnd, CURLOPT_SSL_OPTIONS, (long)CURLSSLOPT_EARLYDATA);
curl_easy_setopt(hnd, CURLOPT_SSL_OPTIONS, CURLSSLOPT_EARLYDATA);
if(!t->method || !strcmp("PUT", t->method))
curl_easy_setopt(hnd, CURLOPT_UPLOAD, 1L);

View file

@ -37,7 +37,7 @@ static CURLcode test_lib1511(char *URL)
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_HEADER, 1L);
easy_setopt(curl, CURLOPT_TIMECONDITION, (long)CURL_TIMECOND_IFMODSINCE);
easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
/* TIMEVALUE in the future */
easy_setopt(curl, CURLOPT_TIMEVALUE, 1566210680L);

View file

@ -57,11 +57,11 @@ static CURLcode test_lib1513(char *URL)
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_TIMEOUT, (long)7);
easy_setopt(curl, CURLOPT_NOSIGNAL, (long)1);
easy_setopt(curl, CURLOPT_TIMEOUT, 7L);
easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progressKiller);
easy_setopt(curl, CURLOPT_PROGRESSDATA, NULL);
easy_setopt(curl, CURLOPT_NOPROGRESS, (long)0);
easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
res = curl_easy_perform(curl);

View file

@ -62,11 +62,11 @@ static CURLcode test_lib1555(char *URL)
easy_init(t1555_curl);
easy_setopt(t1555_curl, CURLOPT_URL, URL);
easy_setopt(t1555_curl, CURLOPT_TIMEOUT, (long)7);
easy_setopt(t1555_curl, CURLOPT_NOSIGNAL, (long)1);
easy_setopt(t1555_curl, CURLOPT_TIMEOUT, 7L);
easy_setopt(t1555_curl, CURLOPT_NOSIGNAL, 1L);
easy_setopt(t1555_curl, CURLOPT_PROGRESSFUNCTION, progressCallback);
easy_setopt(t1555_curl, CURLOPT_PROGRESSDATA, NULL);
easy_setopt(t1555_curl, CURLOPT_NOPROGRESS, (long)0);
easy_setopt(t1555_curl, CURLOPT_NOPROGRESS, 0L);
res = curl_easy_perform(t1555_curl);

View file

@ -37,7 +37,7 @@ static CURLcode test_lib1568(char *URL)
curl_easy_setopt(hnd, CURLOPT_HEADER, 1L);
curl_easy_setopt(hnd, CURLOPT_USERPWD, "testuser:testpass");
curl_easy_setopt(hnd, CURLOPT_USERAGENT, "lib1568");
curl_easy_setopt(hnd, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST);
curl_easy_setopt(hnd, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
curl_easy_setopt(hnd, CURLOPT_PORT, strtol(libtest_arg2, NULL, 10));

View file

@ -40,7 +40,7 @@ static CURLcode test_lib1593(char *URL)
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_TIMECONDITION, (long)CURL_TIMECOND_IFMODSINCE);
easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
/* Some TIMEVALUE; it doesn't matter. */
easy_setopt(curl, CURLOPT_TIMEVALUE, 1566210680L);

View file

@ -33,7 +33,7 @@ static CURLcode test_lib1599(char *URL)
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_NETRC, (long)CURL_NETRC_REQUIRED);
curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_REQUIRED);
curl_easy_setopt(curl, CURLOPT_NETRC_FILE, libtest_arg2);
res = curl_easy_perform(curl);

View file

@ -73,8 +73,7 @@ static CURLcode test_lib1662(char *URL)
curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/2000");
curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION,
(long)CURL_HTTP_VERSION_2TLS);
curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS);
curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L);
curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);

View file

@ -45,7 +45,7 @@ static CURLcode test_lib2309(char *URL)
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_PROXY, libtest_arg3);
curl_easy_setopt(curl, CURLOPT_NETRC, (long)CURL_NETRC_REQUIRED);
curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_REQUIRED);
curl_easy_setopt(curl, CURLOPT_NETRC_FILE, libtest_arg2);
curldupe = curl_easy_duphandle(curl);

View file

@ -70,7 +70,7 @@ static CURLcode test_lib2502(char *URL)
easy_setopt(curl[i], CURLOPT_URL, target_url);
/* go http2 */
easy_setopt(curl[i], CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_3ONLY);
easy_setopt(curl[i], CURLOPT_CONNECTTIMEOUT_MS, (long)5000);
easy_setopt(curl[i], CURLOPT_CONNECTTIMEOUT_MS, 5000L);
easy_setopt(curl[i], CURLOPT_CAINFO, libtest_arg4);
/* wait for first connection established to see if we can share it */
easy_setopt(curl[i], CURLOPT_PIPEWAIT, 1L);

View file

@ -110,7 +110,7 @@ static CURLcode test_lib510(char *URL)
test_setopt(curl, CURLOPT_HTTPHEADER, slist);
if(testnum == 565) {
test_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST);
test_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
test_setopt(curl, CURLOPT_USERPWD, "foo:bar");
}

View file

@ -61,7 +61,7 @@ static CURLcode init(int num, CURLM *cm, const char *url, const char *userpwd,
if(res)
goto init_failed;
res_easy_setopt(testeh[num], CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);
res_easy_setopt(testeh[num], CURLOPT_PROXYAUTH, CURLAUTH_ANY);
if(res)
goto init_failed;

View file

@ -103,7 +103,7 @@ static CURLcode test_lib547(char *URL)
test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
test_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
test_setopt(curl, CURLOPT_PROXYAUTH,
(long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_NTLM);
res = curl_easy_perform(curl);

View file

@ -198,7 +198,7 @@ static CURLcode test_lib552(char *URL)
/* Accept any auth. But for this bug configure proxy with DIGEST, basic
might work too, not NTLM */
test_setopt(curl, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);
test_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
res = curl_easy_perform(curl);

View file

@ -99,7 +99,7 @@ static CURLcode test_lib555(char *URL)
easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
easy_setopt(curl, CURLOPT_PROXYAUTH,
(long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_NTLM);
multi_init(m);

View file

@ -149,7 +149,7 @@ static CURLcode test_lib579(char *URL)
/* enforce chunked transfer by setting the header */
test_setopt(curl, CURLOPT_HTTPHEADER, slist);
test_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST);
test_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
test_setopt(curl, CURLOPT_USERPWD, "foo:bar");
/* we want to use our own progress function */

View file

@ -54,7 +54,7 @@ static CURLcode test_lib583(char *URL)
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_INFILESIZE, (long)5);
easy_setopt(curl, CURLOPT_INFILESIZE, 5L);
multi_add_handle(multiHandle, curl);

View file

@ -29,10 +29,11 @@
It is reproducible by the following steps:
- Use a proxy that offers NTLM and Negotiate ( CURLOPT_PROXY and
CURLOPT_PROXYPORT)
- Tell libcurl NOT to use Negotiate CURL_EASY_SETOPT(CURLOPT_PROXYAUTH,
CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_NTLM)
- Use a proxy that offers NTLM and Negotiate
(CURLOPT_PROXY and CURLOPT_PROXYPORT)
- Tell libcurl NOT to use Negotiate
curl_easy_setopt(CURLOPT_PROXYAUTH,
CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_NTLM)
- Start the request
*/
@ -59,7 +60,7 @@ static CURLcode test_lib590(char *URL)
test_setopt(curl, CURLOPT_URL, URL);
test_setopt(curl, CURLOPT_HEADER, 1L);
test_setopt(curl, CURLOPT_PROXYAUTH,
(long) (CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_NTLM));
CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_NTLM);
test_setopt(curl, CURLOPT_PROXY, libtest_arg2); /* set in first.c */
/* set the name + password twice to test that the API is fine with it */

View file

@ -80,8 +80,7 @@ static CURLcode test_cert_blob(const char *url, const char *cafile)
curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "CURLOPT_CAINFO_BLOB");
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS,
(long)CURLSSLOPT_REVOKE_BEST_EFFORT);
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_REVOKE_BEST_EFFORT);
blob.data = certdata;
blob.len = certsize;

View file

@ -48,7 +48,7 @@ static CURLcode test_lib694(char *URL)
test_setopt(curl, CURLOPT_HEADER, 1L);
test_setopt(curl, CURLOPT_VERBOSE, 1L);
test_setopt(curl, CURLOPT_HTTPAUTH,
(long) (CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_NTLM));
CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_NTLM);
test_setopt(curl, CURLOPT_USERPWD, "me:password");
do {