build: tidy-up MSVC CRT warning suppression macros

- curl_setup.h: replace `_CRT_SECURE_NO_DEPRECATE` with
  `_CRT_SECURE_NO_WARNINGS`, which seems to be the preferred,
  more recent macro for this. Also syncing with libssh2.
  They are equivalent for curl sources with the supported compilers.
- cmake: stop setting `_CRT_SECURE_NO_DEPRECATE` globally for examples.
- examples: suppress CRT deprecation warnings on a per-file basis.
  To make it work when compiling examples out of curl's build systems.
  Use `_CRT_SECURE_NO_WARNINGS`.
- examples: document the functions requiring `_CRT_SECURE_NO_WARNINGS`.
- examples/block_ip: delete superfluous `_CRT_SECURE_NO_WARNINGS`.
- examples/block_ip: limit `_CRT_NONSTDC_NO_DEPRECATE` to MSVC.
- examples/log_failed_transfers: fix to set `_CRT_SECURE_NO_WARNINGS`
  before headers and limit to MSVC.
- curl_setup.h: document which SDKs support `_CRT_NONSTDC_NO_DEPRECATE`.

Closes #19175
This commit is contained in:
Viktor Szakats 2025-10-21 11:51:02 +02:00
parent 1e1ec7f6c2
commit 5fa2d8320c
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
27 changed files with 201 additions and 63 deletions

View file

@ -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)