aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-04-23 09:00:04 +0100
committerRon Yorston <rmy@pobox.com>2023-04-23 09:04:01 +0100
commit0575aaaa0779812752427badbc0f80a09aac02a4 (patch)
tree350b636dad1766e43d1d0c7d132a895c3cc2a628
parent7b81a44c87cf71dfb4f647ba107624e208ffbefe (diff)
downloadbusybox-w32-0575aaaa0779812752427badbc0f80a09aac02a4.tar.gz
busybox-w32-0575aaaa0779812752427badbc0f80a09aac02a4.tar.bz2
busybox-w32-0575aaaa0779812752427badbc0f80a09aac02a4.zip
win32: export xappendword()
Export the function xappendword() from make. Use it in drop and watch. Saves 8-80 bytes, an unusually large disparity.
-rw-r--r--include/mingw.h1
-rw-r--r--miscutils/drop.c4
-rw-r--r--miscutils/make.c13
-rw-r--r--procps/watch.c7
-rw-r--r--win32/mingw.c12
5 files changed, 21 insertions, 16 deletions
diff --git a/include/mingw.h b/include/mingw.h
index 3cf0526f2..c2c37ba48 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -594,3 +594,4 @@ const char *applet_to_exe(const char *name);
594char *get_user_name(void); 594char *get_user_name(void);
595char *quote_arg(const char *arg); 595char *quote_arg(const char *arg);
596char *find_first_executable(const char *name); 596char *find_first_executable(const char *name);
597char *xappendword(const char *str, const char *word);
diff --git a/miscutils/drop.c b/miscutils/drop.c
index db3d709d1..342de41d6 100644
--- a/miscutils/drop.c
+++ b/miscutils/drop.c
@@ -165,10 +165,8 @@ int drop_main(int argc, char **argv)
165 // Build the command line 165 // Build the command line
166 while (*a) { 166 while (*a) {
167 char *q = quote_arg(*a++); 167 char *q = quote_arg(*a++);
168 char *newcmd = xasprintf("%s %s", cmd, q); 168 cmd = xappendword(cmd, q);
169 free(q); 169 free(q);
170 free(cmd);
171 cmd = newcmd;
172 } 170 }
173 171
174 ZeroMemory(&si, sizeof(STARTUPINFO)); 172 ZeroMemory(&si, sizeof(STARTUPINFO));
diff --git a/miscutils/make.c b/miscutils/make.c
index eddc07126..07d824752 100644
--- a/miscutils/make.c
+++ b/miscutils/make.c
@@ -333,19 +333,6 @@ auto_concat(const char *s1, const char *s2)
333 return auto_string(xasprintf("%s%s", s1, s2)); 333 return auto_string(xasprintf("%s%s", s1, s2));
334} 334}
335 335
336/*
337 * Append a word to a space-separated string of words. The first
338 * call should use a NULL pointer for str, subsequent calls should
339 * pass an allocated string which will be freed.
340 */
341static char *
342xappendword(const char *str, const char *word)
343{
344 char *newstr = str ? xasprintf("%s %s", str, word) : xstrdup(word);
345 free((void *)str);
346 return newstr;
347}
348
349static unsigned int 336static unsigned int
350getbucket(const char *name) 337getbucket(const char *name)
351{ 338{
diff --git a/procps/watch.c b/procps/watch.c
index 1190b29df..56b128df6 100644
--- a/procps/watch.c
+++ b/procps/watch.c
@@ -71,9 +71,16 @@ int watch_main(int argc UNUSED_PARAM, char **argv)
71 71
72 // watch from both procps 2.x and 3.x does concatenation. Example: 72 // watch from both procps 2.x and 3.x does concatenation. Example:
73 // watch ls -l "a /tmp" "2>&1" - ls won't see "a /tmp" as one param 73 // watch ls -l "a /tmp" "2>&1" - ls won't see "a /tmp" as one param
74#if ENABLE_PLATFORM_MINGW32
75 cmd = NULL;
76 do {
77 cmd = xappendword(cmd, *argv);
78 } while (*++argv);
79#else
74 cmd = *argv; 80 cmd = *argv;
75 while (*++argv) 81 while (*++argv)
76 cmd = xasprintf("%s %s", cmd, *argv); // leaks cmd 82 cmd = xasprintf("%s %s", cmd, *argv); // leaks cmd
83#endif
77 84
78 period = parse_duration_str(period_str); 85 period = parse_duration_str(period_str);
79 width = (unsigned)-1; // make sure first time new_width != width 86 width = (unsigned)-1; // make sure first time new_width != width
diff --git a/win32/mingw.c b/win32/mingw.c
index e81f17f11..9e1cf5eea 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -2389,3 +2389,15 @@ const char *applet_to_exe(const char *name)
2389 return name; 2389 return name;
2390} 2390}
2391#endif 2391#endif
2392
2393/*
2394 * Append a word to a space-separated string of words. The first
2395 * call should use a NULL pointer for str, subsequent calls should
2396 * pass an allocated string which will be freed.
2397 */
2398char *xappendword(const char *str, const char *word)
2399{
2400 char *newstr = str ? xasprintf("%s %s", str, word) : xstrdup(word);
2401 free((void *)str);
2402 return newstr;
2403}