build: tidy up curl-specific fstat calls and stat struct type

To avoid redefining the `fstat` system symbol, and to clarify
`struct_stat` is a curl symbol.

- introduce `curlx_fstat()` macro and use it.
- rename `struct_stat` to `curl_struct_stat`.

Also:
- tests: replace direct `curlx_win32_stat()` call with `curlx_stat()`.
- checksrc: disallow direct `_fstati64` and `fstat()` calls, except in
  examples.

Closes #20496
This commit is contained in:
Viktor Szakats 2026-02-02 13:14:30 +01:00
parent 9630593650
commit a84b041281
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
22 changed files with 53 additions and 50 deletions

View file

@ -291,7 +291,7 @@ static SANITIZEcode rename_if_reserved_dos(char ** const sanitized,
* to rename such files. */
char *p, *base, *buffer;
#ifdef MSDOS
struct_stat st_buf;
curl_struct_stat st_buf;
#endif
size_t len, bufsize;

View file

@ -68,7 +68,7 @@ int getfiletime(const char *filename, curl_off_t *stamp)
GetLastError());
}
#else
struct_stat statbuf;
curl_struct_stat statbuf;
if(curlx_stat(filename, &statbuf) != -1) {
*stamp = (curl_off_t)statbuf.st_mtime;
rc = 0;

View file

@ -122,13 +122,13 @@ static struct tool_mime *tool_mime_new_filedata(struct tool_mime *parent,
char *data = NULL;
curl_off_t size;
curl_off_t origin;
struct_stat sbuf;
curl_struct_stat sbuf;
CURLX_SET_BINMODE(stdin);
origin = ftell(stdin);
/* If stdin is a regular file, do not buffer data but read it
when needed. */
if(fd >= 0 && origin >= 0 && !fstat(fd, &sbuf) &&
if(fd >= 0 && origin >= 0 && !curlx_fstat(fd, &sbuf) &&
#ifdef __VMS
sbuf.st_fab_rfm != FAB$C_VAR && sbuf.st_fab_rfm != FAB$C_VFC &&
#endif

View file

@ -2209,7 +2209,7 @@ static ParameterError existingfile(char **store,
const struct LongShort *a,
const char *filename)
{
struct_stat info;
curl_struct_stat info;
if(curlx_stat(filename, &info)) {
errorf("The file '%s' provided to --%s does not exist",
filename, a->lname);

View file

@ -146,7 +146,7 @@ static bool is_pkcs11_uri(const char *string)
*
*/
static curl_off_t vms_realfilesize(const char *name,
const struct_stat *stat_buf)
const curl_struct_stat *stat_buf)
{
char buffer[8192];
curl_off_t count;
@ -176,7 +176,8 @@ static curl_off_t vms_realfilesize(const char *name,
* if not to call a routine to get the correct size.
*
*/
static curl_off_t VmsSpecialSize(const char *name, const struct_stat *stat_buf)
static curl_off_t VmsSpecialSize(const char *name,
const curl_struct_stat *stat_buf)
{
switch(stat_buf->st_fab_rfm) {
case FAB$C_VAR:
@ -247,7 +248,7 @@ static struct per_transfer *del_per_transfer(struct per_transfer *per)
static CURLcode pre_transfer(struct per_transfer *per)
{
curl_off_t uploadfilesize = -1;
struct_stat fileinfo;
curl_struct_stat fileinfo;
CURLcode result = CURLE_OK;
if(per->uploadfile && !stdin_upload(per->uploadfile)) {
@ -284,7 +285,7 @@ static CURLcode pre_transfer(struct per_transfer *per)
if(per->infd == -1)
#else
per->infd = curlx_open(per->uploadfile, O_RDONLY | CURL_O_BINARY);
if((per->infd == -1) || fstat(per->infd, &fileinfo))
if((per->infd == -1) || curlx_fstat(per->infd, &fileinfo))
#endif
{
helpf("cannot open '%s'", per->uploadfile);
@ -547,11 +548,11 @@ static CURLcode retrycheck(struct OperationConfig *config,
}
if(truncate && outs->bytes && outs->filename && outs->stream) {
struct_stat fileinfo;
curl_struct_stat fileinfo;
/* The output can be a named pipe or a character device etc that
cannot be truncated. Only truncate regular files. */
if(!fstat(fileno(outs->stream), &fileinfo) &&
if(!curlx_fstat(fileno(outs->stream), &fileinfo) &&
S_ISREG(fileinfo.st_mode)) {
int rc;
/* We have written data to an output file, we truncate file */
@ -717,7 +718,7 @@ static CURLcode post_per_transfer(struct per_transfer *per,
errorf("curl: (%d) Failed writing body", result);
}
if(result && config->rm_partial) {
struct_stat st;
curl_struct_stat st;
if(!curlx_stat(outs->filename, &st) && S_ISREG(st.st_mode)) {
if(!unlink(outs->filename))
notef("Removed output file: %s", outs->filename);
@ -1039,7 +1040,7 @@ static CURLcode setup_outfile(struct OperationConfig *config,
}
if(config->skip_existing) {
struct_stat fileinfo;
curl_struct_stat fileinfo;
if(!curlx_stat(per->outfile, &fileinfo)) {
/* file is present */
notef("skips transfer, \"%s\" exists locally", per->outfile);
@ -1051,7 +1052,7 @@ static CURLcode setup_outfile(struct OperationConfig *config,
if(config->resume_from_current) {
/* We are told to continue from where we are now. Get the size
of the file as it is now and open it for append instead */
struct_stat fileinfo;
curl_struct_stat fileinfo;
/* VMS -- Danger, the filesize is only valid for stream files */
if(curlx_stat(per->outfile, &fileinfo) == 0)
/* set offset to current file size: */