curlx: add and use curlx_freopen()

To complement the existing `curlx_fopen()` internal API.
It's used by the curl's `--stderr` option.

`curlx_freopen()` adds two features to the bare `freopen()`:
- tracing for debug-enabled builds.
- Unicode and long-filename support for Windows builds.

In effect this adds long-filename and enables Unicode support for
the `--stderr <filename>` curl command-line option on Windows.

Also add to checksrc.

Follow-up to 2f17a9b654 #10673

Closes #19598
This commit is contained in:
Viktor Szakats 2025-11-19 01:10:48 +01:00
parent 2decbb1c1f
commit 3d80d37cf0
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
7 changed files with 68 additions and 11 deletions

View file

@ -29,7 +29,7 @@
#include <curl/curl.h>
#include "urldata.h"
#include "curlx/fopen.h" /* for CURLX_FOPEN_LOW() */
#include "curlx/fopen.h" /* for CURLX_FOPEN_LOW(), CURLX_FREOPEN_LOW() */
/* The last 2 #include files should be in this order */
#include "curl_memory.h"
@ -424,7 +424,19 @@ FILE *curl_dbg_fopen(const char *file, const char *mode,
FILE *res = CURLX_FOPEN_LOW(file, mode);
if(source)
curl_dbg_log("FILE %s:%d fopen(\"%s\",\"%s\") = %p\n",
source, line, file, mode, (void *)res);
source, line, file, mode, (void *)res);
return res;
}
ALLOC_FUNC
FILE *curl_dbg_freopen(const char *file, const char *mode, FILE *fh,
int line, const char *source)
{
FILE *res = CURLX_FREOPEN_LOW(file, mode, fh);
if(source)
curl_dbg_log("FILE %s:%d freopen(\"%s\",\"%s\",%p) = %p\n",
source, line, file, mode, (void *)fh, (void *)res);
return res;
}