docs/examples/CMakeLists.txt+1 -2
| @@ -83,8 +83,7 @@ foreach(_target IN LISTS COMPLICATED_MAY_BUILD check_PROGRAMS _all) # keep 'COM |
| add_dependencies(curl-examples ${_target_name}) |
| endif() |
| target_link_libraries(${_target_name} ${LIB_SELECTED} ${CURL_NETWORK_AND_TIME_LIBS} ${_more_libs}) |
| - | target_compile_definitions(${_target_name} PRIVATE "CURL_NO_OLDIES" |
| - | "$<$<BOOL:${WIN32}>:WIN32_LEAN_AND_MEAN>" "$<$<BOOL:${MSVC}>:_CRT_SECURE_NO_DEPRECATE>") |
| + | target_compile_definitions(${_target_name} PRIVATE "CURL_NO_OLDIES" "$<$<BOOL:${WIN32}>:WIN32_LEAN_AND_MEAN>") |
| set_target_properties(${_target_name} PROPERTIES OUTPUT_NAME "${_target}" PROJECT_LABEL "Example ${_target}" UNITY_BUILD OFF) |
| endforeach() |
| |
docs/examples/anyauthput.c+6 -0
| @@ -26,6 +26,12 @@ |
| * one the server supports/wants. |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for fopen() */ |
| + | #endif |
| + | #endif |
| + | |
| #include <stdio.h> |
| #include <fcntl.h> |
| #include <sys/types.h> |
docs/examples/block_ip.c+5 -5
| @@ -34,13 +34,13 @@ |
| int main(void) { printf("Platform not supported.\n"); return 1; } |
| #else |
| |
| - | #ifdef _WIN32 |
| - | #ifndef _CRT_SECURE_NO_WARNINGS |
| - | #define _CRT_SECURE_NO_WARNINGS |
| - | #endif |
| + | #ifdef _MSC_VER |
| #ifndef _CRT_NONSTDC_NO_DEPRECATE |
| - | #define _CRT_NONSTDC_NO_DEPRECATE |
| + | #define _CRT_NONSTDC_NO_DEPRECATE /* for strdup() */ |
| + | #endif |
| #endif |
| + | |
| + | #ifdef _WIN32 |
| #if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600 |
| #undef _WIN32_WINNT |
| #define _WIN32_WINNT 0x0600 /* Requires Windows Vista */ |
docs/examples/chkspeed.c+5 -0
| @@ -34,6 +34,11 @@ |
| * dd if=/dev/urandom of=file_1M.bin bs=1M count=1 |
| * |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for ctime() */ |
| + | #endif |
| + | #endif |
| |
| #include <stdio.h> |
| #include <stdlib.h> |
docs/examples/cookie_interface.c+5 -0
| @@ -25,6 +25,11 @@ |
| * Import and export cookies with COOKIELIST. |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for _snprintf() */ |
| + | #endif |
| + | #endif |
| |
| #include <stdio.h> |
| #include <string.h> |
docs/examples/externalsocket.c+3 -0
| @@ -26,6 +26,9 @@ |
| * </DESC> |
| */ |
| #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for strerror() */ |
| + | #endif |
| #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS |
| #define _WINSOCK_DEPRECATED_NO_WARNINGS /* for inet_addr() */ |
| #endif |
docs/examples/fileupload.c+9 -2
| @@ -25,10 +25,17 @@ |
| * Upload to a file:// URL |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for fopen() */ |
| + | #endif |
| + | #endif |
| + | |
| #include <stdio.h> |
| - | #include <curl/curl.h> |
| - | #include <sys/stat.h> |
| #include <fcntl.h> |
| + | #include <sys/stat.h> |
| + | |
| + | #include <curl/curl.h> |
| |
| #ifdef _WIN32 |
| #undef stat |
docs/examples/ftp-wildcard.c+8 -1
| @@ -25,9 +25,16 @@ |
| * FTP wildcard pattern matching |
| * </DESC> |
| */ |
| - | #include <curl/curl.h> |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for fopen() */ |
| + | #endif |
| + | #endif |
| + | |
| #include <stdio.h> |
| |
| + | #include <curl/curl.h> |
| + | |
| struct callback_data { |
| FILE *output; |
| }; |
docs/examples/ftpget.c+9 -4
| @@ -21,14 +21,19 @@ |
| * SPDX-License-Identifier: curl |
| * |
| ***************************************************************************/ |
| - | #include <stdio.h> |
| - | |
| - | #include <curl/curl.h> |
| - | |
| /* <DESC> |
| * Get a single file from an FTP server. |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for fopen() */ |
| + | #endif |
| + | #endif |
| + | |
| + | #include <stdio.h> |
| + | |
| + | #include <curl/curl.h> |
| |
| struct FtpFile { |
| const char *filename; |
docs/examples/ftpgetinfo.c+10 -5
| @@ -21,15 +21,20 @@ |
| * SPDX-License-Identifier: curl |
| * |
| ***************************************************************************/ |
| - | #include <stdio.h> |
| - | #include <string.h> |
| - | |
| - | #include <curl/curl.h> |
| - | |
| /* <DESC> |
| * Checks a single file's size and mtime from an FTP server. |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for fopen() */ |
| + | #endif |
| + | #endif |
| + | |
| + | #include <stdio.h> |
| + | #include <string.h> |
| + | |
| + | #include <curl/curl.h> |
| |
| static size_t throw_away(void *ptr, size_t size, size_t nmemb, void *data) |
| { |
docs/examples/ftpgetresp.c+10 -4
| @@ -21,15 +21,21 @@ |
| * SPDX-License-Identifier: curl |
| * |
| ***************************************************************************/ |
| - | #include <stdio.h> |
| - | |
| - | #include <curl/curl.h> |
| - | |
| /* <DESC> |
| * Similar to ftpget.c but also stores the received response-lines |
| * in a separate file using our own callback! |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for fopen() */ |
| + | #endif |
| + | #endif |
| + | |
| + | #include <stdio.h> |
| + | |
| + | #include <curl/curl.h> |
| + | |
| static size_t write_response(void *ptr, size_t size, size_t nmemb, void *data) |
| { |
| FILE *writehere = (FILE *)data; |
docs/examples/ftpsget.c+9 -5
| @@ -21,15 +21,19 @@ |
| * SPDX-License-Identifier: curl |
| * |
| ***************************************************************************/ |
| - | |
| - | #include <stdio.h> |
| - | |
| - | #include <curl/curl.h> |
| - | |
| /* <DESC> |
| * Get a single file from an FTPS server. |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for fopen() */ |
| + | #endif |
| + | #endif |
| + | |
| + | #include <stdio.h> |
| + | |
| + | #include <curl/curl.h> |
| |
| struct FtpFile { |
| const char *filename; |
docs/examples/ftpupload.c+16 -10
| @@ -21,14 +21,26 @@ |
| * SPDX-License-Identifier: curl |
| * |
| ***************************************************************************/ |
| + | /* <DESC> |
| + | * Performs an FTP upload and renames the file just after a successful |
| + | * transfer. |
| + | * </DESC> |
| + | */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for fopen(), strerror() */ |
| + | #endif |
| + | #endif |
| + | |
| #include <stdio.h> |
| #include <string.h> |
| + | #include <errno.h> |
| + | #include <fcntl.h> |
| + | #include <sys/stat.h> |
| + | #include <sys/types.h> |
| |
| #include <curl/curl.h> |
| - | #include <sys/types.h> |
| - | #include <sys/stat.h> |
| - | #include <fcntl.h> |
| - | #include <errno.h> |
| + | |
| #ifdef _WIN32 |
| #include <io.h> |
| #undef stat |
| @@ -40,12 +52,6 @@ |
| #include <unistd.h> |
| #endif |
| |
| - | /* <DESC> |
| - | * Performs an FTP upload and renames the file just after a successful |
| - | * transfer. |
| - | * </DESC> |
| - | */ |
| - | |
| #define LOCAL_FILE "/tmp/uploadthis.txt" |
| #define UPLOAD_FILE_AS "while-uploading.txt" |
| #define REMOTE_URL "ftp://example.com/" UPLOAD_FILE_AS |
docs/examples/ftpuploadresume.c+6 -0
| @@ -25,9 +25,15 @@ |
| * Upload to FTP, resuming failed transfers. Active mode. |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for fopen(), sscanf() */ |
| + | #endif |
| + | #endif |
| |
| #include <stdlib.h> |
| #include <stdio.h> |
| + | |
| #include <curl/curl.h> |
| |
| /* parse headers for Content-Length */ |
docs/examples/hsts-preload.c+7 -0
| @@ -25,8 +25,15 @@ |
| * Preload domains to HSTS |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for strcpy() */ |
| + | #endif |
| + | #endif |
| + | |
| #include <stdio.h> |
| #include <string.h> |
| + | |
| #include <curl/curl.h> |
| |
| struct entry { |
docs/examples/http2-download.c+10 -4
| @@ -25,15 +25,17 @@ |
| * Multiplexed HTTP/2 downloads over a single connection |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for _snprintf(), fopen(), strerror() */ |
| + | #endif |
| + | #endif |
| + | |
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <string.h> |
| #include <errno.h> |
| |
| - | #if defined(_MSC_VER) && (_MSC_VER < 1900) |
| - | #define snprintf _snprintf |
| - | #endif |
| - | |
| /* curl stuff */ |
| #include <curl/curl.h> |
| |
| @@ -44,6 +46,10 @@ |
| #define CURLPIPE_MULTIPLEX 0L |
| #endif |
| |
| + | #if defined(_MSC_VER) && (_MSC_VER < 1900) |
| + | #define snprintf _snprintf |
| + | #endif |
| + | |
| struct transfer { |
| FILE *out; |
| CURL *curl; |
docs/examples/http2-serverpush.c+10 -4
| @@ -25,6 +25,12 @@ |
| * HTTP/2 server push |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for _snprintf(), fopen() */ |
| + | #endif |
| + | #endif |
| + | |
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <string.h> |
| @@ -32,14 +38,14 @@ |
| /* curl stuff */ |
| #include <curl/curl.h> |
| |
| - | #if defined(_MSC_VER) && (_MSC_VER < 1900) |
| - | #define snprintf _snprintf |
| - | #endif |
| - | |
| #ifndef CURLPIPE_MULTIPLEX |
| #error "too old libcurl, cannot do HTTP/2 server push!" |
| #endif |
| |
| + | #if defined(_MSC_VER) && (_MSC_VER < 1900) |
| + | #define snprintf _snprintf |
| + | #endif |
| + | |
| static FILE *out_download; |
| |
| static void dump(const char *text, unsigned char *ptr, size_t size, char nohex) |
docs/examples/http2-upload.c+17 -10
| @@ -25,6 +25,13 @@ |
| * Multiplexed HTTP/2 uploads over a single connection |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for '_snprintf(), fopen(), localtime(), |
| + | strerror() */ |
| + | #endif |
| + | #endif |
| + | |
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <string.h> |
| @@ -38,6 +45,16 @@ |
| #include <unistd.h> |
| #endif |
| |
| + | /* curl stuff */ |
| + | #include <curl/curl.h> |
| + | |
| + | #ifndef CURLPIPE_MULTIPLEX |
| + | /* This little trick makes sure that we do not enable pipelining for libcurls |
| + | old enough to not have this symbol. It is _not_ defined to zero in a recent |
| + | libcurl header. */ |
| + | #define CURLPIPE_MULTIPLEX 0L |
| + | #endif |
| + | |
| #ifdef _WIN32 |
| #undef stat |
| #define stat _stat |
| @@ -50,16 +67,6 @@ |
| #define snprintf _snprintf |
| #endif |
| |
| - | /* curl stuff */ |
| - | #include <curl/curl.h> |
| - | |
| - | #ifndef CURLPIPE_MULTIPLEX |
| - | /* This little trick makes sure that we do not enable pipelining for libcurls |
| - | old enough to not have this symbol. It is _not_ defined to zero in a recent |
| - | libcurl header. */ |
| - | #define CURLPIPE_MULTIPLEX 0L |
| - | #endif |
| - | |
| #ifdef _MSC_VER |
| #define gettimeofday(a, b) my_gettimeofday((a), (b)) |
| static int my_gettimeofday(struct timeval *tp, void *tzp) |
docs/examples/httpput.c+6 -0
| @@ -25,6 +25,12 @@ |
| * HTTP PUT with easy interface and read callback |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for fopen() */ |
| + | #endif |
| + | #endif |
| + | |
| #include <stdio.h> |
| #include <fcntl.h> |
| #include <sys/stat.h> |
docs/examples/log_failed_transfers.c+6 -3
| @@ -31,18 +31,21 @@ |
| * The transfer's log is written to disk only if the transfer fails. |
| * |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for fopen(), strerror(), vsnprintf() */ |
| + | #endif |
| + | #endif |
| |
| #include <errno.h> |
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <limits.h> |
| #include <string.h> |
| + | |
| #include <curl/curl.h> |
| |
| #ifdef _WIN32 |
| - | #ifndef _CRT_SECURE_NO_WARNINGS |
| - | #define _CRT_SECURE_NO_WARNINGS |
| - | #endif |
| #include <windows.h> |
| #define strcasecmp _stricmp |
| #define strncasecmp _strnicmp |
docs/examples/sepheaders.c+6 -0
| @@ -25,6 +25,12 @@ |
| * Simple HTTP GET that stores the headers in a separate file |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for fopen() */ |
| + | #endif |
| + | #endif |
| + | |
| #include <stdio.h> |
| #include <stdlib.h> |
| |
docs/examples/sftpget.c+5 -0
| @@ -25,6 +25,11 @@ |
| * Gets a file using an SFTP URL. |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for fopen() */ |
| + | #endif |
| + | #endif |
| |
| #include <stdio.h> |
| |
docs/examples/sftpuploadresume.c+6 -0
| @@ -25,9 +25,15 @@ |
| * Upload to SFTP, resuming a previously aborted transfer. |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for fopen() */ |
| + | #endif |
| + | #endif |
| |
| #include <stdlib.h> |
| #include <stdio.h> |
| + | |
| #include <curl/curl.h> |
| |
| /* read data to upload */ |
docs/examples/simplessl.c+6 -0
| @@ -25,6 +25,12 @@ |
| * Shows HTTPS usage with client certs and optional ssl engine use. |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for fopen() */ |
| + | #endif |
| + | #endif |
| + | |
| #include <stdio.h> |
| |
| #include <curl/curl.h> |
docs/examples/synctime.c+6 -0
| @@ -56,6 +56,12 @@ |
| * This software synchronises your computer clock only when you issue |
| * it with --synctime. By default, it only display the webserver's clock. |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for _snprintf(), fopen(), gmtime(), |
| + | localtime(), sscanf() */ |
| + | #endif |
| + | #endif |
| |
| #include <stdio.h> |
| |
docs/examples/url2file.c+6 -0
| @@ -25,6 +25,12 @@ |
| * Download a given URL into a local file named page.out. |
| * </DESC> |
| */ |
| + | #ifdef _MSC_VER |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for fopen() */ |
| + | #endif |
| + | #endif |
| + | |
| #include <stdio.h> |
| #include <stdlib.h> |
| |
lib/curl_setup.h+9 -5
| @@ -90,11 +90,15 @@ |
| /* Disable Visual Studio warnings: 4127 "conditional expression is constant" */ |
| #pragma warning(disable:4127) |
| /* Avoid VS2005 and upper complaining about portable C functions. */ |
| - | #ifndef _CRT_NONSTDC_NO_DEPRECATE |
| - | #define _CRT_NONSTDC_NO_DEPRECATE /* for strdup(), write(), etc. */ |
| - | #endif |
| - | #ifndef _CRT_SECURE_NO_DEPRECATE |
| - | #define _CRT_SECURE_NO_DEPRECATE /* for fopen(), getenv(), etc. */ |
| + | #ifndef _CRT_NONSTDC_NO_DEPRECATE /* mingw-w64 v2+. MS SDK ~10+/~VS2017+. */ |
| + | #define _CRT_NONSTDC_NO_DEPRECATE /* for close(), fileno(), strdup(), |
| + | unlink(), etc. */ |
| + | #endif |
| + | #ifndef _CRT_SECURE_NO_WARNINGS |
| + | #define _CRT_SECURE_NO_WARNINGS /* for __sys_errlist, __sys_nerr, _wfopen(), |
| + | _wopen(), freopen(), getenv(), gmtime(), |
| + | sprintf(), strcpy(), wcscpy(), wcsncpy() |
| + | in tests: localtime(), open(), sscanf() */ |
| #endif |
| #endif /* _MSC_VER */ |
| |