]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
docs/examples: workaround broken -Wno-pedantic-ms-format
authorMarc Hoersken <info@marc-hoersken.de>
Tue, 14 Dec 2021 06:52:26 +0000 (07:52 +0100)
committerMarc Hoersken <info@marc-hoersken.de>
Tue, 14 Dec 2021 06:52:26 +0000 (07:52 +0100)
Avoid CURL_FORMAT_CURL_OFF_T by using unsigned long instead.
Improve size_t to long conversion in imap-append.c example.

Ref: https://github.com/curl/curl/issues/6079
Ref: https://github.com/curl/curl/pull/6082
Assisted-by: Jay Satiro
Reviewed-by: Daniel Stenberg
Preparation of #7922

docs/examples/anyauthput.c
docs/examples/chkspeed.c
docs/examples/fileupload.c
docs/examples/ftpupload.c
docs/examples/httpput.c
docs/examples/imap-append.c
docs/examples/progressfunc.c
docs/examples/sendrecv.c
docs/examples/sftpuploadresume.c

index cbb9633907a9dcafb52c4abff1f12c25bb6eddb5..f5db702f551a214581106f74c7ed6cb2c38b3516 100644 (file)
@@ -81,17 +81,17 @@ static curlioerr my_ioctl(CURL *handle, curliocmd cmd, void *userp)
 static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream)
 {
   ssize_t retcode;
-  curl_off_t nread;
+  unsigned long nread;
 
   int *fdp = (int *)stream;
   int fd = *fdp;
 
   retcode = read(fd, ptr, (READ_3RD_ARG)(size * nmemb));
 
-  nread = (curl_off_t)retcode;
-
-  fprintf(stderr, "*** We read %" CURL_FORMAT_CURL_OFF_T
-          " bytes from file\n", nread);
+  if(retcode > 0) {
+    nread = (unsigned long)retcode;
+    fprintf(stderr, "*** We read %lu bytes from file\n", nread);
+  }
 
   return retcode;
 }
index bc5387d778f4c5190184a4074be63d2e984e61a1..4c7136bf5ce7227c8de38ccf5ff45445e61f5f64 100644 (file)
@@ -170,32 +170,32 @@ int main(int argc, char *argv[])
     /* check for bytes downloaded */
     res = curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD_T, &val);
     if((CURLE_OK == res) && (val>0))
-      printf("Data downloaded: %" CURL_FORMAT_CURL_OFF_T " bytes.\n", val);
+      printf("Data downloaded: %lu bytes.\n", (unsigned long)val);
 
     /* check for total download time */
     res = curl_easy_getinfo(curl_handle, CURLINFO_TOTAL_TIME_T, &val);
     if((CURLE_OK == res) && (val>0))
-      printf("Total download time: %" CURL_FORMAT_CURL_OFF_T ".%06ld sec.\n",
-             (val / 1000000), (long)(val % 1000000));
+      printf("Total download time: %lu.%06lu sec.\n",
+             (unsigned long)(val / 1000000), (unsigned long)(val % 1000000));
 
     /* check for average download speed */
     res = curl_easy_getinfo(curl_handle, CURLINFO_SPEED_DOWNLOAD_T, &val);
     if((CURLE_OK == res) && (val>0))
