aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2022-04-23 12:25:36 +0100
committerRon Yorston <rmy@pobox.com>2022-04-23 12:25:36 +0100
commit2f0c3703f803e3011d8f0fdd618c796ada7b2925 (patch)
tree9fc429622d1e94f33594cb900570e3713785543b
parent037037df6cdc567132acbeeb2067c442f945889e (diff)
downloadbusybox-w32-2f0c3703f803e3011d8f0fdd618c796ada7b2925.tar.gz
busybox-w32-2f0c3703f803e3011d8f0fdd618c796ada7b2925.tar.bz2
busybox-w32-2f0c3703f803e3011d8f0fdd618c796ada7b2925.zip
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().
-rw-r--r--win32/popen.c23
1 files 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)
144 } 144 }
145 cmd_buff[0] = '\0'; 145 cmd_buff[0] = '\0';
146 146
147#if (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE) && \ 147#if ENABLE_FEATURE_PREFER_APPLETS && NUM_APPLETS > 1
148 NUM_APPLETS > 1
149 if (find_applet_by_name("sh") >= 0) { 148 if (find_applet_by_name("sh") >= 0) {
150 sprintf(cmd_buff, "%s --busybox ", bb_busybox_exec_path); 149 sprintf(cmd_buff, "%s --busybox ", bb_busybox_exec_path);
151 } 150 }
@@ -315,17 +314,23 @@ pid_t mingw_fork_compressor(int fd, const char *compressor, const char *mode)
315 int fd1; 314 int fd1;
316 pid_t pid; 315 pid_t pid;
317 316
318 if (find_applet_by_name(compressor) < 0 317#if ENABLE_FEATURE_PREFER_APPLETS && NUM_APPLETS > 1
319#if ENABLE_XZ || ENABLE_LZMA 318 if (find_applet_by_name(compressor) >= 0
319# if ENABLE_XZ || ENABLE_LZMA
320 /* xz and lzma applets don't support compression, try using 320 /* xz and lzma applets don't support compression, try using
321 * an external program */ 321 * an external program */
322 || (mode[0] == 'w' && index_in_strings("lzma\0xz\0", compressor) >= 0) 322 && !(mode[0] == 'w' && index_in_strings("lzma\0xz\0", compressor) >= 0)
323#endif 323# endif
324 ) 324 ) {
325 cmd = xasprintf("%s -cf -", compressor);
326 else
327 cmd = xasprintf("%s --busybox %s -cf -", bb_busybox_exec_path, 325 cmd = xasprintf("%s --busybox %s -cf -", bb_busybox_exec_path,
328 compressor); 326 compressor);
327 } else {
328 // share format string
329 cmd = xasprintf("%s --busybox %s -cf -" + 13, compressor);
330 }
331#else
332 cmd = xasprintf("%s -cf -", compressor);
333#endif
329 334
330 if ((fd1 = mingw_popen_fd(cmd, mode, fd, &pid)) == -1) 335 if ((fd1 = mingw_popen_fd(cmd, mode, fd, &pid)) == -1)
331 bb_perror_msg_and_die("can't execute '%s'", compressor); 336 bb_perror_msg_and_die("can't execute '%s'", compressor);