build: avoid overriding system open and stat symbols

Replace them by `curlx_open()` and `curlx_stat()`.

To make it obvious in the source code what is being executed.

Also:
- tests/server: stop overriding `open()` for test servers.
  This is critical for the call made from the signal handler.
  For other calls, it's an option to use `curlx_open()`, but
  doesn't look important enough to do it, following the path
  taken with `fopen()`.

Follow-up to 10bac43b87 #18774
Follow-up to 20142f5d06 #18634
Follow-up to bf7375ecc5 #18503

Closes #18776
This commit is contained in:
Viktor Szakats 2025-09-30 01:27:10 +02:00
parent 684f4cdd3e
commit 9678ff5b1b
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
31 changed files with 76 additions and 83 deletions

View file

@ -23,11 +23,6 @@
***************************************************************************/
#include "tool_setup.h"
#ifdef HAVE_FCNTL_H
/* for open() */
#include <fcntl.h>
#endif
#include "tool_cfgable.h"
#include "tool_msgs.h"
#include "tool_cb_wrt.h"
@ -60,7 +55,8 @@ bool tool_create_output_file(struct OutStruct *outs,
else {
int fd;
do {
fd = open(fname, O_CREAT | O_WRONLY | O_EXCL | CURL_O_BINARY, OPENMODE);
fd = curlx_open(fname, O_CREAT | O_WRONLY | O_EXCL | CURL_O_BINARY,
OPENMODE);
/* Keep retrying in the hope that it is not interrupted sometime */
/* !checksrc! disable ERRNOVAR 1 */
} while(fd == -1 && errno == EINTR);
@ -78,8 +74,9 @@ bool tool_create_output_file(struct OutStruct *outs,
return FALSE;
next_num++;
do {
fd = open(curlx_dyn_ptr(&fbuffer),
O_CREAT | O_WRONLY | O_EXCL | CURL_O_BINARY, OPENMODE);
fd = curlx_open(curlx_dyn_ptr(&fbuffer),
O_CREAT | O_WRONLY | O_EXCL | CURL_O_BINARY,
OPENMODE);
/* Keep retrying in the hope that it is not interrupted sometime */
} while(fd == -1 && errno == EINTR);
}

View file

@ -532,7 +532,7 @@ static SANITIZEcode rename_if_reserved_dos(char **const sanitized,
identify whether it is a reserved device name and not a regular
filename. */
#ifdef MSDOS
if(base && ((stat(base, &st_buf)) == 0) && (S_ISCHR(st_buf.st_mode))) {
if(base && (curlx_stat(base, &st_buf) == 0) && S_ISCHR(st_buf.st_mode)) {
/* Prepend a '_' */
size_t blen = strlen(base);
if(blen) {

View file

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

View file

@ -33,10 +33,6 @@
#endif
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#include "tool_findfile.h"
#include "tool_cfgable.h"
@ -77,7 +73,7 @@ static char *checkhome(const char *home, const char *fname, bool dotscore)
else
c = aprintf("%s" DIR_CHAR "%s", home, fname);
if(c) {
int fd = open(c, O_RDONLY);
int fd = curlx_open(c, O_RDONLY);
if(fd >= 0) {
char *path = strdup(c);
close(fd);

View file

@ -30,10 +30,6 @@
#ifndef HAVE_GETPASS_R
/* this file is only for systems without getpass_r() */
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
#ifdef HAVE_TERMIOS_H
# include <termios.h>
#elif defined(HAVE_TERMIO_H)
@ -178,7 +174,7 @@ char *getpass_r(const char *prompt, /* prompt to display */
{
ssize_t nread;
bool disabled;
int fd = open("/dev/tty", O_RDONLY);
int fd = curlx_open("/dev/tty", O_RDONLY);
if(fd == -1)
fd = STDIN_FILENO; /* use stdin if the tty could not be used */

View file

@ -23,10 +23,6 @@
***************************************************************************/
#include "tool_setup.h"
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
#ifdef HAVE_LOCALE_H
# include <locale.h>
#endif
@ -279,22 +275,22 @@ static CURLcode pre_transfer(struct per_transfer *per)
#ifdef __VMS
/* Calculate the real upload size for VMS */
per->infd = -1;
if(stat(per->uploadfile, &fileinfo) == 0) {
if(curlx_stat(per->uploadfile, &fileinfo) == 0) {
fileinfo.st_size = VmsSpecialSize(uploadfile, &fileinfo);
switch(fileinfo.st_fab_rfm) {
case FAB$C_VAR:
case FAB$C_VFC:
case FAB$C_STMCR:
per->infd = open(per->uploadfile, O_RDONLY | CURL_O_BINARY);
per->infd = curlx_open(per->uploadfile, O_RDONLY | CURL_O_BINARY);
break;
default:
per->infd = open(per->uploadfile, O_RDONLY | CURL_O_BINARY,
"rfm=stmlf", "ctx=stm");
per->infd = curlx_open(per->uploadfile, O_RDONLY | CURL_O_BINARY,
"rfm=stmlf", "ctx=stm");
}
}
if(per->infd == -1)
#else
per->infd = open(per->uploadfile, O_RDONLY | CURL_O_BINARY);
per->infd = curlx_open(per->uploadfile, O_RDONLY | CURL_O_BINARY);
if((per->infd == -1) || fstat(per->infd, &fileinfo))
#endif
{
@ -668,8 +664,7 @@ static CURLcode post_per_transfer(struct per_transfer *per,
}
if(result && config->rm_partial) {
struct_stat st;
if(!stat(outs->filename, &st) &&
S_ISREG(st.st_mode)) {
if(!curlx_stat(outs->filename, &st) && S_ISREG(st.st_mode)) {
if(!unlink(outs->filename))
notef("Removed output file: %s", outs->filename);
else
@ -974,7 +969,7 @@ static CURLcode setup_outfile(struct OperationConfig *config,
if(config->skip_existing) {
struct_stat fileinfo;
if(!stat(per->outfile, &fileinfo)) {
if(!curlx_stat(per->outfile, &fileinfo)) {
/* file is present */
notef("skips transfer, \"%s\" exists locally", per->outfile);
per->skip = TRUE;
@ -987,7 +982,7 @@ static CURLcode setup_outfile(struct OperationConfig *config,
of the file as it is now and open it for append instead */
struct_stat fileinfo;
/* VMS -- Danger, the filesize is only valid for stream files */
if(stat(per->outfile, &fileinfo) == 0)
if(curlx_stat(per->outfile, &fileinfo) == 0)
/* set offset to current file size: */
config->resume_from = fileinfo.st_size;
else