-      printf("Average download speed: %" CURL_FORMAT_CURL_OFF_T
-             " kbyte/sec.\n", val / 1024);
+      printf("Average download speed: %lu kbyte/sec.\n",
+             (unsigned long)(val / 1024));
 
     if(prtall) {
       /* check for name resolution time */
       res = curl_easy_getinfo(curl_handle, CURLINFO_NAMELOOKUP_TIME_T, &val);
       if((CURLE_OK == res) && (val>0))
-        printf("Name lookup time: %" CURL_FORMAT_CURL_OFF_T ".%06ld sec.\n",
-               (val / 1000000), (long)(val % 1000000));
+        printf("Name lookup time: %lu.%06lu sec.\n",
+               (unsigned long)(val / 1000000), (unsigned long)(val % 1000000));
 
       /* check for connect time */
       res = curl_easy_getinfo(curl_handle, CURLINFO_CONNECT_TIME_T, &val);
       if((CURLE_OK == res) && (val>0))
-        printf("Connect time: %" CURL_FORMAT_CURL_OFF_T ".%06ld sec.\n",
-               (val / 1000000), (long)(val % 1000000));
+        printf("Connect time: %lu.%06lu sec.\n",
+               (unsigned long)(val / 1000000), (unsigned long)(val % 1000000));
     }
   }
   else {
index afea64316a023f775666fc6b26afed9a16b6c381..81914b2c97a6870c12cfb6e4b5deae05d6a1e232 100644 (file)
@@ -68,18 +68,16 @@ int main(void)
     if(res != CURLE_OK) {
       fprintf(stderr, "curl_easy_perform() failed: %s\n",
               curl_easy_strerror(res));
-
     }
     else {
       /* now extract transfer info */
       curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD_T, &speed_upload);
       curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME_T, &total_time);
 
-      fprintf(stderr, "Speed: %" CURL_FORMAT_CURL_OFF_T " bytes/sec during %"
-              CURL_FORMAT_CURL_OFF_T ".%06ld seconds\n",
-              speed_upload,
-              (total_time / 1000000), (long)(total_time % 1000000));
-
+      fprintf(stderr, "Speed: %lu bytes/sec during %lu.%06lu seconds\n",
+              (unsigned long)speed_upload,
+              (unsigned long)(total_time / 1000000),
+              (unsigned long)(total_time % 1000000));
     }
     /* always cleanup */
     curl_easy_cleanup(curl);
index 1b7bbf26a424248a1a4f2567c2a8ae806f97f89e..75356d86a3d68dfce59b324e0978d29e433c3d89 100644 (file)
    variable's memory when passed in to it from an app like this. */
 static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream)
 {
-  curl_off_t nread;
+  unsigned long nread;
   /* in real-world cases, this would probably get this data differently
      as this fread() stuff is exactly what the library already would do
      by default internally */
   size_t retcode = fread(ptr, size, nmemb, stream);
 
-  nread = (curl_off_t)retcode;
+  if(retcode > 0) {
+    nread = (unsigned long)retcode;
+    fprintf(stderr, "*** We read %lu bytes from file\n", nread);
+  }
 
-  fprintf(stderr, "*** We read %" CURL_FORMAT_CURL_OFF_T
-          " bytes from file\n", nread);
   return retcode;
 }
 
@@ -69,7 +70,7 @@ int main(void)
   CURLcode res;
   FILE *hd_src;
   struct stat file_info;
-  curl_off_t fsize;
+  unsigned long fsize;
 
   struct curl_slist *headerlist = NULL;
   static const char buf_1 [] = "RNFR " UPLOAD_FILE_AS;
@@ -80,9 +81,9 @@ int main(void)
     printf("Couldn't open '%s': %s\n", LOCAL_FILE, strerror(errno));
     return 1;
   }
-  fsize = (curl_off_t)file_info.st_size;
+  fsize = (unsigned long)file_info.st_size;
 
-  printf("Local file size: %" CURL_FORMAT_CURL_OFF_T " bytes.\n", fsize);
+  printf("Local file size: %lu bytes.\n", fsize);
 
   /* get a FILE * of the same file */
   hd_src = fopen(LOCAL_FILE, "rb");
index 90749da2dd14062d9eb2d5c28468b6e064a51058..7fd027819572060c7b23b1ce44b116fbe9e1c504 100644 (file)
 static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream)
 {
   size_t retcode;
-  curl_off_t nread;
+  unsigned long nread;
 
   /* in real-world cases, this would probably get this data differently
      as this fread() stuff is exactly what the library already would do
      by default internally */
   retcode = fread(ptr, size, nmemb, stream);
 
-  nread = (curl_off_t)retcode;
-
-  fprintf(stderr, "*** We read %" CURL_FORMAT_CURL_OFF_T
-          " bytes from file\n", nread);
+  if(retcode > 0) {
+    nread = (unsigned long)retcode;
+    fprintf(stderr, "*** We read %lu bytes from file\n", nread);
+  }
 
   return retcode;
 }
