aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-02-13 10:17:16 +0000
committerRon Yorston <rmy@pobox.com>2021-02-13 10:17:16 +0000
commit8489ebce32f4b6cf5c1c1120fd474e26f7659db7 (patch)
treeeaa5471ae7c13aaf335358fdf1079547fea0226a
parent7587b56c10a4d11fe434e3eaa51212113f09ec10 (diff)
downloadbusybox-w32-8489ebce32f4b6cf5c1c1120fd474e26f7659db7.tar.gz
busybox-w32-8489ebce32f4b6cf5c1c1120fd474e26f7659db7.tar.bz2
busybox-w32-8489ebce32f4b6cf5c1c1120fd474e26f7659db7.zip
win32: code shrink
Rewrite the recent change to tab completion so it only needs one call to sprintf. Then replace sprintf with strcpy/stpcpy, both there and in a couple of other places. Saves 40 bytes.
-rw-r--r--libbb/lineedit.c20
-rw-r--r--shell/ash.c2
-rw-r--r--win32/mingw.c2
3 files changed, 17 insertions, 7 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 4802b46b4..55141e141 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -1251,6 +1251,8 @@ static NOINLINE void input_tab(smallint *lastWasTab)
1251 unsigned match_pfx_len = match_pfx_len; 1251 unsigned match_pfx_len = match_pfx_len;
1252#if ENABLE_PLATFORM_MINGW32 1252#if ENABLE_PLATFORM_MINGW32
1253 unsigned orig_pfx_len; 1253 unsigned orig_pfx_len;
1254 char *target;
1255 const char *source;
1254#endif 1256#endif
1255 int find_type; 1257 int find_type;
1256# if ENABLE_UNICODE_SUPPORT 1258# if ENABLE_UNICODE_SUPPORT
@@ -1393,13 +1395,21 @@ static NOINLINE void input_tab(smallint *lastWasTab)
1393 /* save tail */ 1395 /* save tail */
1394 strcpy(match_buf, &command_ps[cursor]); 1396 strcpy(match_buf, &command_ps[cursor]);
1395 /* add match and tail */ 1397 /* add match and tail */
1396#if ENABLE_PLATFORM_MINGW32 1398# if ENABLE_PLATFORM_MINGW32
1397 if (match_pfx_len == orig_pfx_len) { 1399 if (match_pfx_len == orig_pfx_len) {
1398 sprintf(&command_ps[cursor-match_pfx_len], "%s%s", 1400 /* replace match prefix to allow for altered case */
1399 chosen_match, match_buf); 1401 target = &command_ps[cursor-match_pfx_len];
1400 } else 1402 source = chosen_match;
1401#endif 1403 }
1404 else {
1405 /* only replace tail of match if special characters are quoted */
1406 target = &command_ps[cursor];
1407 source = chosen_match + match_pfx_len;
1408 }
1409 strcpy(stpcpy(target, source), match_buf);
1410# else
1402 sprintf(&command_ps[cursor], "%s%s", chosen_match + match_pfx_len, match_buf); 1411 sprintf(&command_ps[cursor], "%s%s", chosen_match + match_pfx_len, match_buf);
1412# endif
1403 command_len = strlen(command_ps); 1413 command_len = strlen(command_ps);
1404 /* new pos */ 1414 /* new pos */
1405 pos = cursor + len_found - match_pfx_len; 1415 pos = cursor + len_found - match_pfx_len;
diff --git a/shell/ash.c b/shell/ash.c
index c400612d9..f8a18cdc5 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -2119,7 +2119,7 @@ stack_add_system_drive(const char *path)
2119 const char *sd = need_system_drive(path); 2119 const char *sd = need_system_drive(path);
2120 char *p = growstackto(strlen(path) + 5 + (sd ? strlen(sd) : 0)); 2120 char *p = growstackto(strlen(path) + 5 + (sd ? strlen(sd) : 0));
2121 2121
2122 sprintf(p, "%s%s", sd ?: "", path); 2122 strcpy(stpcpy(p, sd ?: ""), path);
2123 return p; 2123 return p;
2124} 2124}
2125#endif 2125#endif
diff --git a/win32/mingw.c b/win32/mingw.c
index a6362333d..75635fdf1 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -1729,7 +1729,7 @@ char *alloc_system_drive(const char *path)
1729{ 1729{
1730 const char *sd = need_system_drive(path); 1730 const char *sd = need_system_drive(path);
1731 char *s = xmalloc(strlen(path) + 5 + (sd ? strlen(sd) : 0)); 1731 char *s = xmalloc(strlen(path) + 5 + (sd ? strlen(sd) : 0));
1732 sprintf(s, "%s%s", sd ?: "", path); 1732 strcpy(stpcpy(s, sd ?: ""), path);
1733 return s; 1733 return s;
1734} 1734}
1735 1735