]> granicus.if.org Git - curl/commitdiff
Added a workaround for printing size_t.
authorGuenter Knauf <lists@gknw.net>
Thu, 22 Sep 2011 23:22:18 +0000 (01:22 +0200)
committerGuenter Knauf <lists@gknw.net>
Fri, 23 Sep 2011 00:16:20 +0000 (02:16 +0200)
docs/examples/anyauthput.c
docs/examples/ftpupload.c
docs/examples/httpput.c
docs/examples/printf_macro.h [new file with mode: 0644]
docs/examples/sendrecv.c

index 76fa158532d6ba3ee157610c72b370d195b0253d..bab36c57b2bbfab2e732ff8463fbe9772f1f7179 100644 (file)
@@ -41,6 +41,7 @@
 #endif
 
 #include <curl/curl.h>
+#include "printf_macro.h"
 
 #if LIBCURL_VERSION_NUM < 0x070c03
 #error "upgrade your libcurl to no less than 7.12.3"
@@ -92,7 +93,7 @@ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
 
   retcode = read(fd, ptr, size * nmemb);
 
-  fprintf(stderr, "*** We read %d bytes from file\n", retcode);
+  fprintf(stderr, "*** We read %" _FMT_SIZE_T " bytes from file\n", retcode);
 
   return retcode;
 }
index 305734d5df7f41a95dc5752bdb474b502c4a3a5c..722acbc9e7ae47f1830be05c96ba93f238f4cc97 100644 (file)
@@ -32,6 +32,7 @@
 #else
 #include <unistd.h>
 #endif
+#include "printf_macro.h"
 
 /*
  * This example shows an FTP upload, with a rename of the file just after
@@ -56,7 +57,7 @@ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
      by default internally */
   size_t retcode = fread(ptr, size, nmemb, stream);
 
-  fprintf(stderr, "*** We read %d bytes from file\n", retcode);
+  fprintf(stderr, "*** We read %" _FMT_SIZE_T " bytes from file\n", retcode);
   return retcode;
 }
 
index f78a74107e5e3714649ca6a253e5707ea93ccead..664c8e152a125b396b729235b4df653aadee33c4 100644 (file)
@@ -25,6 +25,7 @@
 #include <unistd.h>
 
 #include <curl/curl.h>
+#include "printf_macro.h"
 
 /*
  * This example shows a HTTP PUT operation. PUTs a file given as a command
@@ -45,7 +46,7 @@ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
      by default internally */
   retcode = fread(ptr, size, nmemb, stream);
 
-  fprintf(stderr, "*** We read %d bytes from file\n", retcode);
+  fprintf(stderr, "*** We read %" _FMT_SIZE_T " bytes from file\n", retcode);
 
   return retcode;
 }
diff --git a/docs/examples/printf_macro.h b/docs/examples/printf_macro.h
new file mode 100644 (file)
index 0000000..9eed8f4
--- /dev/null
@@ -0,0 +1,45 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+/* Simple hack trying to get a valid printf format string for size_t.
+ * If that fails for your platform you can define your own _FMT_SIZE_T,
+ * f.e.: -D_FMT_SIZE_T="zd"
+ */
+#ifndef _PRINTF_MACRO_H
+#define _PRINTF_MACRO_H
+
+#ifndef _FMT_SIZE_T
+#ifdef WIN32
+#define _FMT_SIZE_T "Id"
+#else
+/*
+"zd" is a GNU extension to POSIX; so we dont use it for size_t but hack around
+#define _FMT_SIZE_T "zd"
+*/
+#ifdef __x86_64__
+#define _FMT_SIZE_T "lu"
+#else
+#define _FMT_SIZE_T "u"
+#endif /* __x86_64__ */
+#endif /* WIN32 */
+#endif /* !_FMT_SIZE_T */
+
+#endif /* !_PRINTF_MACRO_H */
index 0a49f2ff5269e0edc3996e23e5be3571ca77e27d..369601d1675c01219ee6dd54ba38461690fb2c46 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <curl/curl.h>
+#include "printf_macro.h"
 
 /* Auxiliary function that waits on the socket. */
 static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms)
@@ -122,7 +123,7 @@ int main(void)
       if(CURLE_OK != res)
         break;
 
-      printf("Received %u bytes.\n", iolen);
+      printf("Received %" _FMT_SIZE_T " bytes.\n", iolen);
     }
 
     /* always cleanup */