index 78ecc8d01640c3f3f89046a09e356585595615c5..e36cb10c0b22055fb9068fad739ca957a4b9aae6 100644 (file)
@@ -89,7 +89,8 @@ int main(void)
 
   curl = curl_easy_init();
   if(curl) {
-    long infilesize;
+    size_t filesize;
+    long infilesize = LONG_MAX;
     struct upload_status upload_ctx = { 0 };
 
     /* Set username and password */
@@ -108,7 +109,9 @@ int main(void)
     curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx);
     curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
 
-    infilesize = strlen(payload_text);
+    filesize = strlen(payload_text);
+    if(filesize <= LONG_MAX)
+      infilesize = (long)filesize;
     curl_easy_setopt(curl, CURLOPT_INFILESIZE, infilesize);
 
     /* Perform the append */
index df783119efa812abbef0572c8fae483de423ca2b..56889df668cef2b8213f2f6b5d600828e249fdbc 100644 (file)
@@ -51,14 +51,14 @@ static int xferinfo(void *p,
      be used */
   if((curtime - myp->lastruntime) >= MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL) {
     myp->lastruntime = curtime;
-    fprintf(stderr, "TOTAL TIME: %" CURL_FORMAT_CURL_OFF_T ".%06ld\r\n",
-            (curtime / 1000000), (long)(curtime % 1000000));
+    fprintf(stderr, "TOTAL TIME: %lu.%06lu\r\n",
+            (unsigned long)(curtime / 1000000),
+            (unsigned long)(curtime % 1000000));
   }
 
-  fprintf(stderr, "UP: %" CURL_FORMAT_CURL_OFF_T " of %" CURL_FORMAT_CURL_OFF_T
-          "  DOWN: %" CURL_FORMAT_CURL_OFF_T " of %" CURL_FORMAT_CURL_OFF_T
-          "\r\n",
-          ulnow, ultotal, dlnow, dltotal);
+  fprintf(stderr, "UP: %lu of %lu  DOWN: %lu of %lu\r\n",
+          (unsigned long)ulnow, (unsigned long)ultotal,
+          (unsigned long)dlnow, (unsigned long)dltotal);
 
   if(dlnow > STOP_DOWNLOAD_AFTER_THIS_MANY_BYTES)
     return 1;
index 44741aeba8072cdf8b240454da597ad44c1f3336..d8158466bb45acffab15d8eebb22b64943cee17a 100644 (file)
@@ -120,8 +120,7 @@ int main(void)
         return 1;
       }
 
-      printf("Sent %" CURL_FORMAT_CURL_OFF_T " bytes.\n",
-        (curl_off_t)nsent);
+      printf("Sent %lu bytes.\n", (unsigned long)nsent);
 
     } while(nsent_total < request_len);
 
@@ -151,8 +150,7 @@ int main(void)
         break;
       }
 
-      printf("Received %" CURL_FORMAT_CURL_OFF_T " bytes.\n",
-        (curl_off_t)nread);
+      printf("Received %lu bytes.\n", (unsigned long)nread);
     }
 
     /* always cleanup */
index e2aa37392818d7fc42218a93119959214745c407..da2a4102c4c773f3c766909c33326f04f8533edc 100644 (file)
@@ -66,7 +66,7 @@ static curl_off_t sftpGetRemoteFileSize(const char *i_remoteFile)
                                &remoteFileSizeByte);
     if(result)
       return -1;
-    printf("filesize: %" CURL_FORMAT_CURL_OFF_T "\n", remoteFileSizeByte);
+    printf("filesize: %lu\n", (unsigned long)remoteFileSizeByte);
   }
   curl_easy_cleanup(curlHandlePtr);