aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2017-07-18 15:58:52 +0100
committerRon Yorston <rmy@pobox.com>2017-07-18 15:58:52 +0100
commitb680f05ad449505e3d914bebd4c8d83bf768c094 (patch)
treec08ded13d430b0e7e0104f2eb594fad190ce98a3 /coreutils
parent258200ff81d5a9da54dab35acf36213eff1e399b (diff)
parent513a2457b65894b10b9fd6aa8753fca59eced08c (diff)
downloadbusybox-w32-b680f05ad449505e3d914bebd4c8d83bf768c094.tar.gz
busybox-w32-b680f05ad449505e3d914bebd4c8d83bf768c094.tar.bz2
busybox-w32-b680f05ad449505e3d914bebd4c8d83bf768c094.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/cat.c99
-rw-r--r--coreutils/dd.c7
-rw-r--r--coreutils/nl.c20
-rw-r--r--coreutils/printf.c4
-rw-r--r--coreutils/shuf.c2
-rw-r--r--coreutils/test.c33
-rw-r--r--coreutils/uname.c165
-rw-r--r--coreutils/uudecode.c12
8 files changed, 183 insertions, 159 deletions
diff --git a/coreutils/cat.c b/coreutils/cat.c
index 4d9147f8a..a9ba68d6b 100644
--- a/coreutils/cat.c
+++ b/coreutils/cat.c
@@ -13,6 +13,13 @@
13//config: cat is used to concatenate files and print them to the standard 13//config: cat is used to concatenate files and print them to the standard
14//config: output. Enable this option if you wish to enable the 'cat' utility. 14//config: output. Enable this option if you wish to enable the 'cat' utility.
15//config: 15//config:
16//config:config FEATURE_CATN
17//config: bool "Enable -n and -b options"
18//config: default y
19//config: depends on CAT
20//config: help
21//config: -n numbers all output lines while -b numbers nonempty output lines.
22//config:
16//config:config FEATURE_CATV 23//config:config FEATURE_CATV
17//config: bool "cat -v[etA]" 24//config: bool "cat -v[etA]"
18//config: default y 25//config: default y
@@ -27,12 +34,19 @@
27/* BB_AUDIT SUSv3 compliant */ 34/* BB_AUDIT SUSv3 compliant */
28/* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */ 35/* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */
29 36
37//usage:#if ENABLE_FEATURE_CATN || ENABLE_FEATURE_CATV
38//usage:#define cat_trivial_usage
39//usage: "[-" IF_FEATURE_CATN("nb") IF_FEATURE_CATV("vteA") "] [FILE]..."
40//usage:#else
30//usage:#define cat_trivial_usage 41//usage:#define cat_trivial_usage
31//usage: "[-nb"IF_FEATURE_CATV("vteA")"] [FILE]..." 42//usage: "[FILE]..."
43//usage:#endif
32//usage:#define cat_full_usage "\n\n" 44//usage:#define cat_full_usage "\n\n"
33//usage: "Print FILEs to stdout\n" 45//usage: "Print FILEs to stdout\n"
46//usage: IF_FEATURE_CATN(
34//usage: "\n -n Number output lines" 47//usage: "\n -n Number output lines"
35//usage: "\n -b Number nonempty lines" 48//usage: "\n -b Number nonempty lines"
49//usage: )
36//usage: IF_FEATURE_CATV( 50//usage: IF_FEATURE_CATV(
37//usage: "\n -v Show nonprinting characters as ^x or M-x" 51//usage: "\n -v Show nonprinting characters as ^x or M-x"
38//usage: "\n -t ...and tabs as ^I" 52//usage: "\n -t ...and tabs as ^I"
@@ -84,30 +98,35 @@
84 * I agree with the argument. Unfortunately, this ship has sailed (1983...). 98 * I agree with the argument. Unfortunately, this ship has sailed (1983...).
85 * There are dozens of Linux distros and each of them has "cat" which supports -v. 99 * There are dozens of Linux distros and each of them has "cat" which supports -v.
86 * It's unrealistic for us to "reeducate" them to use our, incompatible way 100 * It's unrealistic for us to "reeducate" them to use our, incompatible way
87 * to achieve "cat -v" effect. The actuall effect would be "users pissed off 101 * to achieve "cat -v" effect. The actual effect would be "users pissed off
88 * by gratuitous incompatibility". 102 * by gratuitous incompatibility".
89 */ 103 */
90#define CATV_OPT_e (1<<0) 104#define CAT_OPT_e (1<<0)
91#define CATV_OPT_t (1<<1) 105#define CAT_OPT_t (1<<1)
92#define CATV_OPT_v (1<<2) 106#define CAT_OPT_v (1<<2)
107/* -A occupies bit (1<<3) */
108#define CAT_OPT_n ((1<<4) * ENABLE_FEATURE_CATN)
109#define CAT_OPT_b ((1<<5) * ENABLE_FEATURE_CATN)
93static int catv(unsigned opts, char **argv) 110static int catv(unsigned opts, char **argv)
94{ 111{
95 int retval = EXIT_SUCCESS; 112 int retval = EXIT_SUCCESS;
96 int fd; 113 int fd;
114#if ENABLE_FEATURE_CATN
115 unsigned lineno = 0;
116 unsigned eol_char = (opts & (CAT_OPT_n|CAT_OPT_b)) ? '\n' : 0x100;
117 unsigned skip_num_on = (opts & CAT_OPT_b) ? '\n' : 0x100;
118 bool eol_seen = 1;
119#endif
97 120
98 BUILD_BUG_ON(CATV_OPT_e != VISIBLE_ENDLINE); 121 BUILD_BUG_ON(CAT_OPT_e != VISIBLE_ENDLINE);
99 BUILD_BUG_ON(CATV_OPT_t != VISIBLE_SHOW_TABS); 122 BUILD_BUG_ON(CAT_OPT_t != VISIBLE_SHOW_TABS);
100#if 0 /* These consts match, we can just pass "opts" to visible() */ 123#if 0 /* These consts match, we can just pass "opts" to visible() */
101 if (opts & CATV_OPT_e) 124 if (opts & CAT_OPT_e)
102 flags |= VISIBLE_ENDLINE; 125 flags |= VISIBLE_ENDLINE;
103 if (opts & CATV_OPT_t) 126 if (opts & CAT_OPT_t)
104 flags |= VISIBLE_SHOW_TABS; 127 flags |= VISIBLE_SHOW_TABS;
105#endif 128#endif
106 129
107 /* Read from stdin if there's nothing else to do. */
108 if (!argv[0])
109 *--argv = (char*)"-";
110
111#define read_buf bb_common_bufsiz1 130#define read_buf bb_common_bufsiz1
112 setup_common_bufsiz(); 131 setup_common_bufsiz();
113 do { 132 do {
@@ -127,6 +146,11 @@ static int catv(unsigned opts, char **argv)
127 for (i = 0; i < res; i++) { 146 for (i = 0; i < res; i++) {
128 unsigned char c = read_buf[i]; 147 unsigned char c = read_buf[i];
129 char buf[sizeof("M-^c")]; 148 char buf[sizeof("M-^c")];
149#if ENABLE_FEATURE_CATN
150 if (eol_seen && c != skip_num_on)
151 printf("%6u ", ++lineno);
152 eol_seen = (c == eol_char);
153#endif
130 visible(c, buf, opts); 154 visible(c, buf, opts);
131 fputs(buf, stdout); 155 fputs(buf, stdout);
132 } 156 }
@@ -137,43 +161,50 @@ static int catv(unsigned opts, char **argv)
137 161
138 fflush_stdout_and_exit(retval); 162 fflush_stdout_and_exit(retval);
139} 163}
164#undef CAT_OPT_n
165#undef CAT_OPT_b
140#endif 166#endif
141 167
142int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 168int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
143int cat_main(int argc UNUSED_PARAM, char **argv) 169int cat_main(int argc UNUSED_PARAM, char **argv)
144{ 170{
145 struct number_state ns;
146 unsigned opts; 171 unsigned opts;
147 172
148 IF_FEATURE_CATV(opt_complementary = "Aetv"; /* -A == -vet */) 173 IF_FEATURE_CATV(opt_complementary = "Aetv"; /* -A == -vet */)
149 /* -u is ignored ("unbuffered") */ 174 /* -u is ignored ("unbuffered") */
150 opts = getopt32(argv, IF_FEATURE_CATV("etvA")"nbu"); 175 opts = getopt32(argv, IF_FEATURE_CATV("etvA") IF_FEATURE_CATN("nb") "u");
151 argv += optind; 176 argv += optind;
152 177
178 /* Read from stdin if there's nothing else to do. */
179 if (!argv[0])
180 *--argv = (char*)"-";
181
153#if ENABLE_FEATURE_CATV 182#if ENABLE_FEATURE_CATV
154 if (opts & 7) 183 if (opts & 7)
155 return catv(opts, argv); 184 return catv(opts, argv);
156//BUG: -v,-e,-t,-A ignore -nb
157 opts >>= 4; 185 opts >>= 4;
158#endif 186#endif
159 187
160#define CAT_OPT_n (1<<0) 188#if ENABLE_FEATURE_CATN
161#define CAT_OPT_b (1<<1) 189# define CAT_OPT_n (1<<0)
162#define CAT_OPT_u (1<<2) 190# define CAT_OPT_b (1<<1)
163 if (!(opts & (CAT_OPT_n|CAT_OPT_b))) /* no -n or -b */ 191 if (opts & (CAT_OPT_n|CAT_OPT_b)) { /* -n or -b */
164 return bb_cat(argv); 192 struct number_state ns;
193
194 ns.width = 6;
195 ns.start = 1;
196 ns.inc = 1;
197 ns.sep = "\t";
198 ns.empty_str = "\n";
199 ns.all = !(opts & CAT_OPT_b); /* -n without -b */
200 ns.nonempty = (opts & CAT_OPT_b); /* -b (with or without -n) */
201 do {
202 print_numbered_lines(&ns, *argv);
203 } while (*++argv);
204 fflush_stdout_and_exit(EXIT_SUCCESS);
205 }
206 /*opts >>= 2;*/
207#endif
165 208
166 if (!*argv) 209 return bb_cat(argv);
167 *--argv = (char*)"-";
168 ns.width = 6;
169 ns.start = 1;
170 ns.inc = 1;
171 ns.sep = "\t";
172 ns.empty_str = "\n";
173 ns.all = !(opts & CAT_OPT_b); /* -n without -b */
174 ns.nonempty = (opts & CAT_OPT_b); /* -b (with or without -n) */
175 do {
176 print_numbered_lines(&ns, *argv);
177 } while (*++argv);
178 fflush_stdout_and_exit(EXIT_SUCCESS);
179} 210}
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 2fccf9d8e..b37615313 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -133,9 +133,8 @@ enum {
133 /* end of input flags */ 133 /* end of input flags */
134 FLAG_TWOBUFS = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS, 134 FLAG_TWOBUFS = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
135 FLAG_COUNT = 1 << 7, 135 FLAG_COUNT = 1 << 7,
136 FLAG_STATUS = 1 << 8, 136 FLAG_STATUS_NONE = 1 << 8,
137 FLAG_STATUS_NONE = 1 << 9, 137 FLAG_STATUS_NOXFER = 1 << 9,
138 FLAG_STATUS_NOXFER = 1 << 10,
139}; 138};
140 139
141static void dd_output_status(int UNUSED_PARAM cur_signal) 140static void dd_output_status(int UNUSED_PARAM cur_signal)
@@ -397,7 +396,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
397 n = index_in_strings(status_words, val); 396 n = index_in_strings(status_words, val);
398 if (n < 0) 397 if (n < 0)
399 bb_error_msg_and_die(bb_msg_invalid_arg_to, val, "status"); 398 bb_error_msg_and_die(bb_msg_invalid_arg_to, val, "status");
400 G.flags |= FLAG_STATUS << n; 399 G.flags |= FLAG_STATUS_NONE << n;
401 /*continue;*/ 400 /*continue;*/
402 } 401 }
403#endif 402#endif
diff --git a/coreutils/nl.c b/coreutils/nl.c
index 5c64923bb..dc468a90b 100644
--- a/coreutils/nl.c
+++ b/coreutils/nl.c
@@ -35,26 +35,6 @@
35 35
36#include "libbb.h" 36#include "libbb.h"
37 37
38void FAST_FUNC print_numbered_lines(struct number_state *ns, const char *filename)
39{
40 FILE *fp = fopen_or_warn_stdin(filename);
41 unsigned N = ns->start;
42 char *line;
43
44 while ((line = xmalloc_fgetline(fp)) != NULL) {
45 if (ns->all
46 || (ns->nonempty && line[0])
47 ) {
48 printf("%*u%s%s\n", ns->width, N, ns->sep, line);
49 N += ns->inc;
50 } else if (ns->empty_str)
51 fputs(ns->empty_str, stdout);
52 free(line);
53 }
54
55 fclose(fp);
56}
57
58int nl_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 38int nl_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
59int nl_main(int argc UNUSED_PARAM, char **argv) 39int nl_main(int argc UNUSED_PARAM, char **argv)
60{ 40{
diff --git a/coreutils/printf.c b/coreutils/printf.c
index bc22e0ee7..65bb5a935 100644
--- a/coreutils/printf.c
+++ b/coreutils/printf.c
@@ -305,7 +305,7 @@ static char **print_formatted(char *f, char **argv, int *conv_err)
305 } 305 }
306 break; 306 break;
307 } 307 }
308 if (strchr("-+ #", *f)) { 308 if (*f && strchr("-+ #", *f)) {
309 ++f; 309 ++f;
310 ++direc_length; 310 ++direc_length;
311 } 311 }
@@ -348,7 +348,7 @@ static char **print_formatted(char *f, char **argv, int *conv_err)
348 static const char format_chars[] ALIGN1 = "diouxXfeEgGcs"; 348 static const char format_chars[] ALIGN1 = "diouxXfeEgGcs";
349 char *p = strchr(format_chars, *f); 349 char *p = strchr(format_chars, *f);
350 /* needed - try "printf %" without it */ 350 /* needed - try "printf %" without it */
351 if (p == NULL) { 351 if (p == NULL || *f == '\0') {
352 bb_error_msg("%s: invalid format", direc_start); 352 bb_error_msg("%s: invalid format", direc_start);
353 /* causes main() to exit with error */ 353 /* causes main() to exit with error */
354 return saved_argv - 1; 354 return saved_argv - 1;
diff --git a/coreutils/shuf.c b/coreutils/shuf.c
index 9f61f2f7d..217f15c97 100644
--- a/coreutils/shuf.c
+++ b/coreutils/shuf.c
@@ -53,7 +53,7 @@ static void shuffle_lines(char **lines, unsigned numlines)
53 /* RAND_MAX can be as small as 32767 */ 53 /* RAND_MAX can be as small as 32767 */
54 if (i > RAND_MAX) 54 if (i > RAND_MAX)
55 r ^= rand() << 15; 55 r ^= rand() << 15;
56 r %= i; 56 r %= i + 1;
57 tmp = lines[i]; 57 tmp = lines[i];
58 lines[i] = lines[r]; 58 lines[i] = lines[r];
59 lines[r] = tmp; 59 lines[r] = tmp;
diff --git a/coreutils/test.c b/coreutils/test.c
index c949a3cc9..d4f93312a 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -563,26 +563,11 @@ static int binop(void)
563 /*return 1; - NOTREACHED */ 563 /*return 1; - NOTREACHED */
564} 564}
565 565
566
567static void initialize_group_array(void) 566static void initialize_group_array(void)
568{ 567{
569 int n; 568 group_array = bb_getgroups(&ngroups, NULL);
570
571 /* getgroups may be expensive, try to use it only once */
572 ngroups = 32;
573 do {
574 /* FIXME: ash tries so hard to not die on OOM,
575 * and we spoil it with just one xrealloc here */
576 /* We realloc, because test_main can be entered repeatedly by shell.
577 * Testcase (ash): 'while true; do test -x some_file; done'
578 * and watch top. (some_file must have owner != you) */
579 n = ngroups;
580 group_array = xrealloc(group_array, n * sizeof(gid_t));
581 ngroups = getgroups(n, group_array);
582 } while (ngroups > n);
583} 569}
584 570
585
586/* Return non-zero if GID is one that we have in our groups list. */ 571/* Return non-zero if GID is one that we have in our groups list. */
587//XXX: FIXME: duplicate of existing libbb function? 572//XXX: FIXME: duplicate of existing libbb function?
588// see toplevel TODO file: 573// see toplevel TODO file:
@@ -610,14 +595,10 @@ static int is_a_group_member(gid_t gid)
610/* Do the same thing access(2) does, but use the effective uid and gid, 595/* Do the same thing access(2) does, but use the effective uid and gid,
611 and don't make the mistake of telling root that any file is 596 and don't make the mistake of telling root that any file is
612 executable. */ 597 executable. */
613static int test_eaccess(char *path, int mode) 598static int test_eaccess(struct stat *st, int mode)
614{ 599{
615 struct stat st;
616 unsigned int euid = geteuid(); 600 unsigned int euid = geteuid();
617 601
618 if (stat(path, &st) < 0)
619 return -1;
620
621 if (euid == 0) { 602 if (euid == 0) {
622 /* Root can read or write any file. */ 603 /* Root can read or write any file. */
623 if (mode != X_OK) 604 if (mode != X_OK)
@@ -625,16 +606,16 @@ static int test_eaccess(char *path, int mode)
625 606
626 /* Root can execute any file that has any one of the execute 607 /* Root can execute any file that has any one of the execute
627 * bits set. */ 608 * bits set. */
628 if (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) 609 if (st->st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))
629 return 0; 610 return 0;
630 } 611 }
631 612
632 if (st.st_uid == euid) /* owner */ 613 if (st->st_uid == euid) /* owner */
633 mode <<= 6; 614 mode <<= 6;
634 else if (is_a_group_member(st.st_gid)) 615 else if (is_a_group_member(st->st_gid))
635 mode <<= 3; 616 mode <<= 3;
636 617
637 if (st.st_mode & mode) 618 if (st->st_mode & mode)
638 return 0; 619 return 0;
639 620
640 return -1; 621 return -1;
@@ -682,7 +663,7 @@ static int filstat(char *nm, enum token mode)
682 i = W_OK; 663 i = W_OK;
683 if (mode == FILEX) 664 if (mode == FILEX)
684 i = X_OK; 665 i = X_OK;
685 return test_eaccess(nm, i) == 0; 666 return test_eaccess(&s, i) == 0;
686 } 667 }
687 if (is_file_type(mode)) { 668 if (is_file_type(mode)) {
688 if (mode == FILREG) 669 if (mode == FILREG)
diff --git a/coreutils/uname.c b/coreutils/uname.c
index 4d98fde25..9c6a06ebb 100644
--- a/coreutils/uname.c
+++ b/coreutils/uname.c
@@ -55,10 +55,20 @@
55//config: help 55//config: help
56//config: Sets the operating system name reported by uname -o. The 56//config: Sets the operating system name reported by uname -o. The
57//config: default is "GNU/Linux". 57//config: default is "GNU/Linux".
58//config:
59//can't use "ARCH" for this applet, all hell breaks loose in build system :)
60//config:config BBARCH
61//config: bool "arch"
62//config: default y
63//config: help
64//config: Same as uname -m.
58 65
59//applet:IF_UNAME(APPLET(uname, BB_DIR_BIN, BB_SUID_DROP)) 66//applet:IF_UNAME(APPLET(uname, BB_DIR_BIN, BB_SUID_DROP))
67// APPLET_ODDNAME:name main location suid_type help
68//applet:IF_BBARCH(APPLET_ODDNAME(arch, uname, BB_DIR_BIN, BB_SUID_DROP, arch))
60 69
61//kbuild:lib-$(CONFIG_UNAME) += uname.o 70//kbuild:lib-$(CONFIG_UNAME) += uname.o
71//kbuild:lib-$(CONFIG_BBARCH) += uname.o
62 72
63/* BB_AUDIT SUSv3 compliant */ 73/* BB_AUDIT SUSv3 compliant */
64/* http://www.opengroup.org/onlinepubs/007904975/utilities/uname.html */ 74/* http://www.opengroup.org/onlinepubs/007904975/utilities/uname.html */
@@ -81,6 +91,11 @@
81//usage: "$ uname -a\n" 91//usage: "$ uname -a\n"
82//usage: "Linux debian 2.4.23 #2 Tue Dec 23 17:09:10 MST 2003 i686 GNU/Linux\n" 92//usage: "Linux debian 2.4.23 #2 Tue Dec 23 17:09:10 MST 2003 i686 GNU/Linux\n"
83 93
94//usage:#define arch_trivial_usage
95//usage: ""
96//usage:#define arch_full_usage "\n\n"
97//usage: "Print system architecture"
98
84#include "libbb.h" 99#include "libbb.h"
85/* After libbb.h, since it needs sys/types.h on some systems */ 100/* After libbb.h, since it needs sys/types.h on some systems */
86#include <sys/utsname.h> 101#include <sys/utsname.h>
@@ -92,7 +107,8 @@ typedef struct {
92 char os[sizeof(CONFIG_UNAME_OSNAME)]; 107 char os[sizeof(CONFIG_UNAME_OSNAME)];
93} uname_info_t; 108} uname_info_t;
94 109
95static const char options[] ALIGN1 = "snrvmpioa"; 110#if ENABLE_UNAME
111#define options "snrvmpioa"
96static const unsigned short utsname_offset[] = { 112static const unsigned short utsname_offset[] = {
97 offsetof(uname_info_t, name.sysname), /* -s */ 113 offsetof(uname_info_t, name.sysname), /* -s */
98 offsetof(uname_info_t, name.nodename), /* -n */ 114 offsetof(uname_info_t, name.nodename), /* -n */
@@ -103,86 +119,97 @@ static const unsigned short utsname_offset[] = {
103 offsetof(uname_info_t, platform), /* -i */ 119 offsetof(uname_info_t, platform), /* -i */
104 offsetof(uname_info_t, os), /* -o */ 120 offsetof(uname_info_t, os), /* -o */
105}; 121};
122#endif
106 123
107int uname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 124int uname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
108int uname_main(int argc UNUSED_PARAM, char **argv) 125int uname_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
109{ 126{
110#if ENABLE_LONG_OPTS
111 static const char uname_longopts[] ALIGN1 =
112 /* name, has_arg, val */
113 "all\0" No_argument "a"
114 "kernel-name\0" No_argument "s"
115 "nodename\0" No_argument "n"
116 "kernel-release\0" No_argument "r"
117 "release\0" No_argument "r"
118 "kernel-version\0" No_argument "v"
119 "machine\0" No_argument "m"
120 "processor\0" No_argument "p"
121 "hardware-platform\0" No_argument "i"
122 "operating-system\0" No_argument "o"
123 ;
124#endif
125 uname_info_t uname_info; 127 uname_info_t uname_info;
126#if defined(__sparc__) && defined(__linux__) 128 IF_UNAME(const char *unknown_str = "unknown";)
127 char *fake_sparc = getenv("FAKE_SPARC");
128#endif
129 const char *unknown_str = "unknown";
130 const char *fmt;
131 const unsigned short *delta;
132 unsigned toprint; 129 unsigned toprint;
133 130
134 IF_LONG_OPTS(applet_long_options = uname_longopts); 131 toprint = (1 << 4); /* "arch" = "uname -m" */
135 toprint = getopt32(argv, options); 132
136 133#if ENABLE_UNAME
137 if (argv[optind]) { /* coreutils-6.9 compat */ 134 if (!ENABLE_BBARCH || applet_name[0] == 'u') {
138 bb_show_usage(); 135# if ENABLE_LONG_OPTS
139 } 136 static const char uname_longopts[] ALIGN1 =
140 137 /* name, has_arg, val */
141 if (toprint & (1 << 8)) { /* -a => all opts on */ 138 "all\0" No_argument "a"
142 toprint = (1 << 8) - 1; 139 "kernel-name\0" No_argument "s"
143 unknown_str = ""; /* -a does not print unknown fields */ 140 "nodename\0" No_argument "n"
144 } 141 "kernel-release\0" No_argument "r"
145 142 "release\0" No_argument "r"
146 if (toprint == 0) { /* no opts => -s (sysname) */ 143 "kernel-version\0" No_argument "v"
147 toprint = 1; 144 "machine\0" No_argument "m"
148 } 145 "processor\0" No_argument "p"
146 "hardware-platform\0" No_argument "i"
147 "operating-system\0" No_argument "o"
148 ;
149# endif
150 IF_LONG_OPTS(applet_long_options = uname_longopts);
151 toprint = getopt32(argv, options);
152 if (argv[optind]) { /* coreutils-6.9 compat */
153 bb_show_usage();
154 }
155 if (toprint & (1 << 8)) { /* -a => all opts on */
156 toprint = (1 << 8) - 1;
157 unknown_str = ""; /* -a does not print unknown fields */
158 }
159 if (toprint == 0) { /* no opts => -s (sysname) */
160 toprint = 1;
161 }
162 } /* if "uname" */
163#endif
149 164
150 uname(&uname_info.name); /* never fails */ 165 uname(&uname_info.name); /* never fails */
151 166
152#if defined(__sparc__) && defined(__linux__) 167#if defined(__sparc__) && defined(__linux__)
153 if (fake_sparc && (fake_sparc[0] | 0x20) == 'y') { 168 {
154 strcpy(uname_info.name.machine, "sparc"); 169 char *fake_sparc = getenv("FAKE_SPARC");
155 } 170 if (fake_sparc && (fake_sparc[0] | 0x20) == 'y') {
156#endif 171 strcpy(uname_info.name.machine, "sparc");
157 strcpy(uname_info.processor, unknown_str); 172 }
158 strcpy(uname_info.platform, unknown_str);
159 strcpy(uname_info.os, CONFIG_UNAME_OSNAME);
160#if 0
161 /* Fedora does something like this */
162 strcpy(uname_info.processor, uname_info.name.machine);
163 strcpy(uname_info.platform, uname_info.name.machine);
164 if (uname_info.platform[0] == 'i'
165 && uname_info.platform[1]
166 && uname_info.platform[2] == '8'
167 && uname_info.platform[3] == '6'
168 ) {
169 uname_info.platform[1] = '3';
170 } 173 }
171#endif 174#endif
172 175 if (ENABLE_BBARCH && (!ENABLE_UNAME || applet_name[0] == 'a')) {
173 delta = utsname_offset; 176 puts(uname_info.name.machine);
174 fmt = " %s" + 1; 177 } else {
175 do { 178#if ENABLE_UNAME
176 if (toprint & 1) { 179 /* "uname" */
177 const char *p = (char *)(&uname_info) + *delta; 180 const char *fmt;
178 if (p[0]) { 181 const unsigned short *delta;
179 printf(fmt, p); 182
180 fmt = " %s"; 183 strcpy(uname_info.processor, unknown_str);
181 } 184 strcpy(uname_info.platform, unknown_str);
185 strcpy(uname_info.os, CONFIG_UNAME_OSNAME);
186# if 0
187 /* Fedora does something like this */
188 strcpy(uname_info.processor, uname_info.name.machine);
189 strcpy(uname_info.platform, uname_info.name.machine);
190 if (uname_info.platform[0] == 'i'
191 && uname_info.platform[1]
192 && uname_info.platform[2] == '8'
193 && uname_info.platform[3] == '6'
194 ) {
195 uname_info.platform[1] = '3';
182 } 196 }
183 ++delta; 197# endif
184 } while (toprint >>= 1); 198 delta = utsname_offset;
185 bb_putchar('\n'); 199 fmt = " %s" + 1;
200 do {
201 if (toprint & 1) {
202 const char *p = (char *)(&uname_info) + *delta;
203 if (p[0]) {
204 printf(fmt, p);
205 fmt = " %s";
206 }
207 }
208 ++delta;
209 } while (toprint >>= 1);
210 bb_putchar('\n');
211#endif
212 }
186 213
187 fflush_stdout_and_exit(EXIT_SUCCESS); /* coreutils-6.9 compat */ 214 fflush_stdout_and_exit(EXIT_SUCCESS); /* coreutils-6.9 compat */
188} 215}
diff --git a/coreutils/uudecode.c b/coreutils/uudecode.c
index ddce2548b..2fe771f69 100644
--- a/coreutils/uudecode.c
+++ b/coreutils/uudecode.c
@@ -47,10 +47,16 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
47 line = xmalloc_fgets_str_len(src_stream, "\n", &line_len); 47 line = xmalloc_fgets_str_len(src_stream, "\n", &line_len);
48 if (!line) 48 if (!line)
49 break; 49 break;
50 /* Handle both Unix and MSDOS text, and stray trailing spaces */ 50 /* Handle both Unix and MSDOS text.
51 * Note: space should not be trimmed, some encoders use it instead of "`"
52 * for padding of last incomplete 4-char block.
53 */
51 str_len = line_len; 54 str_len = line_len;
52 while (--str_len >= 0 && isspace(line[str_len])) 55 while (--str_len >= 0
56 && (line[str_len] == '\n' || line[str_len] == '\r')
57 ) {
53 line[str_len] = '\0'; 58 line[str_len] = '\0';
59 }
54 60
55 if (strcmp(line, "end") == 0) { 61 if (strcmp(line, "end") == 0) {
56 return; /* the only non-error exit */ 62 return; /* the only non-error exit */
@@ -65,7 +71,7 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
65 71
66 encoded_len = line[0] * 4 / 3; 72 encoded_len = line[0] * 4 / 3;
67 /* Check that line is not too short. (we tolerate 73 /* Check that line is not too short. (we tolerate
68 * overly _long_ line to accommodate possible extra '`'). 74 * overly _long_ line to accommodate possible extra "`").
69 * Empty line case is also caught here. */ 75 * Empty line case is also caught here. */
70 if (str_len <= encoded_len) { 76 if (str_len <= encoded_len) {
71 break; /* go to bb_error_msg_and_die("short file"); */ 77 break; /* go to bb_error_msg_and_die("short file"); */