diff options
author | Yang Tse <yangsita@gmail.com> | 2012-04-13 17:58:41 +0200 |
---|---|---|
committer | Yang Tse <yangsita@gmail.com> | 2012-04-13 17:59:49 +0200 |
commit | 865893fb143540037ca34f6a4438ebe2e286ec5a (patch) | |
tree | 7e915522d0c9e6eafd0a4d30929dfa45c3695da3 | |
parent | a60edcc6d445e7e0517589cf5fda2682bd89e34e (diff) | |
download | curl-865893fb143540037ca34f6a4438ebe2e286ec5a.tar.gz |
examples: fix compiler warnings
-rw-r--r-- | docs/examples/Makefile.am | 2 | ||||
-rw-r--r-- | docs/examples/anyauthput.c | 9 | ||||
-rw-r--r-- | docs/examples/externalsocket.c | 12 | ||||
-rw-r--r-- | docs/examples/ftp-wildcard.c | 7 | ||||
-rw-r--r-- | docs/examples/ftpupload.c | 9 | ||||
-rw-r--r-- | docs/examples/httpput.c | 9 | ||||
-rw-r--r-- | docs/examples/imap.c | 2 | ||||
-rw-r--r-- | docs/examples/post-callback.c | 6 | ||||
-rw-r--r-- | docs/examples/printf_macro.h | 45 | ||||
-rw-r--r-- | docs/examples/sendrecv.c | 8 |
10 files changed, 41 insertions, 68 deletions
diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index a71014d7c..27d20dfb6 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -23,7 +23,7 @@ AUTOMAKE_OPTIONS = foreign nostdinc EXTRA_DIST = README Makefile.example Makefile.inc Makefile.m32 \ - Makefile.netware makefile.dj printf_macro.h $(COMPLICATED_EXAMPLES) + Makefile.netware makefile.dj $(COMPLICATED_EXAMPLES) # Specify our include paths here, and do it relative to $(top_srcdir) and # $(top_builddir), to ensure that these paths which belong to the library diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index 2997a1e98..a28ecb769 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -42,7 +42,6 @@ #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" @@ -89,12 +88,16 @@ static curlioerr my_ioctl(CURL *handle, curliocmd cmd, void *userp) static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) { size_t retcode; + curl_off_t nread; intptr_t fd = (intptr_t)stream; retcode = read(fd, ptr, size * nmemb); - fprintf(stderr, "*** We read %" _FMT_SIZE_T " bytes from file\n", retcode); + nread = (curl_off_t)retcode; + + fprintf(stderr, "*** We read %" CURL_FORMAT_CURL_OFF_T + " bytes from file\n", nread); return retcode; } diff --git a/docs/examples/externalsocket.c b/docs/examples/externalsocket.c index c4abafd87..6e2a773b2 100644 --- a/docs/examples/externalsocket.c +++ b/docs/examples/externalsocket.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -57,7 +57,10 @@ static curl_socket_t opensocket(void *clientp, curlsocktype purpose, struct curl_sockaddr *address) { - curl_socket_t sockfd = *(curl_socket_t *)clientp; + curl_socket_t sockfd; + (void)purpose; + (void)address; + sockfd = *(curl_socket_t *)clientp; /* the actual externally set socket is passed in via the OPENSOCKETDATA option */ return sockfd; @@ -66,6 +69,9 @@ static curl_socket_t opensocket(void *clientp, static int sockopt_callback(void *clientp, curl_socket_t curlfd, curlsocktype purpose) { + (void)clientp; + (void)curlfd; + (void)purpose; /* This return code was added in libcurl 7.21.5 */ return CURL_SOCKOPT_ALREADY_CONNECTED; } @@ -96,7 +102,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_URL, "http://99.99.99.99:9999"); /* Create the socket "manually" */ - if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) { + if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) == CURL_SOCKET_BAD ) { printf("Error creating listening socket.\n"); return 3; } diff --git a/docs/examples/ftp-wildcard.c b/docs/examples/ftp-wildcard.c index fd92ca651..5a2a10311 100644 --- a/docs/examples/ftp-wildcard.c +++ b/docs/examples/ftp-wildcard.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -33,7 +33,7 @@ static long file_is_comming(struct curl_fileinfo *finfo, static long file_is_downloaded(struct callback_data *data); static size_t write_it(char *buff, size_t size, size_t nmemb, - struct callback_data *data); + void *cb_data); int main(int argc, char **argv) { @@ -135,8 +135,9 @@ static long file_is_downloaded(struct callback_data *data) } static size_t write_it(char *buff, size_t size, size_t nmemb, - struct callback_data *data) + void *cb_data) { + struct callback_data *data = cb_data; size_t written = 0; if(data->output) written = fwrite(buff, size, nmemb, data->output); diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index 722acbc9e..9928b9e81 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -32,7 +32,6 @@ #else #include <unistd.h> #endif -#include "printf_macro.h" /* * This example shows an FTP upload, with a rename of the file just after @@ -52,12 +51,16 @@ variable's memory when passed in to it from an app like this. */ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) { + curl_off_t 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); - fprintf(stderr, "*** We read %" _FMT_SIZE_T " bytes from file\n", retcode); + nread = (curl_off_t)retcode; + + fprintf(stderr, "*** We read %" CURL_FORMAT_CURL_OFF_T + " bytes from file\n", nread); return retcode; } diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index 664c8e152..f04618f96 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -25,7 +25,6 @@ #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 @@ -40,13 +39,17 @@ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) { size_t retcode; + curl_off_t 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); - fprintf(stderr, "*** We read %" _FMT_SIZE_T " bytes from file\n", retcode); + nread = (curl_off_t)retcode; + + fprintf(stderr, "*** We read %" CURL_FORMAT_CURL_OFF_T + " bytes from file\n", nread); return retcode; } diff --git a/docs/examples/imap.c b/docs/examples/imap.c index eafea81f2..ba07f022a 100644 --- a/docs/examples/imap.c +++ b/docs/examples/imap.c @@ -25,7 +25,7 @@ int main(void) { CURL *curl; - CURLcode res; + CURLcode res = CURLE_OK; curl = curl_easy_init(); if(curl) { diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index bb99a8566..adadaf803 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -30,7 +30,7 @@ const char data[]="this is what we post to the silly web server"; struct WriteThis { const char *readptr; - int sizeleft; + long sizeleft; }; static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp) @@ -96,7 +96,7 @@ int main(void) #else /* Set the expected POST size. If you want to POST large amounts of data, consider CURLOPT_POSTFIELDSIZE_LARGE */ - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)pooh.sizeleft); + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, pooh.sizeleft); #endif #ifdef DISABLE_EXPECT diff --git a/docs/examples/printf_macro.h b/docs/examples/printf_macro.h deleted file mode 100644 index 9eed8f4c6..000000000 --- a/docs/examples/printf_macro.h +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * 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 369601d16..88fddf59f 100644 --- a/docs/examples/sendrecv.c +++ b/docs/examples/sendrecv.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -24,7 +24,6 @@ #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) @@ -65,6 +64,7 @@ int main(void) curl_socket_t sockfd; /* socket */ long sockextr; size_t iolen; + curl_off_t nread; curl = curl_easy_init(); if(curl) { @@ -123,7 +123,9 @@ int main(void) if(CURLE_OK != res) break; - printf("Received %" _FMT_SIZE_T " bytes.\n", iolen); + nread = (curl_off_t)iolen; + + printf("Received %" CURL_FORMAT_CURL_OFF_T " bytes.\n", nread); } /* always cleanup */ |