aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2015-10-31 17:13:47 +0000
committerRon Yorston <rmy@pobox.com>2015-10-31 17:13:47 +0000
commit4432dbba6559d3d88e18ecf2c33d9e5a39e82074 (patch)
treef6db886523a04e0b45926336223ff8c32761dc43 /coreutils
parentbc09f29f78547856e2152dc47051aeed548f28e8 (diff)
parent6bd3fff51aa74e2ee2d87887b12182a3b09792ef (diff)
downloadbusybox-w32-4432dbba6559d3d88e18ecf2c33d9e5a39e82074.tar.gz
busybox-w32-4432dbba6559d3d88e18ecf2c33d9e5a39e82074.tar.bz2
busybox-w32-4432dbba6559d3d88e18ecf2c33d9e5a39e82074.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/Config.src15
-rw-r--r--coreutils/ls.c2
-rw-r--r--coreutils/sort.c67
-rw-r--r--coreutils/stat.c81
-rw-r--r--coreutils/stty.c2
-rw-r--r--coreutils/tr.c23
6 files changed, 122 insertions, 68 deletions
diff --git a/coreutils/Config.src b/coreutils/Config.src
index 21b97d382..619c2efe8 100644
--- a/coreutils/Config.src
+++ b/coreutils/Config.src
@@ -543,21 +543,6 @@ config FEATURE_SPLIT_FANCY
543 Supports additional suffixes 'b' for 512 bytes, 543 Supports additional suffixes 'b' for 512 bytes,
544 'g' for 1GiB for the -b option. 544 'g' for 1GiB for the -b option.
545 545
546config STAT
547 bool "stat"
548 default y
549 help
550 display file or filesystem status.
551
552config FEATURE_STAT_FORMAT
553 bool "Enable custom formats (-c)"
554 default y
555 depends on STAT
556 help
557 Without this, stat will not support the '-c format' option where
558 users can pass a custom format string for output. This adds about
559 7k to a nonstatic build on amd64.
560
561config STTY 546config STTY
562 bool "stty" 547 bool "stty"
563 default y 548 default y
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 14c8beaff..c48498858 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -1105,7 +1105,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
1105 1105
1106#if ENABLE_FEATURE_AUTOWIDTH 1106#if ENABLE_FEATURE_AUTOWIDTH
1107 /* obtain the terminal width */ 1107 /* obtain the terminal width */
1108 get_terminal_width_height(STDIN_FILENO, &G_terminal_width, NULL); 1108 G_terminal_width = get_terminal_width(STDIN_FILENO);
1109 /* go one less... */ 1109 /* go one less... */
1110 G_terminal_width--; 1110 G_terminal_width--;
1111#endif 1111#endif
diff --git a/coreutils/sort.c b/coreutils/sort.c
index 36f02543b..07d903388 100644
--- a/coreutils/sort.c
+++ b/coreutils/sort.c
@@ -106,7 +106,9 @@ static struct sort_key {
106 106
107static char *get_key(char *str, struct sort_key *key, int flags) 107static char *get_key(char *str, struct sort_key *key, int flags)
108{ 108{
109 int start = 0, end = 0, len, j; 109 int start = start; /* for compiler */
110 int end;
111 int len, j;
110 unsigned i; 112 unsigned i;
111 113
112 /* Special case whole string, so we don't have to make a copy */ 114 /* Special case whole string, so we don't have to make a copy */
@@ -123,12 +125,15 @@ static char *get_key(char *str, struct sort_key *key, int flags)
123 end = len; 125 end = len;
124 /* Loop through fields */ 126 /* Loop through fields */
125 else { 127 else {
128 unsigned char ch = 0;
129
126 end = 0; 130 end = 0;
127 for (i = 1; i < key->range[2*j] + j; i++) { 131 for (i = 1; i < key->range[2*j] + j; i++) {
128 if (key_separator) { 132 if (key_separator) {
129 /* Skip body of key and separator */ 133 /* Skip body of key and separator */
130 while (str[end]) { 134 while ((ch = str[end]) != '\0') {
131 if (str[end++] == key_separator) 135 end++;
136 if (ch == key_separator)
132 break; 137 break;
133 } 138 }
134 } else { 139 } else {
@@ -136,7 +141,7 @@ static char *get_key(char *str, struct sort_key *key, int flags)
136 while (isspace(str[end])) 141 while (isspace(str[end]))
137 end++; 142 end++;
138 /* Skip body of key */ 143 /* Skip body of key */
139 while (str[end]) { 144 while (str[end] != '\0') {
140 if (isspace(str[end])) 145 if (isspace(str[end]))
141 break; 146 break;
142 end++; 147 end++;
@@ -144,23 +149,29 @@ static char *get_key(char *str, struct sort_key *key, int flags)
144 } 149 }
145 } 150 }
146 /* Remove last delim: "abc:def:" => "abc:def" */ 151 /* Remove last delim: "abc:def:" => "abc:def" */
147 if (key_separator && j && end != 0) 152 if (j && ch) {
153 //if (str[end-1] != key_separator)
154 // bb_error_msg(_and_die("BUG! "
155 // "str[start:%d,end:%d]:'%.*s'",
156 // start, end, (int)(end-start), &str[start]);
148 end--; 157 end--;
158 }
149 } 159 }
150 if (!j) start = end; 160 if (!j) start = end;
151 } 161 }
152 /* Strip leading whitespace if necessary */ 162 /* Strip leading whitespace if necessary */
153//XXX: skip_whitespace()
154 if (flags & FLAG_b) 163 if (flags & FLAG_b)
164 /* not using skip_whitespace() for speed */
155 while (isspace(str[start])) start++; 165 while (isspace(str[start])) start++;
156 /* Strip trailing whitespace if necessary */ 166 /* Strip trailing whitespace if necessary */
157 if (flags & FLAG_bb) 167 if (flags & FLAG_bb)
158 while (end > start && isspace(str[end-1])) end--; 168 while (end > start && isspace(str[end-1])) end--;
159 /* Handle offsets on start and end */ 169 /* -kSTART,N.ENDCHAR: honor ENDCHAR (1-based) */
160 if (key->range[3]) { 170 if (key->range[3]) {
161 end += key->range[3] - 1; 171 end = key->range[3];
162 if (end > len) end = len; 172 if (end > len) end = len;
163 } 173 }
174 /* -kN.STARTCHAR[,...]: honor STARTCHAR (1-based) */
164 if (key->range[1]) { 175 if (key->range[1]) {
165 start += key->range[1] - 1; 176 start += key->range[1] - 1;
166 if (start > len) start = len; 177 if (start > len) start = len;
@@ -281,7 +292,7 @@ static int compare_keys(const void *xarg, const void *yarg)
281 else if (!yy) 292 else if (!yy)
282 retval = 1; 293 retval = 1;
283 else 294 else
284 retval = (dx == thyme.tm_mon) ? 0 : dx - thyme.tm_mon; 295 retval = dx - thyme.tm_mon;
285 break; 296 break;
286 } 297 }
287 /* Full floating point version of -n */ 298 /* Full floating point version of -n */
@@ -307,8 +318,8 @@ static int compare_keys(const void *xarg, const void *yarg)
307 318
308 /* Perform fallback sort if necessary */ 319 /* Perform fallback sort if necessary */
309 if (!retval && !(option_mask32 & FLAG_s)) { 320 if (!retval && !(option_mask32 & FLAG_s)) {
310 retval = strcmp(*(char **)xarg, *(char **)yarg);
311 flags = option_mask32; 321 flags = option_mask32;
322 retval = strcmp(*(char **)xarg, *(char **)yarg);
312 } 323 }
313 324
314 if (flags & FLAG_r) 325 if (flags & FLAG_r)
@@ -336,7 +347,7 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
336 char *line, **lines; 347 char *line, **lines;
337 char *str_ignored, *str_o, *str_t; 348 char *str_ignored, *str_o, *str_t;
338 llist_t *lst_k = NULL; 349 llist_t *lst_k = NULL;
339 int i, flag; 350 int i;
340 int linecount; 351 int linecount;
341 unsigned opts; 352 unsigned opts;
342 353
@@ -359,7 +370,7 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
359 /* note: below this point we use option_mask32, not opts, 370 /* note: below this point we use option_mask32, not opts,
360 * since that reduces register pressure and makes code smaller */ 371 * since that reduces register pressure and makes code smaller */
361 372
362 /* parse sort key */ 373 /* Parse sort key */
363 while (lst_k) { 374 while (lst_k) {
364 enum { 375 enum {
365 FLAG_allowed_for_k = 376 FLAG_allowed_for_k =
@@ -386,17 +397,18 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
386 key->range[2*i+1] = str2u(&str_k); 397 key->range[2*i+1] = str2u(&str_k);
387 } 398 }
388 while (*str_k) { 399 while (*str_k) {
389 const char *temp2; 400 int flag;
401 const char *idx;
390 402
391 if (*str_k == ',' && !i++) { 403 if (*str_k == ',' && !i++) {
392 str_k++; 404 str_k++;
393 break; 405 break;
394 } /* no else needed: fall through to syntax error 406 } /* no else needed: fall through to syntax error
395 because comma isn't in OPT_STR */ 407 because comma isn't in OPT_STR */
396 temp2 = strchr(OPT_STR, *str_k); 408 idx = strchr(OPT_STR, *str_k);
397 if (!temp2) 409 if (!idx)
398 bb_error_msg_and_die("unknown key option"); 410 bb_error_msg_and_die("unknown key option");
399 flag = 1 << (temp2 - OPT_STR); 411 flag = 1 << (idx - OPT_STR);
400 if (flag & ~FLAG_allowed_for_k) 412 if (flag & ~FLAG_allowed_for_k)
401 bb_error_msg_and_die("unknown sort type"); 413 bb_error_msg_and_die("unknown sort type");
402 /* b after ',' means strip _trailing_ space */ 414 /* b after ',' means strip _trailing_ space */
@@ -430,10 +442,10 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
430 } while (*++argv); 442 } while (*++argv);
431 443
432#if ENABLE_FEATURE_SORT_BIG 444#if ENABLE_FEATURE_SORT_BIG
433 /* if no key, perform alphabetic sort */ 445 /* If no key, perform alphabetic sort */
434 if (!key_list) 446 if (!key_list)
435 add_key()->range[0] = 1; 447 add_key()->range[0] = 1;
436 /* handle -c */ 448 /* Handle -c */
437 if (option_mask32 & FLAG_c) { 449 if (option_mask32 & FLAG_c) {
438 int j = (option_mask32 & FLAG_u) ? -1 : 0; 450 int j = (option_mask32 & FLAG_u) ? -1 : 0;
439 for (i = 1; i < linecount; i++) { 451 for (i = 1; i < linecount; i++) {
@@ -447,20 +459,21 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
447#endif 459#endif
448 /* Perform the actual sort */ 460 /* Perform the actual sort */
449 qsort(lines, linecount, sizeof(lines[0]), compare_keys); 461 qsort(lines, linecount, sizeof(lines[0]), compare_keys);
450 /* handle -u */ 462
463 /* Handle -u */
451 if (option_mask32 & FLAG_u) { 464 if (option_mask32 & FLAG_u) {
452 flag = 0; 465 int j = 0;
453 /* coreutils 6.3 drop lines for which only key is the same */ 466 /* coreutils 6.3 drop lines for which only key is the same */
454 /* -- disabling last-resort compare... */ 467 /* -- disabling last-resort compare... */
455 option_mask32 |= FLAG_s; 468 option_mask32 |= FLAG_s;
456 for (i = 1; i < linecount; i++) { 469 for (i = 1; i < linecount; i++) {
457 if (compare_keys(&lines[flag], &lines[i]) == 0) 470 if (compare_keys(&lines[j], &lines[i]) == 0)
458 free(lines[i]); 471 free(lines[i]);
459 else 472 else
460 lines[++flag] = lines[i]; 473 lines[++j] = lines[i];
461 } 474 }
462 if (linecount) 475 if (linecount)
463 linecount = flag+1; 476 linecount = j+1;
464 } 477 }
465 478
466 /* Print it */ 479 /* Print it */
@@ -469,9 +482,11 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
469 if (option_mask32 & FLAG_o) 482 if (option_mask32 & FLAG_o)
470 xmove_fd(xopen(str_o, O_WRONLY|O_CREAT|O_TRUNC), STDOUT_FILENO); 483 xmove_fd(xopen(str_o, O_WRONLY|O_CREAT|O_TRUNC), STDOUT_FILENO);
471#endif 484#endif
472 flag = (option_mask32 & FLAG_z) ? '\0' : '\n'; 485 {
473 for (i = 0; i < linecount; i++) 486 int ch = (option_mask32 & FLAG_z) ? '\0' : '\n';
474 printf("%s%c", lines[i], flag); 487 for (i = 0; i < linecount; i++)
488 printf("%s%c", lines[i], ch);
489 }
475 490
476 fflush_stdout_and_exit(EXIT_SUCCESS); 491 fflush_stdout_and_exit(EXIT_SUCCESS);
477} 492}
diff --git a/coreutils/stat.c b/coreutils/stat.c
index f7fd227bb..1a490fef7 100644
--- a/coreutils/stat.c
+++ b/coreutils/stat.c
@@ -12,54 +12,83 @@
12 * 12 *
13 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 13 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
14 */ 14 */
15//config:config STAT
16//config: bool "stat"
17//config: default y
18//config: help
19//config: display file or filesystem status.
20//config:
21//config:config FEATURE_STAT_FORMAT
22//config: bool "Enable custom formats (-c)"
23//config: default y
24//config: depends on STAT
25//config: help
26//config: Without this, stat will not support the '-c format' option where
27//config: users can pass a custom format string for output. This adds about
28//config: 7k to a nonstatic build on amd64.
29//config:
30//config:config FEATURE_STAT_FILESYSTEM
31//config: bool "Enable display of filesystem status (-f)"
32//config: default y
33//config: depends on STAT
34//config: select PLATFORM_LINUX # statfs()
35//config: help
36//config: Without this, stat will not support the '-f' option to display
37//config: information about filesystem status.
38
15 39
16//usage:#define stat_trivial_usage 40//usage:#define stat_trivial_usage
17//usage: "[OPTIONS] FILE..." 41//usage: "[OPTIONS] FILE..."
18//usage:#define stat_full_usage "\n\n" 42//usage:#define stat_full_usage "\n\n"
19//usage: "Display file (default) or filesystem status\n" 43//usage: "Display file"
44//usage: IF_FEATURE_STAT_FILESYSTEM(" (default) or filesystem")
45//usage: " status\n"
20//usage: IF_FEATURE_STAT_FORMAT( 46//usage: IF_FEATURE_STAT_FORMAT(
21//usage: "\n -c fmt Use the specified format" 47//usage: "\n -c FMT Use the specified format"
22//usage: ) 48//usage: )
49//usage: IF_FEATURE_STAT_FILESYSTEM(
23//usage: "\n -f Display filesystem status" 50//usage: "\n -f Display filesystem status"
51//usage: )
24//usage: "\n -L Follow links" 52//usage: "\n -L Follow links"
25//usage: "\n -t Display info in terse form" 53//usage: "\n -t Terse display"
26//usage: IF_SELINUX( 54//usage: IF_SELINUX(
27//usage: "\n -Z Print security context" 55//usage: "\n -Z Print security context"
28//usage: ) 56//usage: )
29//usage: IF_FEATURE_STAT_FORMAT( 57//usage: IF_FEATURE_STAT_FORMAT(
30//usage: "\n\nValid format sequences for files:\n" 58//usage: "\n\nFMT sequences"IF_FEATURE_STAT_FILESYSTEM(" for files")":\n"
31//usage: " %a Access rights in octal\n" 59//usage: " %a Access rights in octal\n"
32//usage: " %A Access rights in human readable form\n" 60//usage: " %A Access rights in human readable form\n"
33//usage: " %b Number of blocks allocated (see %B)\n" 61//usage: " %b Number of blocks allocated (see %B)\n"
34//usage: " %B The size in bytes of each block reported by %b\n" 62//usage: " %B Size in bytes of each block reported by %b\n"
35//usage: " %d Device number in decimal\n" 63//usage: " %d Device number in decimal\n"
36//usage: " %D Device number in hex\n" 64//usage: " %D Device number in hex\n"
37//usage: " %f Raw mode in hex\n" 65//usage: " %f Raw mode in hex\n"
38//usage: " %F File type\n" 66//usage: " %F File type\n"
39//usage: " %g Group ID of owner\n" 67//usage: " %g Group ID\n"
40//usage: " %G Group name of owner\n" 68//usage: " %G Group name\n"
41//usage: " %h Number of hard links\n" 69//usage: " %h Number of hard links\n"
42//usage: " %i Inode number\n" 70//usage: " %i Inode number\n"
43//usage: " %n File name\n" 71//usage: " %n File name\n"
44//usage: " %N File name, with -> TARGET if symlink\n" 72//usage: " %N File name, with -> TARGET if symlink\n"
45//usage: " %o I/O block size\n" 73//usage: " %o I/O block size\n"
46//usage: " %s Total size, in bytes\n" 74//usage: " %s Total size in bytes\n"
47//usage: " %t Major device type in hex\n" 75//usage: " %t Major device type in hex\n"
48//usage: " %T Minor device type in hex\n" 76//usage: " %T Minor device type in hex\n"
49//usage: " %u User ID of owner\n" 77//usage: " %u User ID\n"
50//usage: " %U User name of owner\n" 78//usage: " %U User name\n"
51//usage: " %x Time of last access\n" 79//usage: " %x Time of last access\n"
52//usage: " %X Time of last access as seconds since Epoch\n" 80//usage: " %X Time of last access as seconds since Epoch\n"
53//usage: " %y Time of last modification\n" 81//usage: " %y Time of last modification\n"
54//usage: " %Y Time of last modification as seconds since Epoch\n" 82//usage: " %Y Time of last modification as seconds since Epoch\n"
55//usage: " %z Time of last change\n" 83//usage: " %z Time of last change\n"
56//usage: " %Z Time of last change as seconds since Epoch\n" 84//usage: " %Z Time of last change as seconds since Epoch\n"
57//usage: "\nValid format sequences for file systems:\n" 85//usage: IF_FEATURE_STAT_FILESYSTEM(
86//usage: "\nFMT sequences for file systems:\n"
58//usage: " %a Free blocks available to non-superuser\n" 87//usage: " %a Free blocks available to non-superuser\n"
59//usage: " %b Total data blocks in file system\n" 88//usage: " %b Total data blocks\n"
60//usage: " %c Total file nodes in file system\n" 89//usage: " %c Total file nodes\n"
61//usage: " %d Free file nodes in file system\n" 90//usage: " %d Free file nodes\n"
62//usage: " %f Free blocks in file system\n" 91//usage: " %f Free blocks\n"
63//usage: IF_SELINUX( 92//usage: IF_SELINUX(
64//usage: " %C Security context in selinux\n" 93//usage: " %C Security context in selinux\n"
65//usage: ) 94//usage: )
@@ -71,13 +100,16 @@
71//usage: " %t Type in hex\n" 100//usage: " %t Type in hex\n"
72//usage: " %T Type in human readable form" 101//usage: " %T Type in human readable form"
73//usage: ) 102//usage: )
103//usage: )
74 104
75#include "libbb.h" 105#include "libbb.h"
76 106
77#define OPT_FILESYS (1 << 0) 107enum {
78#define OPT_TERSE (1 << 1) 108 OPT_TERSE = (1 << 0),
79#define OPT_DEREFERENCE (1 << 2) 109 OPT_DEREFERENCE = (1 << 1),
80#define OPT_SELINUX (1 << 3) 110 OPT_FILESYS = (1 << 2) * ENABLE_FEATURE_STAT_FILESYSTEM,
111 OPT_SELINUX = (1 << (2+ENABLE_FEATURE_STAT_FILESYSTEM)) * ENABLE_SELINUX,
112};
81 113
82#if ENABLE_FEATURE_STAT_FORMAT 114#if ENABLE_FEATURE_STAT_FORMAT
83typedef bool (*statfunc_ptr)(const char *, const char *); 115typedef bool (*statfunc_ptr)(const char *, const char *);
@@ -132,6 +164,7 @@ static const char *human_time(time_t t)
132#undef buf 164#undef buf
133} 165}
134 166
167#if ENABLE_FEATURE_STAT_FILESYSTEM
135/* Return the type of the specified file system. 168/* Return the type of the specified file system.
136 * Some systems have statfvs.f_basetype[FSTYPSZ]. (AIX, HP-UX, and Solaris) 169 * Some systems have statfvs.f_basetype[FSTYPSZ]. (AIX, HP-UX, and Solaris)
137 * Others have statfs.f_fstypename[MFSNAMELEN]. (NetBSD 1.5.2) 170 * Others have statfs.f_fstypename[MFSNAMELEN]. (NetBSD 1.5.2)
@@ -202,6 +235,7 @@ static unsigned long long get_f_fsid(const struct statfs *statfsbuf)
202 while (--sz > 0); 235 while (--sz > 0);
203 return r; 236 return r;
204} 237}
238#endif /* FEATURE_STAT_FILESYSTEM */
205 239
206#if ENABLE_FEATURE_STAT_FORMAT 240#if ENABLE_FEATURE_STAT_FORMAT
207static void strcatc(char *str, char c) 241static void strcatc(char *str, char c)
@@ -217,6 +251,7 @@ static void printfs(char *pformat, const char *msg)
217 printf(pformat, msg); 251 printf(pformat, msg);
218} 252}
219 253
254#if ENABLE_FEATURE_STAT_FILESYSTEM
220/* print statfs info */ 255/* print statfs info */
221static void FAST_FUNC print_statfs(char *pformat, const char m, 256static void FAST_FUNC print_statfs(char *pformat, const char m,
222 const char *const filename, const void *data 257 const char *const filename, const void *data
@@ -263,6 +298,7 @@ static void FAST_FUNC print_statfs(char *pformat, const char m,
263 printf(pformat, m); 298 printf(pformat, m);
264 } 299 }
265} 300}
301#endif
266 302
267/* print stat info */ 303/* print stat info */
268static void FAST_FUNC print_stat(char *pformat, const char m, 304static void FAST_FUNC print_stat(char *pformat, const char m,
@@ -423,6 +459,7 @@ static void print_it(const char *masterformat,
423} 459}
424#endif /* FEATURE_STAT_FORMAT */ 460#endif /* FEATURE_STAT_FORMAT */
425 461
462#if ENABLE_FEATURE_STAT_FILESYSTEM
426/* Stat the file system and print what we find. */ 463/* Stat the file system and print what we find. */
427#if !ENABLE_FEATURE_STAT_FORMAT 464#if !ENABLE_FEATURE_STAT_FORMAT
428#define do_statfs(filename, format) do_statfs(filename) 465#define do_statfs(filename, format) do_statfs(filename)
@@ -538,6 +575,7 @@ static bool do_statfs(const char *filename, const char *format)
538#endif /* FEATURE_STAT_FORMAT */ 575#endif /* FEATURE_STAT_FORMAT */
539 return 1; 576 return 1;
540} 577}
578#endif /* FEATURE_STAT_FILESYSTEM */
541 579
542/* stat the file and print what we find */ 580/* stat the file and print what we find */
543#if !ENABLE_FEATURE_STAT_FORMAT 581#if !ENABLE_FEATURE_STAT_FORMAT
@@ -721,12 +759,15 @@ int stat_main(int argc UNUSED_PARAM, char **argv)
721 statfunc_ptr statfunc = do_stat; 759 statfunc_ptr statfunc = do_stat;
722 760
723 opt_complementary = "-1"; /* min one arg */ 761 opt_complementary = "-1"; /* min one arg */
724 opts = getopt32(argv, "ftL" 762 opts = getopt32(argv, "tL"
763 IF_FEATURE_STAT_FILESYSTEM("f")
725 IF_SELINUX("Z") 764 IF_SELINUX("Z")
726 IF_FEATURE_STAT_FORMAT("c:", &format) 765 IF_FEATURE_STAT_FORMAT("c:", &format)
727 ); 766 );
767#if ENABLE_FEATURE_STAT_FILESYSTEM
728 if (opts & OPT_FILESYS) /* -f */ 768 if (opts & OPT_FILESYS) /* -f */
729 statfunc = do_statfs; 769 statfunc = do_statfs;
770#endif
730#if ENABLE_SELINUX 771#if ENABLE_SELINUX
731 if (opts & OPT_SELINUX) { 772 if (opts & OPT_SELINUX) {
732 selinux_or_die(); 773 selinux_or_die();
diff --git a/coreutils/stty.c b/coreutils/stty.c
index 378a848e7..b63b0b91a 100644
--- a/coreutils/stty.c
+++ b/coreutils/stty.c
@@ -1403,7 +1403,7 @@ int stty_main(int argc UNUSED_PARAM, char **argv)
1403 perror_on_device_and_die("%s"); 1403 perror_on_device_and_die("%s");
1404 1404
1405 if (stty_state & (STTY_verbose_output | STTY_recoverable_output | STTY_noargs)) { 1405 if (stty_state & (STTY_verbose_output | STTY_recoverable_output | STTY_noargs)) {
1406 get_terminal_width_height(STDOUT_FILENO, &G.max_col, NULL); 1406 G.max_col = get_terminal_width(STDOUT_FILENO);
1407 output_func(&mode, display_all); 1407 output_func(&mode, display_all);
1408 return EXIT_SUCCESS; 1408 return EXIT_SUCCESS;
1409 } 1409 }
diff --git a/coreutils/tr.c b/coreutils/tr.c
index e67948a36..2f49d5a86 100644
--- a/coreutils/tr.c
+++ b/coreutils/tr.c
@@ -91,7 +91,6 @@ static void map(char *pvector,
91 * Character classes, e.g. [:upper:] ==> A...Z 91 * Character classes, e.g. [:upper:] ==> A...Z
92 * Equiv classess, e.g. [=A=] ==> A (hmmmmmmm?) 92 * Equiv classess, e.g. [=A=] ==> A (hmmmmmmm?)
93 * not supported: 93 * not supported:
94 * \ooo-\ooo - octal ranges
95 * [x*N] - repeat char x N times 94 * [x*N] - repeat char x N times
96 * [x*] - repeat char x until it fills STRING2: 95 * [x*] - repeat char x until it fills STRING2:
97 * # echo qwe123 | /usr/bin/tr 123456789 '[d]' 96 * # echo qwe123 | /usr/bin/tr 123456789 '[d]'
@@ -99,7 +98,7 @@ static void map(char *pvector,
99 * # echo qwe123 | /usr/bin/tr 123456789 '[d*]' 98 * # echo qwe123 | /usr/bin/tr 123456789 '[d*]'
100 * qweddd 99 * qweddd
101 */ 100 */
102static unsigned expand(const char *arg, char **buffer_p) 101static unsigned expand(char *arg, char **buffer_p)
103{ 102{
104 char *buffer = *buffer_p; 103 char *buffer = *buffer_p;
105 unsigned pos = 0; 104 unsigned pos = 0;
@@ -113,9 +112,17 @@ static unsigned expand(const char *arg, char **buffer_p)
113 *buffer_p = buffer = xrealloc(buffer, size); 112 *buffer_p = buffer = xrealloc(buffer, size);
114 } 113 }
115 if (*arg == '\\') { 114 if (*arg == '\\') {
115 const char *z;
116 arg++; 116 arg++;
117 buffer[pos++] = bb_process_escape_sequence(&arg); 117 z = arg;
118 continue; 118 ac = bb_process_escape_sequence(&z);
119 arg = (char *)z;
120 arg--;
121 *arg = ac;
122 /*
123 * fall through, there may be a range.
124 * If not, current char will be treated anyway.
125 */
119 } 126 }
120 if (arg[1] == '-') { /* "0-9..." */ 127 if (arg[1] == '-') { /* "0-9..." */
121 ac = arg[2]; 128 ac = arg[2];
@@ -124,9 +131,15 @@ static unsigned expand(const char *arg, char **buffer_p)
124 continue; /* next iter will copy '-' and stop */ 131 continue; /* next iter will copy '-' and stop */
125 } 132 }
126 i = (unsigned char) *arg; 133 i = (unsigned char) *arg;
134 arg += 3; /* skip 0-9 or 0-\ */
135 if (ac == '\\') {
136 const char *z;
137 z = arg;
138 ac = bb_process_escape_sequence(&z);
139 arg = (char *)z;
140 }
127 while (i <= ac) /* ok: i is unsigned _int_ */ 141 while (i <= ac) /* ok: i is unsigned _int_ */
128 buffer[pos++] = i++; 142 buffer[pos++] = i++;
129 arg += 3; /* skip 0-9 */
130 continue; 143 continue;
131 } 144 }
132 if ((ENABLE_FEATURE_TR_CLASSES || ENABLE_FEATURE_TR_EQUIV) 145 if ((ENABLE_FEATURE_TR_CLASSES || ENABLE_FEATURE_TR_EQUIV)