aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-07-09 13:10:58 +0100
committerRon Yorston <rmy@pobox.com>2020-07-09 13:10:58 +0100
commit9c0b2f7020d7c30b21a930ef54be632e092e533b (patch)
treeb2187c40bd2fd9f49f73599fb08e52cb7a596de0 /libbb
parenta8c6e20e332a9e11a9d28cd6770eadb9c9d73cb7 (diff)
parentd21a63f9fca8eb16f79de9b72d4a3484dfaec1fc (diff)
downloadbusybox-w32-9c0b2f7020d7c30b21a930ef54be632e092e533b.tar.gz
busybox-w32-9c0b2f7020d7c30b21a930ef54be632e092e533b.tar.bz2
busybox-w32-9c0b2f7020d7c30b21a930ef54be632e092e533b.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb')
-rw-r--r--libbb/appletlib.c38
-rw-r--r--libbb/compare_string_array.c7
-rw-r--r--libbb/duration.c1
-rw-r--r--libbb/last_char_is.c17
-rw-r--r--libbb/lineedit.c2
-rw-r--r--libbb/procps.c12
-rw-r--r--libbb/xfuncs_printf.c19
7 files changed, 64 insertions, 32 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 8c46d0d1b..d2f98567e 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -794,7 +794,9 @@ static void install_links(const char *busybox UNUSED_PARAM,
794} 794}
795# endif 795# endif
796 796
797# if ENABLE_BUSYBOX || NUM_APPLETS > 0
797static void run_applet_and_exit(const char *name, char **argv) NORETURN; 798static void run_applet_and_exit(const char *name, char **argv) NORETURN;
799#endif
798 800
799# if NUM_SCRIPTS > 0 801# if NUM_SCRIPTS > 0
800static int find_script_by_name(const char *name) 802static int find_script_by_name(const char *name)
@@ -815,13 +817,13 @@ int scripted_main(int argc UNUSED_PARAM, char **argv)
815{ 817{
816 int script = find_script_by_name(applet_name); 818 int script = find_script_by_name(applet_name);
817 if (script >= 0) 819 if (script >= 0)
818#if ENABLE_ASH || ENABLE_SH_IS_ASH || ENABLE_BASH_IS_ASH 820# if ENABLE_SHELL_ASH
819 exit(ash_main(-script - 1, argv)); 821 exit(ash_main(-script - 1, argv));
820#elif ENABLE_HUSH || ENABLE_SH_IS_HUSH || ENABLE_BASH_IS_HUSH 822# elif ENABLE_SHELL_HUSH
821 exit(hush_main(-script - 1, argv)); 823 exit(hush_main(-script - 1, argv));
822#else 824# else
823 return 1; 825 return 1;
824#endif 826# endif
825 return 0; 827 return 0;
826} 828}
827 829
@@ -1160,7 +1162,33 @@ static NORETURN void run_applet_and_exit(const char *name, char **argv)
1160} 1162}
1161# endif 1163# endif
1162 1164
1163#endif /* !defined(SINGLE_APPLET_MAIN) */ 1165#else /* defined(SINGLE_APPLET_MAIN) */
1166
1167# if NUM_SCRIPTS > 0
1168/* if SINGLE_APPLET_MAIN, these two functions are simpler: */
1169int scripted_main(int argc UNUSED_PARAM, char **argv) MAIN_EXTERNALLY_VISIBLE;
1170int scripted_main(int argc UNUSED_PARAM, char **argv)
1171{
1172# if ENABLE_SHELL_ASH
1173 int script = 0;
1174 exit(ash_main(-script - 1, argv));
1175# elif ENABLE_SHELL_HUSH
1176 int script = 0;
1177 exit(hush_main(-script - 1, argv));
1178# else
1179 return 1;
1180# endif
1181}
1182char* FAST_FUNC
1183get_script_content(unsigned n UNUSED_PARAM)
1184{
1185 char *t = unpack_bz2_data(packed_scripts, sizeof(packed_scripts),
1186 UNPACKED_SCRIPTS_LENGTH);
1187 return t;
1188}
1189# endif /* NUM_SCRIPTS > 0 */
1190
1191#endif /* defined(SINGLE_APPLET_MAIN) */
1164 1192
1165 1193
1166#if ENABLE_BUILD_LIBBUSYBOX 1194#if ENABLE_BUILD_LIBBUSYBOX
diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c
index 856739c41..ede5a97e3 100644
--- a/libbb/compare_string_array.c
+++ b/libbb/compare_string_array.c
@@ -158,8 +158,11 @@ int FAST_FUNC index_in_substrings(const char *strings, const char *key)
158const char* FAST_FUNC nth_string(const char *strings, int n) 158const char* FAST_FUNC nth_string(const char *strings, int n)
159{ 159{
160 while (n) { 160 while (n) {
161 n--; 161 if (*strings++ == '\0') {
162 strings += strlen(strings) + 1; 162 if (*strings == '\0') /* reached end of strings */
163 break;
164 n--;
165 }
163 } 166 }
164 return strings; 167 return strings;
165} 168}
diff --git a/libbb/duration.c b/libbb/duration.c
index 5acd0dba3..22b209f4d 100644
--- a/libbb/duration.c
+++ b/libbb/duration.c
@@ -17,6 +17,7 @@
17//kbuild:lib-$(CONFIG_TIMEOUT) += duration.o 17//kbuild:lib-$(CONFIG_TIMEOUT) += duration.o
18//kbuild:lib-$(CONFIG_PING) += duration.o 18//kbuild:lib-$(CONFIG_PING) += duration.o
19//kbuild:lib-$(CONFIG_PING6) += duration.o 19//kbuild:lib-$(CONFIG_PING6) += duration.o
20//kbuild:lib-$(CONFIG_WATCH) += duration.o
20 21
21#include "libbb.h" 22#include "libbb.h"
22 23
diff --git a/libbb/last_char_is.c b/libbb/last_char_is.c
index 66f2e3635..918526e6c 100644
--- a/libbb/last_char_is.c
+++ b/libbb/last_char_is.c
@@ -8,16 +8,17 @@
8 */ 8 */
9#include "libbb.h" 9#include "libbb.h"
10 10
11/* Find out if the last character of a string matches the one given. 11/* Find out if the last character of a string matches the one given */
12 * Don't underrun the buffer if the string length is 0.
13 */
14char* FAST_FUNC last_char_is(const char *s, int c) 12char* FAST_FUNC last_char_is(const char *s, int c)
15{ 13{
16 if (s && *s) { 14 if (s) {
17 size_t sz = strlen(s) - 1; 15 size_t sz = strlen(s);
18 s += sz; 16 /* Don't underrun the buffer if the string length is 0 */
19 if ( (unsigned char)*s == c) 17 if (sz != 0) {
20 return (char*)s; 18 s += sz - 1;
19 if ((unsigned char)*s == c)
20 return (char*)s;
21 }
21 } 22 }
22 return NULL; 23 return NULL;
23} 24}
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index f4247d237..a36a1647d 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -99,7 +99,7 @@ static bool BB_ispunct(CHAR_T c)
99# if ENABLE_FEATURE_EDITING_VI 99# if ENABLE_FEATURE_EDITING_VI
100static bool BB_isalnum_or_underscore(CHAR_T c) 100static bool BB_isalnum_or_underscore(CHAR_T c)
101{ 101{
102 return ((unsigned)c < 256 && isalnum(c)) || c == '_'; 102 return isalnum(c) || c == '_';
103} 103}
104# endif 104# endif
105# define BB_ispunct(c) ispunct(c) 105# define BB_ispunct(c) ispunct(c)
diff --git a/libbb/procps.c b/libbb/procps.c
index e6892d7ff..4f9705bc1 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -178,6 +178,15 @@ static char *skip_fields(char *str, int count)
178} 178}
179#endif 179#endif
180 180
181static char* skip_whitespace_if_prefixed_with(char *buf, const char *prefix)
182{
183 char *tp = is_prefixed_with(buf, prefix);
184 if (tp) {
185 tp = skip_whitespace(tp);
186 }
187 return tp;
188}
189
181#if ENABLE_FEATURE_TOPMEM || ENABLE_PMAP 190#if ENABLE_FEATURE_TOPMEM || ENABLE_PMAP
182int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, 191int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total,
183 void (*cb)(struct smaprec *, void *), void *data) 192 void (*cb)(struct smaprec *, void *), void *data)
@@ -208,8 +217,7 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total,
208 char *tp, *p; 217 char *tp, *p;
209 218
210#define SCAN(S, X) \ 219#define SCAN(S, X) \
211 if ((tp = is_prefixed_with(buf, S)) != NULL) { \ 220 if ((tp = skip_whitespace_if_prefixed_with(buf, S)) != NULL) { \
212 tp = skip_whitespace(tp); \
213 total->X += currec.X = fast_strtoul_10(&tp); \ 221 total->X += currec.X = fast_strtoul_10(&tp); \
214 continue; \ 222 continue; \
215 } 223 }
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index cfe062a47..6fdc0f6a4 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -93,26 +93,17 @@ char* FAST_FUNC xstrdup(const char *s)
93// the (possibly truncated to length n) string into it. 93// the (possibly truncated to length n) string into it.
94char* FAST_FUNC xstrndup(const char *s, int n) 94char* FAST_FUNC xstrndup(const char *s, int n)
95{ 95{
96 int m;
97 char *t; 96 char *t;
98 97
99 if (ENABLE_DEBUG && s == NULL) 98 if (ENABLE_DEBUG && s == NULL)
100 bb_simple_error_msg_and_die("xstrndup bug"); 99 bb_simple_error_msg_and_die("xstrndup bug");
101 100
102 /* We can just xmalloc(n+1) and strncpy into it, */ 101 t = strndup(s, n);
103 /* but think about xstrndup("abc", 10000) wastage! */
104 m = n;
105 t = (char*) s;
106 while (m) {
107 if (!*t) break;
108 m--;
109 t++;
110 }
111 n -= m;
112 t = xmalloc(n + 1);
113 t[n] = '\0';
114 102
115 return memcpy(t, s, n); 103 if (t == NULL)
104 bb_die_memory_exhausted();
105
106 return t;
116} 107}
117 108
118void* FAST_FUNC xmemdup(const void *s, int n) 109void* FAST_FUNC xmemdup(const void *s, int n)