build: tidy up and simplify setmode() detection and use

- move macro to `curl_setup.h` (from curlx), and rename.
  It's required by src, test servers, libtests. Also used by unit/tunit,
  (which is fixable but this patch doesn't touch it.)
- special-case it for Windows/Cygwin/MS-DOS.
- build: drop `setmode()`/`_setmode()` detection.
  This also avoids detecting the different `setmode()` on BSDs,
  and a lot of complexity and overhead.
- use `CURL_O_BINARY`.

Follow-up to 250d613763 #15787
Follow-up to 5e70566094 #15169

Closes #20539
This commit is contained in:
Viktor Szakats 2026-02-07 17:57:39 +01:00
parent 2c0019b085
commit cdfc8dc7ad
No known key found for this signature in database
19 changed files with 32 additions and 103 deletions

View file

@ -54,7 +54,6 @@ CURLX_HFILES = \
../lib/curl_setup.h \
../lib/curlx/base64.h \
../lib/curlx/basename.h \
../lib/curlx/binmode.h \
../lib/curlx/dynbuf.h \
../lib/curlx/fopen.h \
../lib/curlx/multibyte.h \

View file

@ -124,7 +124,7 @@ static struct tool_mime *tool_mime_new_filedata(struct tool_mime *parent,
curl_off_t origin;
curlx_struct_stat sbuf;
CURLX_SET_BINMODE(stdin);
CURL_BINMODE(stdin);
origin = ftell(stdin);
/* If stdin is a regular file, do not buffer data but read it
when needed. */

View file

@ -675,7 +675,7 @@ static ParameterError data_urlencode(const char *nextarg,
/* a '@' letter, it means that a filename or - (stdin) follows */
if(!strcmp("-", p)) {
file = stdin;
CURLX_SET_BINMODE(stdin);
CURL_BINMODE(stdin);
}
else {
file = curlx_fopen(p, "rb");
@ -949,7 +949,7 @@ static ParameterError set_data(cmdline_t cmd,
if(!strcmp("-", nextarg)) {
file = stdin;
if(cmd == C_DATA_BINARY) /* forced data-binary */
CURLX_SET_BINMODE(stdin);
CURL_BINMODE(stdin);
}
else {
file = curlx_fopen(nextarg, "rb");

View file

@ -910,7 +910,7 @@ static CURLcode etag_store(struct OperationConfig *config,
}
else {
/* always use binary mode for protocol header output */
CURLX_SET_BINMODE(etag_save->stream);
CURL_BINMODE(etag_save->stream);
}
return CURLE_OK;
}
@ -923,7 +923,7 @@ static CURLcode setup_headerfile(struct OperationConfig *config,
if(!strcmp(config->headerfile, "%")) {
heads->stream = stderr;
/* use binary mode for protocol header output */
CURLX_SET_BINMODE(heads->stream);
CURL_BINMODE(heads->stream);
}
else if(strcmp(config->headerfile, "-")) {
FILE *newfile;
@ -963,7 +963,7 @@ static CURLcode setup_headerfile(struct OperationConfig *config,
}
else {
/* always use binary mode for protocol header output */
CURLX_SET_BINMODE(heads->stream);
CURL_BINMODE(heads->stream);
}
return CURLE_OK;
}
@ -1118,7 +1118,7 @@ static void check_stdin_upload(struct OperationConfig *config,
DEBUGASSERT(per->infdopen == FALSE);
DEBUGASSERT(per->infd == STDIN_FILENO);
CURLX_SET_BINMODE(stdin);
CURL_BINMODE(stdin);
if(!strcmp(per->uploadfile, ".")) {
#if defined(USE_WINSOCK) && !defined(CURL_WINDOWS_UWP)
/* non-blocking stdin behavior on Windows is challenging
@ -1350,7 +1350,7 @@ static CURLcode create_single(struct OperationConfig *config,
!config->use_ascii) {
/* We get the output to stdout and we have not got the ASCII/text flag,
then set stdout to be binary */
CURLX_SET_BINMODE(stdout);
CURL_BINMODE(stdout);
}
/* explicitly passed to stdout means okaying binary gunk */