build: update to not need _CRT_NONSTDC_NO_DEPRECATE with MSVC

Use non-deprecated CRT function variants on Windows.

- introduce `curlx_fdopen()`, `curlx_close()` and use them. Map them to
  non-deprecated, underscored, CRT functions on Windows.

- replace `close()` uses with either `sclose()` (for sockets) or
  `curlx_close()` (for files).

- map `fileno`, `unlink`, `isatty` to their non-deprecated, underscored,
  versions on Windows.

- tool_dirhie: map `mkdir` to `_mkdir` on Windows.

- easy: use `_strdup()` on Windows, regardless of how `HAVE_STRDUP` is
  set.

- cmake: assume `HAVE_STRDUP` on Windows. To allow dropping a detection
  hack using `_CRT_NONSTDC_NO_DEPRECATE` with MSVC. Windows always has
  `_strdup()` which the code uses, but also needs `HAVE_STRDUP` defined
  to disable curl's own `strdup()` implementation.

- curl_setup.h: drop `_CRT_NONSTDC_NO_DEPRECATE` as no longer necessary.

Closes #20212
This commit is contained in:
Viktor Szakats 2026-01-07 19:37:02 +01:00
parent dbc4603b09
commit e50aa46fb2
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
25 changed files with 54 additions and 49 deletions

View file

@ -89,7 +89,7 @@ bool tool_create_output_file(struct OutStruct *outs,
if(fd != -1) {
file = curlx_fdopen(fd, "wb");
if(!file)
close(fd);
curlx_close(fd);
}
}

View file

@ -23,14 +23,13 @@
***************************************************************************/
#include "tool_setup.h"
#ifdef _WIN32
#include <direct.h>
#endif
#include "tool_dirhie.h"
#include "tool_msgs.h"
#if defined(_WIN32) || (defined(MSDOS) && !defined(__DJGPP__))
#ifdef _WIN32
# include <direct.h>
# define mkdir(x, y) _mkdir(x)
#elif defined(MSDOS) && !defined(__DJGPP__)
# define mkdir(x, y) (mkdir)(x)
#endif

View file

@ -74,7 +74,7 @@ static char *checkhome(const char *home, const char *fname, bool dotscore)
int fd = curlx_open(c, O_RDONLY);
if(fd >= 0) {
char *path = curlx_strdup(c);
close(fd);
curlx_close(fd);
curl_free(c);
return path;
}

View file

@ -187,7 +187,7 @@ char *getpass_r(const char *prompt, /* prompt to display */
}
if(STDIN_FILENO != fd)
close(fd);
curlx_close(fd);
return password; /* return pointer to buffer */
}

View file

@ -289,7 +289,7 @@ static CURLcode pre_transfer(struct per_transfer *per)
{
helpf("cannot open '%s'", per->uploadfile);
if(per->infd != -1) {
close(per->infd);
curlx_close(per->infd);
per->infd = STDIN_FILENO;
}
return CURLE_READ_ERROR;
@ -621,7 +621,7 @@ static CURLcode post_per_transfer(struct per_transfer *per,
else
#endif
if(per->infdopen)
close(per->infd);
curlx_close(per->infd);
if(per->skip)
goto skip;