lib: make CURLX_SET_BINMODE() and use it

Use it from libtests' `first.c` and thus also from units, and tunits.

Also:
- cmake: drop stray `curltool` lib dependency for units.
- units: stop depending on `src` headers.
- tests/server: drop depending on `src` headers.
  (the remaining one listed in the comments, `tool_xattr.h`, was not
  actually used from servers.)
- tests/server: drop duplicate curlx headers.
  (Except `warnless.h`, which is tricky on Windows.)

Closes #17672
This commit is contained in:
Viktor Szakats 2025-06-19 14:05:25 +02:00
parent 35d0c047ce
commit 916f241f2f
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
18 changed files with 29 additions and 44 deletions

View file

@ -45,6 +45,7 @@ CURLX_CFILES = \
../lib/curlx/warnless.c
CURLX_HFILES = \
../lib/curlx/binmode.h \
../lib/curlx/multibyte.h \
../lib/curl_setup.h \
../lib/curlx/dynbuf.h \
@ -105,7 +106,6 @@ CURL_HFILES = \
config2setopts.h \
slist_wc.h \
terminal.h \
tool_binmode.h \
tool_bname.h \
tool_cb_dbg.h \
tool_cb_hdr.h \

View file

@ -1,39 +0,0 @@
#ifndef HEADER_CURL_TOOL_BINMODE_H
#define HEADER_CURL_TOOL_BINMODE_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "tool_setup.h"
#if (defined(HAVE_SETMODE) || defined(HAVE__SETMODE)) && defined(O_BINARY)
/* Requires io.h and/or fcntl.h when available */
#ifdef HAVE__SETMODE
# define CURL_SET_BINMODE(stream) (void)_setmode(fileno(stream), O_BINARY)
#else
# define CURL_SET_BINMODE(stream) (void)setmode(fileno(stream), O_BINARY)
#endif
#else
# define CURL_SET_BINMODE(stream) (void)stream; tool_nop_stmt
#endif
#endif /* HEADER_CURL_TOOL_BINMODE_H */

View file

@ -27,7 +27,6 @@
#include "tool_cfgable.h"
#include "tool_msgs.h"
#include "tool_binmode.h"
#include "tool_getparam.h"
#include "tool_paramhlp.h"
#include "tool_formparse.h"
@ -133,7 +132,7 @@ static struct tool_mime *tool_mime_new_filedata(struct tool_mime *parent,
curl_off_t origin;
struct_stat sbuf;
CURL_SET_BINMODE(stdin);
CURLX_SET_BINMODE(stdin);
origin = ftell(stdin);
/* If stdin is a regular file, do not buffer data but read it
when needed. */

View file

@ -24,7 +24,6 @@
#include "tool_setup.h"
#include <curlx.h>
#include "tool_binmode.h"
#include "tool_cfgable.h"
#include "tool_cb_prg.h"
#include "tool_filetime.h"
@ -625,7 +624,7 @@ static ParameterError data_urlencode(struct GlobalConfig *global,
/* a '@' letter, it means that a filename or - (stdin) follows */
if(!strcmp("-", p)) {
file = stdin;
CURL_SET_BINMODE(stdin);
CURLX_SET_BINMODE(stdin);
}
else {
file = fopen(p, "rb");
@ -901,7 +900,7 @@ static ParameterError set_data(cmdline_t cmd,
if(!strcmp("-", nextarg)) {
file = stdin;
if(cmd == C_DATA_BINARY) /* forced data-binary */
CURL_SET_BINMODE(stdin);
CURLX_SET_BINMODE(stdin);
}
else {
file = fopen(nextarg, "rb");

View file

@ -56,7 +56,6 @@
#include <curlx.h>
#include "tool_binmode.h"
#include "tool_cfgable.h"
#include "tool_cb_dbg.h"
#include "tool_cb_hdr.h"
@ -869,7 +868,7 @@ static CURLcode etag_store(struct GlobalConfig *global,
}
else {
/* always use binary mode for protocol header output */
CURL_SET_BINMODE(etag_save->stream);
CURLX_SET_BINMODE(etag_save->stream);
}
return CURLE_OK;
}
@ -883,7 +882,7 @@ static CURLcode setup_headerfile(struct GlobalConfig *global,
if(!strcmp(config->headerfile, "%")) {
heads->stream = stderr;
/* use binary mode for protocol header output */
CURL_SET_BINMODE(heads->stream);
CURLX_SET_BINMODE(heads->stream);
}
else if(strcmp(config->headerfile, "-")) {
FILE *newfile;
@ -923,7 +922,7 @@ static CURLcode setup_headerfile(struct GlobalConfig *global,
}
else {
/* always use binary mode for protocol header output */
CURL_SET_BINMODE(heads->stream);
CURLX_SET_BINMODE(heads->stream);
}
return CURLE_OK;
}
@ -1065,7 +1064,7 @@ static void check_stdin_upload(struct GlobalConfig *global,
DEBUGASSERT(per->infdopen == FALSE);
DEBUGASSERT(per->infd == STDIN_FILENO);
CURL_SET_BINMODE(stdin);
CURLX_SET_BINMODE(stdin);
if(!strcmp(per->uploadfile, ".")) {
if(curlx_nonblock((curl_socket_t)per->infd, TRUE) < 0)
warnf(global,
@ -1345,7 +1344,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
!config->use_ascii) {
/* We get the output to stdout and we have not got the ASCII/text
flag, then set stdout to be binary */
CURL_SET_BINMODE(stdout);
CURLX_SET_BINMODE(stdout);
}
/* explicitly passed to stdout means okaying binary gunk */