windows: fixup fopen() in CURLDEBUG builds

Introduce an immutable `CURL_FOPEN()` macro to store the `fopen()`
mapping on Windows. Then use that instead `(fopen)` from `memdebug.c`.
It makes CURLDEBUG builds use the correct `fopen` wrapper on Windows.
This macro is only defined on Windows, as of this patch.

This is necessary after cde81e4398,
which no longer applies the default `fopen()` override to `memdebug.c`.

Also:
- curl_setup.h: de-dupe, simplify Windows file I/O function overrides.
- curl_memory.h: fix to reset `fopen` to `curlx_win32_fopen()` on
  Windows. Before this patch it reset it to stock `fopen()`.

Follow-up to cde81e4398 #17631

Closes #16747
This commit is contained in:
Viktor Szakats 2025-06-16 10:16:17 +02:00
parent cde81e4398
commit 6828009695
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
3 changed files with 44 additions and 48 deletions

View file

@ -78,7 +78,11 @@ void curl_dbg_memdebug(const char *logname)
{
if(!curl_dbg_logfile) {
if(logname && *logname)
#ifdef CURL_FOPEN
curl_dbg_logfile = CURL_FOPEN(logname, FOPEN_WRITETEXT);
#else
curl_dbg_logfile = (fopen)(logname, FOPEN_WRITETEXT);
#endif
else
curl_dbg_logfile = stderr;
#ifdef MEMDEBUG_LOG_SYNC
@ -414,7 +418,12 @@ ALLOC_FUNC
FILE *curl_dbg_fopen(const char *file, const char *mode,
int line, const char *source)
{
FILE *res = (fopen)(file, mode);
FILE *res;
#ifdef CURL_FOPEN
res = CURL_FOPEN(file, mode);
#else
res = (fopen)(file, mode);
#endif
if(source)
curl_dbg_log("FILE %s:%d fopen(\"%s\",\"%s\") = %p\n",