]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib: make `CURLX_SET_BINMODE()` and use it
authorViktor Szakats <commit@vsz.me>
Thu, 19 Jun 2025 12:05:25 +0000 (14:05 +0200)
committerViktor Szakats <commit@vsz.me>
Thu, 19 Jun 2025 13:57:37 +0000 (15:57 +0200)
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

18 files changed:
lib/Makefile.inc
lib/curlx/binmode.h [moved from src/tool_binmode.h with 85% similarity]
lib/curlx/curlx.h
src/Makefile.inc
src/tool_formparse.c
src/tool_getparam.c
src/tool_operate.c
tests/libtest/CMakeLists.txt
tests/libtest/Makefile.am
tests/libtest/first.c
tests/server/CMakeLists.txt
tests/server/Makefile.am
tests/server/mqttd.c
tests/server/sockfilt.c
tests/server/socksd.c
tests/server/sws.c
tests/unit/CMakeLists.txt
tests/unit/Makefile.am

index 8e33a23f6cc0b87b4bc7d03c4646d6636d2ea1df..257e104de94fb52d573e86d7d53980288f3bd4ae 100644 (file)
@@ -39,6 +39,7 @@ LIB_CURLX_CFILES = \
   curlx/winapi.c
 
 LIB_CURLX_HFILES = \
+  curlx/binmode.h  \
   curlx/base64.h   \
   curlx/curlx.h    \
   curlx/dynbuf.h   \
similarity index 85%
rename from src/tool_binmode.h
rename to lib/curlx/binmode.h
index 4da6fb73e1368a78943753c67bafdfd088b3bfc6..3f356edd597c2ed7abc183d6dca56741c6961de1 100644 (file)
  * SPDX-License-Identifier: curl
  *
  ***************************************************************************/
-#include "tool_setup.h"
+#include "../curl_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)
+#  define CURLX_SET_BINMODE(stream)  (void)_setmode(fileno(stream), O_BINARY)
 #else
-#  define CURL_SET_BINMODE(stream)  (void)setmode(fileno(stream), O_BINARY)
+#  define CURLX_SET_BINMODE(stream)  (void)setmode(fileno(stream), O_BINARY)
 #endif
 #else
-#  define CURL_SET_BINMODE(stream)  (void)stream; tool_nop_stmt
+#  define CURLX_SET_BINMODE(stream)  (void)stream; Curl_nop_stmt
 #endif
 
 #endif /* HEADER_CURL_TOOL_BINMODE_H */
index 5b97ec5b83da137cb6678f0dee30f22b36c6353e..9f7bd3a975eafb24f8c320e322929af3827fa109 100644 (file)
@@ -31,6 +31,9 @@
  * be.
  */
 
+#include "binmode.h"
+/* "binmode.h" provides macro CURLX_SET_BINMODE() */
+
 #include "nonblock.h"
 /* "nonblock.h" provides curlx_nonblock() */
 
