aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-11-12 08:27:51 +0000
committerRon Yorston <rmy@pobox.com>2020-11-12 08:27:51 +0000
commitead8b92e3d66ab45235e137f85fb3a529dcc64ef (patch)
treeaf268270382dad969218063d4a8120fc91a9e631 /coreutils
parent567728c22dddea4ed33b8a69641ba2e0c3f1f600 (diff)
parent64981b4c8e88812c322bee3832f1d421ff670ed5 (diff)
downloadbusybox-w32-ead8b92e3d66ab45235e137f85fb3a529dcc64ef.tar.gz
busybox-w32-ead8b92e3d66ab45235e137f85fb3a529dcc64ef.tar.bz2
busybox-w32-ead8b92e3d66ab45235e137f85fb3a529dcc64ef.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/chmod.c13
-rw-r--r--coreutils/chown.c9
-rw-r--r--coreutils/test.c82
-rw-r--r--coreutils/uudecode.c6
4 files changed, 95 insertions, 15 deletions
diff --git a/coreutils/chmod.c b/coreutils/chmod.c
index 27e9b6b86..d2988c490 100644
--- a/coreutils/chmod.c
+++ b/coreutils/chmod.c
@@ -65,12 +65,14 @@
65 * symbolic links encountered during recursive directory traversals. 65 * symbolic links encountered during recursive directory traversals.
66 */ 66 */
67 67
68static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf, void* param, int depth) 68static int FAST_FUNC fileAction(struct recursive_state *state,
69 const char *fileName,
70 struct stat *statbuf)
69{ 71{
70 mode_t newmode; 72 mode_t newmode;
71 73
72 /* match coreutils behavior */ 74 /* match coreutils behavior */
73 if (depth == 0) { 75 if (state->depth == 0) {
74 /* statbuf holds lstat result, but we need stat (follow link) */ 76 /* statbuf holds lstat result, but we need stat (follow link) */
75 if (stat(fileName, statbuf)) 77 if (stat(fileName, statbuf))
76 goto err; 78 goto err;
@@ -79,9 +81,9 @@ static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf, void
79 return TRUE; 81 return TRUE;
80 } 82 }
81 83
82 newmode = bb_parse_mode((char *)param, statbuf->st_mode); 84 newmode = bb_parse_mode((char *)state->userData, statbuf->st_mode);
83 if (newmode == (mode_t)-1) 85 if (newmode == (mode_t)-1)
84 bb_error_msg_and_die("invalid mode '%s'", (char *)param); 86 bb_error_msg_and_die("invalid mode '%s'", (char *)state->userData);
85 87
86 if (chmod(fileName, newmode) == 0) { 88 if (chmod(fileName, newmode) == 0) {
87 if (OPT_VERBOSE 89 if (OPT_VERBOSE
@@ -136,8 +138,7 @@ int chmod_main(int argc UNUSED_PARAM, char **argv)
136 OPT_RECURSE, // recurse 138 OPT_RECURSE, // recurse
137 fileAction, // file action 139 fileAction, // file action
138 fileAction, // dir action 140 fileAction, // dir action
139 smode, // user data 141 smode) // user data
140 0) // depth
141 ) { 142 ) {
142 retval = EXIT_FAILURE; 143 retval = EXIT_FAILURE;
143 } 144 }
diff --git a/coreutils/chown.c b/coreutils/chown.c
index a1c5c0224..ffccc6cce 100644
--- a/coreutils/chown.c
+++ b/coreutils/chown.c
@@ -97,10 +97,10 @@ struct param_t {
97 chown_fptr chown_func; 97 chown_fptr chown_func;
98}; 98};
99 99
100static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf, 100static int FAST_FUNC fileAction(struct recursive_state *state UNUSED_PARAM,
101 void *vparam, int depth UNUSED_PARAM) 101 const char *fileName, struct stat *statbuf)
102{ 102{
103#define param (*(struct param_t*)vparam) 103#define param (*(struct param_t*)state->userData)
104#define opt option_mask32 104#define opt option_mask32
105 uid_t u = (param.ugid.uid == (uid_t)-1L) ? statbuf->st_uid : param.ugid.uid; 105 uid_t u = (param.ugid.uid == (uid_t)-1L) ? statbuf->st_uid : param.ugid.uid;
106 gid_t g = (param.ugid.gid == (gid_t)-1L) ? statbuf->st_gid : param.ugid.gid; 106 gid_t g = (param.ugid.gid == (gid_t)-1L) ? statbuf->st_gid : param.ugid.gid;
@@ -159,8 +159,7 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
159 flags, /* flags */ 159 flags, /* flags */
160 fileAction, /* file action */ 160 fileAction, /* file action */
161 fileAction, /* dir action */ 161 fileAction, /* dir action */
162 &param, /* user data */ 162 &param) /* user data */
163 0) /* depth */
164 ) { 163 ) {
165 retval = EXIT_FAILURE; 164 retval = EXIT_FAILURE;
166 } 165 }
diff --git a/coreutils/test.c b/coreutils/test.c
index a08986130..ac7b546a3 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -76,6 +76,8 @@
76//usage: "1\n" 76//usage: "1\n"
77 77
78#include "libbb.h" 78#include "libbb.h"
79#include <regex.h>
80#include <fnmatch.h>
79 81
80/* This is a NOFORK applet. Be very careful! */ 82/* This is a NOFORK applet. Be very careful! */
81 83
@@ -146,6 +148,14 @@
146 148
147#define TEST_DEBUG 0 149#define TEST_DEBUG 0
148 150
151#if ENABLE_TEST2 \
152 || (ENABLE_ASH_BASH_COMPAT && ENABLE_ASH_TEST) \
153 || (ENABLE_HUSH_BASH_COMPAT && ENABLE_HUSH_TEST)
154# define BASH_TEST2 1
155#else
156# define BASH_TEST2 0
157#endif
158
149enum token { 159enum token {
150 EOI, 160 EOI,
151 161
@@ -184,6 +194,10 @@ enum token {
184 STRLT, 194 STRLT,
185 STRGT, 195 STRGT,
186 196
197#if BASH_TEST2
198 REGEX,
199#endif
200
187 INTEQ, /* int ops */ 201 INTEQ, /* int ops */
188 INTNE, 202 INTNE,
189 INTGE, 203 INTGE,
@@ -257,6 +271,9 @@ static const char *const TOKSTR[] = {
257 "STRNE", 271 "STRNE",
258 "STRLT", 272 "STRLT",
259 "STRGT", 273 "STRGT",
274#if BASH_TEST2
275 "REGEX",
276#endif
260 "INTEQ", 277 "INTEQ",
261 "INTNE", 278 "INTNE",
262 "INTGE", 279 "INTGE",
@@ -320,6 +337,9 @@ static const struct operator_t ops_table[] = {
320 { /* "!=" */ STRNE , BINOP }, 337 { /* "!=" */ STRNE , BINOP },
321 { /* "<" */ STRLT , BINOP }, 338 { /* "<" */ STRLT , BINOP },
322 { /* ">" */ STRGT , BINOP }, 339 { /* ">" */ STRGT , BINOP },
340#if BASH_TEST2
341 { /* "=~" */ REGEX , BINOP },
342#endif
323 { /* "-eq"*/ INTEQ , BINOP }, 343 { /* "-eq"*/ INTEQ , BINOP },
324 { /* "-ne"*/ INTNE , BINOP }, 344 { /* "-ne"*/ INTNE , BINOP },
325 { /* "-ge"*/ INTGE , BINOP }, 345 { /* "-ge"*/ INTGE , BINOP },
@@ -332,6 +352,10 @@ static const struct operator_t ops_table[] = {
332 { /* "!" */ UNOT , BUNOP }, 352 { /* "!" */ UNOT , BUNOP },
333 { /* "-a" */ BAND , BBINOP }, 353 { /* "-a" */ BAND , BBINOP },
334 { /* "-o" */ BOR , BBINOP }, 354 { /* "-o" */ BOR , BBINOP },
355#if BASH_TEST2
356 { /* "&&" */ BAND , BBINOP },
357 { /* "||" */ BOR , BBINOP },
358#endif
335 { /* "(" */ LPAREN , PAREN }, 359 { /* "(" */ LPAREN , PAREN },
336 { /* ")" */ RPAREN , PAREN }, 360 { /* ")" */ RPAREN , PAREN },
337}; 361};
@@ -365,6 +389,9 @@ static const char ops_texts[] ALIGN1 =
365 "!=" "\0" 389 "!=" "\0"
366 "<" "\0" 390 "<" "\0"
367 ">" "\0" 391 ">" "\0"
392#if BASH_TEST2
393 "=~" "\0"
394#endif
368 "-eq" "\0" 395 "-eq" "\0"
369 "-ne" "\0" 396 "-ne" "\0"
370 "-ge" "\0" 397 "-ge" "\0"
@@ -377,6 +404,10 @@ static const char ops_texts[] ALIGN1 =
377 "!" "\0" 404 "!" "\0"
378 "-a" "\0" 405 "-a" "\0"
379 "-o" "\0" 406 "-o" "\0"
407#if BASH_TEST2
408 "&&" "\0"
409 "||" "\0"
410#endif
380 "(" "\0" 411 "(" "\0"
381 ")" "\0" 412 ")" "\0"
382; 413;
@@ -397,6 +428,9 @@ struct test_statics {
397 const struct operator_t *last_operator; 428 const struct operator_t *last_operator;
398 gid_t *group_array; 429 gid_t *group_array;
399 int ngroups; 430 int ngroups;
431#if BASH_TEST2
432 bool bash_test2;
433#endif
400 jmp_buf leaving; 434 jmp_buf leaving;
401}; 435};
402 436
@@ -408,6 +442,7 @@ extern struct test_statics *const test_ptr_to_statics;
408#define last_operator (S.last_operator) 442#define last_operator (S.last_operator)
409#define group_array (S.group_array ) 443#define group_array (S.group_array )
410#define ngroups (S.ngroups ) 444#define ngroups (S.ngroups )
445#define bash_test2 (S.bash_test2 )
411#define leaving (S.leaving ) 446#define leaving (S.leaving )
412 447
413#define INIT_S() do { \ 448#define INIT_S() do { \
@@ -501,6 +536,20 @@ static enum token check_operator(const char *s)
501 n = index_in_strings(ops_texts, s); 536 n = index_in_strings(ops_texts, s);
502 if (n < 0) 537 if (n < 0)
503 return OPERAND; 538 return OPERAND;
539
540#if BASH_TEST2
541 if (ops_table[n].op_num == REGEX && !bash_test2) {
542 /* =~ is only for [[ ]] */
543 return OPERAND;
544 }
545 if (ops_table[n].op_num == BAND || ops_table[n].op_num == BOR) {
546 /* [ ] accepts -a and -o but not && and || */
547 /* [[ ]] accepts && and || but not -a and -o */
548 if (bash_test2 == (s[0] == '-'))
549 return OPERAND;
550 }
551#endif
552
504 last_operator = &ops_table[n]; 553 last_operator = &ops_table[n];
505 return ops_table[n].op_num; 554 return ops_table[n].op_num;
506} 555}
@@ -536,6 +585,29 @@ static int binop(void)
536 /*if (op->op_num == INTLT)*/ 585 /*if (op->op_num == INTLT)*/
537 return val1 < val2; 586 return val1 < val2;
538 } 587 }
588#if BASH_TEST2
589 if (bash_test2) {
590 if (op->op_num == STREQ) {
591 val1 = fnmatch(opnd2, opnd1, 0);
592 return val1 == 0;
593 }
594 if (op->op_num == STRNE) {
595 val1 = fnmatch(opnd2, opnd1, 0);
596 return val1 != 0;
597 }
598 if (op->op_num == REGEX) {
599 regex_t re_buffer;
600 memset(&re_buffer, 0, sizeof(re_buffer));
601 if (regcomp(&re_buffer, opnd2, REG_EXTENDED)) { // REG_NEWLINE?
602 /* Bad regex */
603 longjmp(leaving, 2); /* [[ a =~ * ]]; echo $? - prints 2 (silently, no error msg) */
604 }
605 val1 = regexec(&re_buffer, opnd1, 0, NULL, 0);
606 regfree(&re_buffer);
607 return val1 == 0;
608 }
609 }
610#endif
539 if (is_str_op(op->op_num)) { 611 if (is_str_op(op->op_num)) {
540 val1 = strcmp(opnd1, opnd2); 612 val1 = strcmp(opnd1, opnd2);
541 if (op->op_num == STREQ) 613 if (op->op_num == STREQ)
@@ -824,6 +896,9 @@ int test_main(int argc, char **argv)
824{ 896{
825 int res; 897 int res;
826 const char *arg0; 898 const char *arg0;
899#if BASH_TEST2
900 bool bt2 = 0;
901#endif
827 902
828 arg0 = bb_basename(argv[0]); 903 arg0 = bb_basename(argv[0]);
829 if ((ENABLE_TEST1 || ENABLE_TEST2 || ENABLE_ASH_TEST || ENABLE_HUSH_TEST) 904 if ((ENABLE_TEST1 || ENABLE_TEST2 || ENABLE_ASH_TEST || ENABLE_HUSH_TEST)
@@ -840,6 +915,9 @@ int test_main(int argc, char **argv)
840 bb_simple_error_msg("missing ]]"); 915 bb_simple_error_msg("missing ]]");
841 return 2; 916 return 2;
842 } 917 }
918#if BASH_TEST2
919 bt2 = 1;
920#endif
843 } 921 }
844 argv[argc] = NULL; 922 argv[argc] = NULL;
845 } 923 }
@@ -848,6 +926,10 @@ int test_main(int argc, char **argv)
848 /* We must do DEINIT_S() prior to returning */ 926 /* We must do DEINIT_S() prior to returning */
849 INIT_S(); 927 INIT_S();
850 928
929#if BASH_TEST2
930 bash_test2 = bt2;
931#endif
932
851 res = setjmp(leaving); 933 res = setjmp(leaving);
852 if (res) 934 if (res)
853 goto ret; 935 goto ret;
diff --git a/coreutils/uudecode.c b/coreutils/uudecode.c
index dc8ef5cca..5b2edd649 100644
--- a/coreutils/uudecode.c
+++ b/coreutils/uudecode.c
@@ -110,9 +110,7 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
110 } 110 }
111 bb_simple_error_msg_and_die("short file"); 111 bb_simple_error_msg_and_die("short file");
112} 112}
113#endif
114 113
115#if ENABLE_UUDECODE
116int uudecode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 114int uudecode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
117int uudecode_main(int argc UNUSED_PARAM, char **argv) 115int uudecode_main(int argc UNUSED_PARAM, char **argv)
118{ 116{
@@ -202,10 +200,10 @@ int base64_main(int argc UNUSED_PARAM, char **argv)
202 *--argv = (char*)"-"; 200 *--argv = (char*)"-";
203 src_stream = xfopen_stdin(argv[0]); 201 src_stream = xfopen_stdin(argv[0]);
204 if (opts) { 202 if (opts) {
205 read_base64(src_stream, stdout, /*flags:*/ (char)EOF); 203 read_base64(src_stream, stdout, /*flags:*/ (unsigned char)EOF);
206 } else { 204 } else {
207 enum { 205 enum {
208 SRC_BUF_SIZE = 76/4*3, /* This *MUST* be a multiple of 3 */ 206 SRC_BUF_SIZE = 76 / 4 * 3, /* this *MUST* be a multiple of 3 */
209 DST_BUF_SIZE = 4 * ((SRC_BUF_SIZE + 2) / 3), 207 DST_BUF_SIZE = 4 * ((SRC_BUF_SIZE + 2) / 3),
210 }; 208 };
211 char src_buf[SRC_BUF_SIZE]; 209 char src_buf[SRC_BUF_SIZE];