]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
docs/libcurl: fix type and prototype problems in examples
authorDaniel Stenberg <daniel@haxx.se>
Tue, 29 Apr 2025 20:27:52 +0000 (22:27 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 29 Apr 2025 20:44:05 +0000 (22:44 +0200)
Found by enabling the typechecks when compiling them with
verify-examples.pl

Closes #17231

21 files changed:
.github/scripts/verify-examples.pl
docs/libcurl/curl_easy_recv.md
docs/libcurl/curl_easy_send.md
docs/libcurl/curl_ws_meta.md
docs/libcurl/opts/CURLOPT_ALTSVC.md
docs/libcurl/opts/CURLOPT_CHUNK_END_FUNCTION.md
docs/libcurl/opts/CURLOPT_HEADEROPT.md
docs/libcurl/opts/CURLOPT_IPRESOLVE.md
docs/libcurl/opts/CURLOPT_MIME_OPTIONS.md
docs/libcurl/opts/CURLOPT_POSTREDIR.md
docs/libcurl/opts/CURLOPT_PROGRESSDATA.md
docs/libcurl/opts/CURLOPT_PROGRESSFUNCTION.md
docs/libcurl/opts/CURLOPT_PROTOCOLS.md
docs/libcurl/opts/CURLOPT_PROXYTYPE.md
docs/libcurl/opts/CURLOPT_PROXY_SSLVERSION.md
docs/libcurl/opts/CURLOPT_PROXY_SSL_OPTIONS.md
docs/libcurl/opts/CURLOPT_REDIR_PROTOCOLS.md
docs/libcurl/opts/CURLOPT_SSH_AUTH_TYPES.md
docs/libcurl/opts/CURLOPT_TCP_NODELAY.md
docs/libcurl/opts/CURLOPT_TRAILERFUNCTION.md
docs/libcurl/opts/CURLOPT_XFERINFODATA.md

index 1366db0a880c43bae4b58be873a68f2cac2cda4d..5853f46b5692295e6e0a06ae36317824230c6e34 100755 (executable)
@@ -34,7 +34,7 @@ if($files[0] eq "-h") {
 }
 
 sub testcompile {
-    my $rc = system("gcc -c test.c -DCURL_DISABLE_TYPECHECK -DCURL_ALLOW_OLD_MULTI_SOCKET -DCURL_DISABLE_DEPRECATION -Wunused -Werror -Wall -Wno-unused-but-set-variable -I include") >> 8;
+    my $rc = system("gcc -c test.c -DCURL_ALLOW_OLD_MULTI_SOCKET -DCURL_DISABLE_DEPRECATION -Wunused -Werror -Wall -Wno-unused-but-set-variable -I include") >> 8;
     return $rc;
 }
 
index 2e3b595ec3614cd506f68576adda385543c6d390..e89c03592bf88b900f03c39b97357d39d7e1256b 100644 (file)
@@ -76,7 +76,7 @@ int main(void)
     if(res == CURLE_OK) {
       char buf[256];
       size_t nread;
-      long sockfd;
+      curl_socket_t sockfd;
 
       /* Extract the socket from the curl handle - we need it for waiting. */
       res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
index 97d63f6774ca5a104e02ff361ad8ade6edd404cd..885b37f1bcf6b704c85913cf5e6080ef4cbe4dac 100644 (file)
@@ -69,7 +69,7 @@ int main(void)
     res = curl_easy_perform(curl);
 
     if(res == CURLE_OK) {
-      long sockfd;
+      curl_socket_t sockfd;
       size_t sent;
       /* Extract the socket from the curl handle - we need it for waiting. */
       res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
index 1fd8b6641fd07121333ba10637997464d6968540..e34e5476764a71df576538a5a13f0a552bf31477 100644 (file)
@@ -137,7 +137,7 @@ struct customdata {
   void *ptr;
 };
 
-static size_t writecb(unsigned char *buffer,
+static size_t writecb(char *buffer,
                       size_t size, size_t nitems, void *p)
 {
   struct customdata *c = (struct customdata *)p;
index 802affd14aab3948b935ac17d107585f219d8269..14e3f31f92bec8c929ef99d5848b47ab95ba2a7e 100644 (file)
@@ -60,7 +60,7 @@ int main(void)
 {
   CURL *curl = curl_easy_init();
   if(curl) {
-    curl_easy_setopt(curl, CURLOPT_ALTSVC_CTRL, CURLALTSVC_H1);
+    curl_easy_setopt(curl, CURLOPT_ALTSVC_CTRL, (long)CURLALTSVC_H1);
     curl_easy_setopt(curl, CURLOPT_ALTSVC, "altsvc-cache.txt");
     curl_easy_perform(curl);
   }
index 2ebde59c76ad32091df7ee7fd430b94614746377..d95da58876c0ce70b17abc246a2216e7d37194bb 100644 (file)
@@ -53,8 +53,9 @@ struct callback_data {
    FILE *output;
 };
 
-static long file_is_downloaded(struct callback_data *data)
+static long file_is_downloaded(void *ptr)
 {
+  struct callback_data *data = ptr;
   if(data->output) {
     fclose(data->output);
     data->output = 0x0;
index 09f61d65d158d6fdbbe118e62c25a02e70532738..090781042c1ed030a17c4ce2fe88afd8e6a5e110 100644 (file)
@@ -65,7 +65,7 @@ int main(void)
     /* HTTPS over a proxy makes a separate CONNECT to the proxy, so tell
        libcurl to not send the custom headers to the proxy. Keep them
        separate. */
-    curl_easy_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE);
+    curl_easy_setopt(curl, CURLOPT_HEADEROPT, (long)CURLHEADER_SEPARATE);
     ret = curl_easy_perform(curl);
     curl_slist_free_all(list);
     curl_easy_cleanup(curl);
index 1b761c961b560e1e35e49063a820af8d0f787507..1b13e3641d7643e3205452e71fffb09b591164c7 100644 (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);
 
index 2dff43e0a5104d0fbe39677951a14a8d63f64203..8f17b14ed844433c76f8ea32cb9c401af0020bd1 100644 (file)
@@ -69,7 +69,7 @@ int main(void)
 
   if(curl) {
     curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
-    curl_easy_setopt(curl, CURLOPT_MIME_OPTIONS, CURLMIMEOPT_FORMESCAPE);
+    curl_easy_setopt(curl, CURLOPT_MIME_OPTIONS, (long)CURLMIMEOPT_FORMESCAPE);
 
     form = curl_mime_init(curl);
     if(form) {
index 99729a679262d08c628910b22c8f2590f1ea5b12..6f4d48b140b7c0a7cb76cdb20e6d6eba0258ea2a 100644 (file)
@@ -65,7 +65,7 @@ int main(void)
 
     /* example.com is redirected, so we tell libcurl to send POST on 301,
        302 and 303 HTTP response codes */
-    curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
+    curl_easy_setopt(curl, CURLOPT_POSTREDIR, (long)CURL_REDIR_POST_ALL);
 
     curl_easy_perform(curl);
   }
index 7e2683391849468049e6327056ccebff215a461a..d86210b3e2c6dcb2aa23d666cac58d673414eaa1 100644 (file)
@@ -43,11 +43,11 @@ struct progress {
   size_t size;
 };
 
-static size_t progress_callback(void *clientp,
-                                double dltotal,
-                                double dlnow,
-                                double ultotal,
-                                double ulnow)
+static int progress_callback(void *clientp,
+                             double dltotal,
+                             double dlnow,
+                             double ultotal,
+                             double ulnow)
 {
   struct progress *memory = clientp;
   printf("private: %p\n", memory->private);
index 2074eb10bad41ac08b4f39f0d28d9779e4061e1b..5334edbe22247891fe8332d57023d6c6b1f3b878 100644 (file)
@@ -89,11 +89,11 @@ struct progress {
   size_t size;
 };
 
-static size_t progress_callback(void *clientp,
-                                double dltotal,
-                                double dlnow,
-                                double ultotal,
-                                double ulnow)
+static int progress_callback(void *clientp,
+                             double dltotal,
+                             double dlnow,
+                             double ultotal,
+                             double ulnow)
 {
   struct progress *memory = clientp;
   printf("private: %p\n", memory->private);
index 8adc95afa0b8824eb070bb6533145803a6b48215..fd4d10adfaf933cfd83c9ee0888d1e1e839b08fe 100644 (file)
@@ -88,7 +88,7 @@ int main(int argc, char **argv)
 
     /* only allow HTTP, TFTP and SFTP */
     curl_easy_setopt(curl, CURLOPT_PROTOCOLS,
-                     CURLPROTO_HTTP | CURLPROTO_TFTP | CURLPROTO_SFTP);
+                     (long)CURLPROTO_HTTP | CURLPROTO_TFTP | CURLPROTO_SFTP);
 
     /* Perform the request */
     curl_easy_perform(curl);
index 68c45e86dc1559ea21ccba4a05345bfd3a699d2f..668a2e43c130955f07facabc66cbc87dbc36fd88 100644 (file)
@@ -86,7 +86,7 @@ int main(void)
     curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
     curl_easy_setopt(curl, CURLOPT_PROXY, "local.example.com:1080");
     /* set the proxy type */
-    curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
+    curl_easy_setopt(curl, CURLOPT_PROXYTYPE, (long)CURLPROXY_SOCKS5);
     ret = curl_easy_perform(curl);
     curl_easy_cleanup(curl);
   }
index 0b35e310599273a0e868327fbac12c7de14fc024..f2f76bbf9c86ab0cc90b39364b01161d6cc17f23 100644 (file)
@@ -116,7 +116,7 @@ int main(void)
     curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
 
     /* ask libcurl to use TLS version 1.0 or later */
-    curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
+    curl_easy_setopt(curl, CURLOPT_SSLVERSION, (long)CURL_SSLVERSION_TLSv1);
 
     /* Perform the request */
     curl_easy_perform(curl);
index 0a0681e21dd7223013aa21090e01c5b5ff0add91..62eafca48d512fa07112fdd2c190bbf529ef8437 100644 (file)
@@ -105,8 +105,8 @@ int main(void)
     curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
     curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
     /* weaken TLS only for use with silly proxies */
-    curl_easy_setopt(curl, CURLOPT_PROXY_SSL_OPTIONS, CURLSSLOPT_ALLOW_BEAST |
-                     CURLSSLOPT_NO_REVOKE);
+    curl_easy_setopt(curl, CURLOPT_PROXY_SSL_OPTIONS, (long)
+                     CURLSSLOPT_ALLOW_BEAST | CURLSSLOPT_NO_REVOKE);
     res = curl_easy_perform(curl);
     curl_easy_cleanup(curl);
   }
index 1e27e7ab3c572adb926eb2b3cf05ee0bc5361fba..9cbcc57b5faa812acb2941aa22a34e682019a4d6 100644 (file)
@@ -97,7 +97,7 @@ int main(int argc, char **argv)
     curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
 
     /* only allow redirects to HTTP and HTTPS URLs */
-    curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS,
+    curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, (long)
                      CURLPROTO_HTTP | CURLPROTO_HTTPS);
 
     /* Perform the request */
index 58be11d55e6fc304dc01dd2ff3a11b0b22bd0a3e..01ebd6f7a4cd9b209b55eb8097e438dec5321f67 100644 (file)
@@ -52,7 +52,7 @@ int main(void)
   if(curl) {
     CURLcode res;
     curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/file");
-    curl_easy_setopt(curl, CURLOPT_SSH_AUTH_TYPES,
+    curl_easy_setopt(curl, CURLOPT_SSH_AUTH_TYPES, (long)
                      CURLSSH_AUTH_PUBLICKEY | CURLSSH_AUTH_KEYBOARD);
     res = curl_easy_perform(curl);
     curl_easy_cleanup(curl);
index 1b9d4e270005eb788aac43c0b49064c65b13e0a6..d6c226962014e7038ca608a869bf9fcdebc0b610 100644 (file)
@@ -57,7 +57,7 @@ int main(void)
   if(curl) {
     curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
     /* leave Nagle enabled */
-    curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 0);
+    curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 0L);
     curl_easy_perform(curl);
   }
 }
index de341fb0d3d1e5788b174fc037e41ad96dee4bd3..06362337658fc4570c17fd60c8772feb0e2f3231 100644 (file)
@@ -64,6 +64,9 @@ NULL
 
 # EXAMPLE
 ~~~c
+extern size_t read_cb(char *ptr, size_t size,
+                      size_t nmemb, void *userdata);
+
 static int trailer_cb(struct curl_slist **tr, void *data)
 {
   /* libcurl frees the list */
@@ -84,7 +87,7 @@ int main(void)
 
     /* Assuming we have a function that returns the data to be pushed
        Let that function be read_cb */
-    curl_easy_setopt(curl, CURLOPT_READFUNCTION, trailer_cb);
+    curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);
 
     struct curl_slist *headers = NULL;
     headers = curl_slist_append(headers, "Trailer: My-super-awesome-trailer");
index 1a8d20cedc20bdab4ac87ba388144b5142707966..3cc0ddd1ca31b932f57ac35a3a64d2dbb5e78c14 100644 (file)
@@ -46,11 +46,11 @@ struct progress {
   size_t size;
 };
 
-static size_t progress_cb(void *clientp,
-                          curl_off_t dltotal,
-                          curl_off_t dlnow,
-                          curl_off_t ultotal,
-                          curl_off_t ulnow)
+static int progress_cb(void *clientp,
+                       curl_off_t dltotal,
+                       curl_off_t dlnow,
+                       curl_off_t ultotal,
+                       curl_off_t ulnow)
 {
   struct progress *memory = clientp;
   printf("private ptr: %p\n", memory->private);