index a4c3ca453a2ebfc28f9e1fc7e423a48c4e052499..9b183260ddf1f0649873a678127804a47d3aeade 100644 (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 \
index 2273b69dd301432b56e6e5a07476e1f80ecfc05b..748bcb29a280eb28b3266758e06e86726f45344e 100644 (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. */
index a72a010ce4e6907b0e6c72111aa72af534224d55..cc1cd3f3b16dc3c26df684dcd6bc067843d6ad6e 100644 (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");
index a52439caf811ee57d4369f2fe44b8a5e2e5a90dd..5f52838ce820aacd0762c685b9651df82d37b431 100644 (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 */
index 1d485d17d80a01dd373d64984f62b615957b48b5..f8dedc5c43648eb3a9b28b49c1d8f09237084f11 100644 (file)
@@ -54,7 +54,6 @@ target_include_directories(${BUNDLE} PRIVATE
   "${PROJECT_BINARY_DIR}/lib"            # for "curl_config.h"
   "${PROJECT_SOURCE_DIR}/lib"            # for "curl_setup.h"
   "${PROJECT_SOURCE_DIR}/lib/curlx"      # for curlx
-  "${PROJECT_SOURCE_DIR}/src"            # for "tool_binmode.h"
   "${CMAKE_CURRENT_SOURCE_DIR}"          # for the generated bundle source to find included test sources
   "${PROJECT_SOURCE_DIR}/tests/unit"     # for "curlcheck.h"
 )
index 0db7a0e349085e3615a647b4d191bf9b2034a67d..46e3ccce79aee1f62510061289951bb94a9d6953 100644 (file)
@@ -37,7 +37,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/include        \
               -I$(top_builddir)/lib          \
               -I$(top_srcdir)/lib            \
               -I$(top_srcdir)/lib/curlx      \
-              -I$(top_srcdir)/src            \
               -I$(srcdir)                    \
               -I$(top_srcdir)/tests/unit
 
index 2a828a1b3fcd0fa702a8cb8bc035d82f5932ff01..b6bf2b1b9b28ac7432dde4e2d05eb68d8aec206c 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "memdebug.h"
 #include "curlx/timediff.h"
-#include "tool_binmode.h"
+#include "curlx/binmode.h"
 
 int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
                    struct timeval *tv)
@@ -107,7 +107,7 @@ int main(int argc, char **argv)
   char *env;
   size_t tmp;
 
-  CURL_SET_BINMODE(stdout);
+  CURLX_SET_BINMODE(stdout);
 
   memory_tracking_init();
 
index 4ad9cc55fecb7b8e790a481e0ddb90630a9735ed..0cdf890e5cdfa9ac03e06b8619984d133ba5816a 100644 (file)
@@ -42,7 +42,6 @@ target_include_directories(${BUNDLE} PRIVATE
   "${PROJECT_BINARY_DIR}/lib"            # for "curl_config.h"
   "${PROJECT_SOURCE_DIR}/lib"            # for "curl_setup.h"
   "${PROJECT_SOURCE_DIR}/lib/curlx"      # for curlx
-  "${PROJECT_SOURCE_DIR}/src"            # for "tool_binmode.h", "tool_xattr.h"
   "${CMAKE_CURRENT_SOURCE_DIR}"          # for the generated bundle source to find included test sources
 )
 set_property(TARGET ${BUNDLE} APPEND PROPERTY COMPILE_DEFINITIONS "WITHOUT_LIBCURL")
index 36b40084372160b0a466663a7b1fd5660beb0251..41b1c86d79743c50354d507a01c73793bcdbcedf 100644 (file)
@@ -31,14 +31,12 @@ AUTOMAKE_OPTIONS = foreign nostdinc
 # $(top_srcdir)/include is for libcurl's external include files
 # $(top_builddir)/lib is for libcurl's generated lib/curl_config.h file
 # $(top_srcdir)/lib for libcurl's lib/curl_setup.h and other "borrowed" files
-# $(top_srcdir)/src for "tool_binmode.h", "tool_xattr.h"
 # $(srcdir) for the generated bundle source to find included test sources
 
 AM_CPPFLAGS = -I$(top_srcdir)/include        \
               -I$(top_builddir)/lib          \
               -I$(top_srcdir)/lib            \
               -I$(top_srcdir)/lib/curlx      \
-              -I$(top_srcdir)/src            \
               -I$(srcdir)
 
 # Get BUNDLE, BUNDLE_SRC, FIRSTFILES, UTILS, CURLX_SRCS, TESTFILES variables
index db5007f109c06007a6fcc306f4c0ac7158585747..57ebf22a500784eddd05963939397d319cef36c6 100644 (file)
@@ -55,8 +55,6 @@
 #include <curlx.h> /* from the private lib dir */
 #include "getpart.h"
 
-#include "tool_binmode.h"
-
 /* include memdebug.h last */
 #include <memdebug.h>
 
@@ -985,9 +983,9 @@ static int test_mqttd(int argc, char *argv[])
     return 2;
 #endif
 
-  CURL_SET_BINMODE(stdin);
-  CURL_SET_BINMODE(stdout);
-  CURL_SET_BINMODE(stderr);
+  CURLX_SET_BINMODE(stdin);
+  CURLX_SET_BINMODE(stdout);
+  CURLX_SET_BINMODE(stderr);
 
   install_signal_handlers(FALSE);
 
index b4e62a50bb4a7bf84d7ad5394b752e05a18a5976..9728abfadf09e2825108cff9979af0c53a476bcc 100644 (file)
 #endif
 
 #include <curlx.h> /* from the private lib dir */
-#include "inet_pton.h"
-#include "timediff.h"
 #include "warnless.h" /* for read() */
 
-#include "tool_binmode.h"
-
 /* include memdebug.h last */
 #include <memdebug.h>
 
@@ -1495,9 +1491,9 @@ static int test_sockfilt(int argc, char *argv[])
     return 2;
 #endif
 
-  CURL_SET_BINMODE(stdin);
-  CURL_SET_BINMODE(stdout);
-  CURL_SET_BINMODE(stderr);
+  CURLX_SET_BINMODE(stdin);
+  CURLX_SET_BINMODE(stdout);
+  CURLX_SET_BINMODE(stderr);
 
   install_signal_handlers(false);
 
index af8083bbdb931d3c382f0e8877b99f6c7c15252a..b6d7794c8a206d27be567edbf7a7858731efd156 100644 (file)
@@ -74,8 +74,6 @@
 #endif
 
 #include <curlx.h> /* from the private lib dir */
-#include "inet_pton.h"
-#include "tool_binmode.h"
 
 /* include memdebug.h last */
 #include <memdebug.h>
@@ -1043,9 +1041,9 @@ static int test_socksd(int argc, char *argv[])
     return 2;
 #endif
 
-  CURL_SET_BINMODE(stdin);
-  CURL_SET_BINMODE(stdout);
-  CURL_SET_BINMODE(stderr);
+  CURLX_SET_BINMODE(stdin);
+  CURLX_SET_BINMODE(stdout);
+  CURLX_SET_BINMODE(stderr);
 
   install_signal_handlers(false);
 
index 553030e61d0ffa1f1d69d817302f04ca6464ea72..4e78649bc892ff92caedf5249a2514eec83f1180 100644 (file)
@@ -51,7 +51,6 @@
 
 #include <curlx.h> /* from the private lib dir */
 #include "getpart.h"
-#include "inet_pton.h"
 
 /* include memdebug.h last */
 #include <memdebug.h>
index 5d776e8544e92a2d656bec2560d19a4d346de2dc..947b7f42123229fd00dcd6276c762cb60613ffb6 100644 (file)
@@ -35,12 +35,11 @@ add_custom_command(OUTPUT "${BUNDLE_SRC}"
 
 add_executable(${BUNDLE} EXCLUDE_FROM_ALL ${UTILS} "${BUNDLE_SRC}")
 add_dependencies(testdeps ${BUNDLE})
-target_link_libraries(${BUNDLE} curltool curlu)
+target_link_libraries(${BUNDLE} curlu)
 target_include_directories(${BUNDLE} PRIVATE
   "${PROJECT_BINARY_DIR}/lib"            # for "curl_config.h"
   "${PROJECT_SOURCE_DIR}/lib"            # for "curl_setup.h"
   "${PROJECT_SOURCE_DIR}/lib/curlx"      # for curlx
-  "${PROJECT_SOURCE_DIR}/src"            # for "tool_binmode.h"
   "${PROJECT_SOURCE_DIR}/tests/libtest"  # for "first.h"
   "${CMAKE_CURRENT_SOURCE_DIR}"          # for the generated bundle source to find included test sources
 )
index e3cf2cc4a062ee34ced466ed17f68c54c70f24d0..162977ee03dddc1baa8559cf80a6840d219b7403 100644 (file)
@@ -37,7 +37,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/include        \
               -I$(top_builddir)/lib          \
               -I$(top_srcdir)/lib            \
               -I$(top_srcdir)/lib/curlx      \
-              -I$(top_srcdir)/src            \
               -I$(top_srcdir)/tests/libtest  \
               -I$(srcdir)