From 2f0c3703f803e3011d8f0fdd618c796ada7b2925 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 23 Apr 2022 12:25:36 +0100 Subject: win32: proper conditional compilation in popen.c In mingw_fork_compressor() the code to prefer applets over external programs should be conditionally compiled based on the setting of ENABLE_FEATURE_PREFER_APPLETS. In mingw_popen() there's no need to use ENABLE_FEATURE_SH_STANDALONE for the same purpose. ENABLE_FEATURE_PREFER_APPLETS is sufficient. Save a few bytes by sharing a format string in mingw_fork_compressor(). --- win32/popen.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/win32/popen.c b/win32/popen.c index c9ea00ffd..2208aa6bb 100644 --- a/win32/popen.c +++ b/win32/popen.c @@ -144,8 +144,7 @@ FILE *mingw_popen(const char *cmd, const char *mode) } cmd_buff[0] = '\0'; -#if (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE) && \ - NUM_APPLETS > 1 +#if ENABLE_FEATURE_PREFER_APPLETS && NUM_APPLETS > 1 if (find_applet_by_name("sh") >= 0) { sprintf(cmd_buff, "%s --busybox ", bb_busybox_exec_path); } @@ -315,17 +314,23 @@ pid_t mingw_fork_compressor(int fd, const char *compressor, const char *mode) int fd1; pid_t pid; - if (find_applet_by_name(compressor) < 0 -#if ENABLE_XZ || ENABLE_LZMA +#if ENABLE_FEATURE_PREFER_APPLETS && NUM_APPLETS > 1 + if (find_applet_by_name(compressor) >= 0 +# if ENABLE_XZ || ENABLE_LZMA /* xz and lzma applets don't support compression, try using * an external program */ - || (mode[0] == 'w' && index_in_strings("lzma\0xz\0", compressor) >= 0) -#endif - ) - cmd = xasprintf("%s -cf -", compressor); - else + && !(mode[0] == 'w' && index_in_strings("lzma\0xz\0", compressor) >= 0) +# endif + ) { cmd = xasprintf("%s --busybox %s -cf -", bb_busybox_exec_path, compressor); + } else { + // share format string + cmd = xasprintf("%s --busybox %s -cf -" + 13, compressor); + } +#else + cmd = xasprintf("%s -cf -", compressor); +#endif if ((fd1 = mingw_popen_fd(cmd, mode, fd, &pid)) == -1) bb_perror_msg_and_die("can't execute '%s'", compressor); -- cgit v1.2.3-55-g6feb