aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorGuenter Knauf <lists@gknw.net>2011-09-23 01:22:18 +0200
committerGuenter Knauf <lists@gknw.net>2011-09-23 02:16:20 +0200
commitba52e0a93bbdfa0430d12cda14d4ed71616b92a1 (patch)
tree7231d966e216e75051b786c401c904085bfa52ac /docs
parent40c27e299f97e36c4c2ecc697397f5626737513b (diff)
Added a workaround for printing size_t.
Diffstat (limited to 'docs')
-rw-r--r--docs/examples/anyauthput.c3
-rw-r--r--docs/examples/ftpupload.c3
-rw-r--r--docs/examples/httpput.c3
-rw-r--r--docs/examples/printf_macro.h45
-rw-r--r--docs/examples/sendrecv.c3
5 files changed, 53 insertions, 4 deletions
diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c
index 76fa15853..bab36c57b 100644
--- a/docs/examples/anyauthput.c
+++ b/docs/examples/anyauthput.c
@@ -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;
}
diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c
index 305734d5d..722acbc9e 100644
--- a/docs/examples/ftpupload.c
+++ b/docs/examples/ftpupload.c
@@ -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;
}
diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c
index f78a74107..664c8e152 100644
--- a/docs/examples/httpput.c
+++ b/docs/examples/httpput.c
@@ -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
index 000000000..9eed8f4c6
--- /dev/null
+++ b/docs/examples/printf_macro.h
@@ -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 */
diff --git a/docs/examples/sendrecv.c b/docs/examples/sendrecv.c
index 0a49f2ff5..369601d16 100644
--- a/docs/examples/sendrecv.c
+++ b/docs/examples/sendrecv.c
@@ -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 */