aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2012-03-22 13:15:08 +0000
committerRon Yorston <rmy@pobox.com>2012-03-22 13:15:08 +0000
commitc0d4367d6b581eb5989c02815880cf0fa2851ae8 (patch)
tree868c266e627e2d7f65ba5a4d5f98a1c421453181 /coreutils
parentf6bad5ef766b0447158e3de2f55c35f1f6cecb58 (diff)
parentda4441c44f6efccb6f7b7588404d9c6bfb7b6af8 (diff)
downloadbusybox-w32-c0d4367d6b581eb5989c02815880cf0fa2851ae8.tar.gz
busybox-w32-c0d4367d6b581eb5989c02815880cf0fa2851ae8.tar.bz2
busybox-w32-c0d4367d6b581eb5989c02815880cf0fa2851ae8.zip
Merge commit 'da4441c44f6efccb6f7b7588404d9c6bfb7b6af8' into merge
Conflicts: libbb/vfork_daemon_rexec.c networking/wget.c procps/ps.c
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/Config.src10
-rw-r--r--coreutils/Kbuild.src2
-rw-r--r--coreutils/df.c2
-rw-r--r--coreutils/echo.c185
-rw-r--r--coreutils/id.c5
-rw-r--r--coreutils/length.c.disabled (renamed from coreutils/length.c)0
-rw-r--r--coreutils/stty.c20
7 files changed, 116 insertions, 108 deletions
diff --git a/coreutils/Config.src b/coreutils/Config.src
index b599f7999..6297f43a3 100644
--- a/coreutils/Config.src
+++ b/coreutils/Config.src
@@ -295,11 +295,11 @@ config FEATURE_INSTALL_LONG_OPTIONS
295 help 295 help
296 Support long options for the install applet. 296 Support long options for the install applet.
297 297
298config LENGTH 298####config LENGTH
299 bool "length" 299#### bool "length"
300 default y 300#### default y
301 help 301#### help
302 length is used to print out the length of a specified string. 302#### length is used to print out the length of a specified string.
303 303
304config LN 304config LN
305 bool "ln" 305 bool "ln"
diff --git a/coreutils/Kbuild.src b/coreutils/Kbuild.src
index 4ea0fa50a..6a41c8318 100644
--- a/coreutils/Kbuild.src
+++ b/coreutils/Kbuild.src
@@ -39,7 +39,7 @@ lib-$(CONFIG_HEAD) += head.o
39lib-$(CONFIG_HOSTID) += hostid.o 39lib-$(CONFIG_HOSTID) += hostid.o
40lib-$(CONFIG_ID) += id.o 40lib-$(CONFIG_ID) += id.o
41lib-$(CONFIG_INSTALL) += install.o 41lib-$(CONFIG_INSTALL) += install.o
42lib-$(CONFIG_LENGTH) += length.o 42#lib-$(CONFIG_LENGTH) += length.o
43lib-$(CONFIG_LN) += ln.o 43lib-$(CONFIG_LN) += ln.o
44lib-$(CONFIG_LOGNAME) += logname.o 44lib-$(CONFIG_LOGNAME) += logname.o
45lib-$(CONFIG_LS) += ls.o 45lib-$(CONFIG_LS) += ls.o
diff --git a/coreutils/df.c b/coreutils/df.c
index af9b77b23..70fd1f4fd 100644
--- a/coreutils/df.c
+++ b/coreutils/df.c
@@ -160,7 +160,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
160 } 160 }
161 161
162 /* GNU coreutils 6.10 skips certain mounts, try to be compatible. */ 162 /* GNU coreutils 6.10 skips certain mounts, try to be compatible. */
163 if (strcmp(device, "rootfs") == 0) 163 if (ENABLE_FEATURE_SKIP_ROOTFS && strcmp(device, "rootfs") == 0)
164 continue; 164 continue;
165 165
166#ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY 166#ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY
diff --git a/coreutils/echo.c b/coreutils/echo.c
index 3821e594e..72e18c161 100644
--- a/coreutils/echo.c
+++ b/coreutils/echo.c
@@ -29,122 +29,135 @@
29 29
30/* NB: can be used by shell even if not enabled as applet */ 30/* NB: can be used by shell even if not enabled as applet */
31 31
32/*
33 * NB2: we don't use stdio, we need better error handing.
34 * Examples include writing into non-opened stdout and error on write.
35 *
36 * With stdio, output gets shoveled into stdout buffer, and even
37 * fflush cannot clear it out. It seems that even if libc receives
38 * EBADF on write attempts, it feels determined to output data no matter what.
39 * If echo is called by shell, it will try writing again later, and possibly
40 * will clobber future output. Not good.
41 *
42 * Solaris has fpurge which discards buffered input. glibc has __fpurge.
43 * But this function is not standard.
44 */
45
32int echo_main(int argc UNUSED_PARAM, char **argv) 46int echo_main(int argc UNUSED_PARAM, char **argv)
33{ 47{
48 char **pp;
34 const char *arg; 49 const char *arg;
50 char *out;
51 char *buffer;
52 unsigned buflen;
35#if !ENABLE_FEATURE_FANCY_ECHO 53#if !ENABLE_FEATURE_FANCY_ECHO
36 enum { 54 enum {
37 eflag = '\\', 55 eflag = '\\',
38 nflag = 1, /* 1 -- print '\n' */ 56 nflag = 1, /* 1 -- print '\n' */
39 }; 57 };
40 58
41 /* We must check that stdout is not closed. 59 argv++;
42 * The reason for this is highly non-obvious.
43 * echo_main is used from shell. Shell must correctly handle "echo foo"
44 * if stdout is closed. With stdio, output gets shoveled into
45 * stdout buffer, and even fflush cannot clear it out. It seems that
46 * even if libc receives EBADF on write attempts, it feels determined
47 * to output data no matter what. So it will try later,
48 * and possibly will clobber future output. Not good. */
49// TODO: check fcntl() & O_ACCMODE == O_WRONLY or O_RDWR?
50 if (fcntl(1, F_GETFL) == -1)
51 return 1; /* match coreutils 6.10 (sans error msg to stderr) */
52 //if (dup2(1, 1) != 1) - old way
53 // return 1;
54
55 arg = *++argv;
56 if (!arg)
57 goto newline_ret;
58#else 60#else
59 const char *p;
60 char nflag = 1; 61 char nflag = 1;
61 char eflag = 0; 62 char eflag = 0;
62 63
63 /* We must check that stdout is not closed. */ 64 while ((arg = *++argv) != NULL) {
64 if (fcntl(1, F_GETFL) == -1) 65 char n, e;
65 return 1;
66 66
67 while (1) { 67 if (arg[0] != '-')
68 arg = *++argv; 68 break; /* not an option arg, echo it */
69 if (!arg)
70 goto newline_ret;
71 if (*arg != '-')
72 break;
73 69
74 /* If it appears that we are handling options, then make sure 70 /* If it appears that we are handling options, then make sure
75 * that all of the options specified are actually valid. 71 * that all of the options specified are actually valid.
76 * Otherwise, the string should just be echoed. 72 * Otherwise, the string should just be echoed.
77 */ 73 */
78 p = arg + 1; 74 arg++;
79 if (!*p) /* A single '-', so echo it. */ 75 n = nflag;
80 goto just_echo; 76 e = eflag;
81
82 do { 77 do {
83 if (!strrchr("neE", *p)) 78 if (*arg == 'n')
79 n = 0;
80 else if (*arg == 'e')
81 e = '\\';
82 else if (*arg != 'E') {
83 /* "-ccc" arg with one of c's invalid, echo it */
84 /* arg consisting from just "-" also handled here */
84 goto just_echo; 85 goto just_echo;
85 } while (*++p); 86 }
86 87 } while (*++arg);
87 /* All of the options in this arg are valid, so handle them. */ 88 nflag = n;
88 p = arg + 1; 89 eflag = e;
89 do {
90 if (*p == 'n')
91 nflag = 0;
92 if (*p == 'e')
93 eflag = '\\';
94 } while (*++p);
95 } 90 }
96 just_echo: 91 just_echo:
97#endif 92#endif
98 while (1) { 93
99 /* arg is already == *argv and isn't NULL */ 94 buflen = 0;
95 pp = argv;
96 while ((arg = *pp) != NULL) {
97 buflen += strlen(arg) + 1;
98 pp++;
99 }
100 out = buffer = xmalloc(buflen + 1); /* +1 is needed for "no args" case */
101
102 while ((arg = *argv) != NULL) {
100 int c; 103 int c;
101 104
102 if (!eflag) { 105 if (!eflag) {
103 /* optimization for very common case */ 106 /* optimization for very common case */
104 fputs(arg, stdout); 107 out = stpcpy(out, arg);
105 } else while ((c = *arg++)) { 108 } else
106 if (c == eflag) { /* Check for escape seq. */ 109 while ((c = *arg++) != '\0') {
110 if (c == eflag) {
111 /* This is an "\x" sequence */
112
107 if (*arg == 'c') { 113 if (*arg == 'c') {
108 /* '\c' means cancel newline and 114 /* "\c" means cancel newline and
109 * ignore all subsequent chars. */ 115 * ignore all subsequent chars. */
110 goto ret; 116 goto do_write;
111 } 117 }
112#if !ENABLE_FEATURE_FANCY_ECHO 118 /* Since SUSv3 mandates a first digit of 0, 4-digit octals
113 /* SUSv3 specifies that octal escapes must begin with '0'. */ 119 * of the form \0### are accepted. */
114 if ( ((int)(unsigned char)(*arg) - '0') >= 8) /* '8' or bigger */ 120 if (*arg == '0') {
115#endif 121 if ((unsigned char)(arg[1] - '0') < 8) {
116 { 122 /* 2nd char is 0..7: skip leading '0' */
117 /* Since SUSv3 mandates a first digit of 0, 4-digit octals 123 arg++;
118 * of the form \0### are accepted. */
119 if (*arg == '0') {
120 /* NB: don't turn "...\0" into "...\" */
121 if (arg[1] && ((unsigned char)(arg[1]) - '0') < 8) {
122 arg++;
123 }
124 } 124 }
125 /* bb_process_escape_sequence handles NUL correctly 125 }
126 * ("...\" case). */ 126 /* bb_process_escape_sequence handles NUL correctly
127 c = bb_process_escape_sequence(&arg); 127 * ("...\" case). */
128 {
129 /* optimization: don't force arg to be on-stack,
130 * use another variable for that. ~30 bytes win */
131 const char *z = arg;
132 c = bb_process_escape_sequence(&z);
133 arg = z;
128 } 134 }
129 } 135 }
130 bb_putchar(c); 136 *out++ = c;
131 } 137 }
132 138
133 arg = *++argv; 139 if (!*++argv)
134 if (!arg)
135 break; 140 break;
136 bb_putchar(' '); 141 *out++ = ' ';
137 } 142 }
138 143
139 newline_ret:
140 if (nflag) { 144 if (nflag) {
141 bb_putchar('\n'); 145 *out++ = '\n';
142 } 146 }
143 ret: 147
144 return fflush_all(); 148 do_write:
149 /* Careful to error out on partial writes too (think ENOSPC!) */
150 errno = 0;
151 /*r =*/ full_write(STDOUT_FILENO, buffer, out - buffer);
152 free(buffer);
153 if (/*WRONG:r < 0*/ errno) {
154 bb_perror_msg(bb_msg_write_error);
155 return 1;
156 }
157 return 0;
145} 158}
146 159
147/*- 160/*
148 * Copyright (c) 1991, 1993 161 * Copyright (c) 1991, 1993
149 * The Regents of the University of California. All rights reserved. 162 * The Regents of the University of California. All rights reserved.
150 * 163 *
@@ -230,7 +243,7 @@ int echo_main(int argc, char **argv)
230 goto just_echo; 243 goto just_echo;
231 244
232 do { 245 do {
233 if (!strrchr("neE", *p)) 246 if (!strchr("neE", *p))
234 goto just_echo; 247 goto just_echo;
235 } while (*++p); 248 } while (*++p);
236 249
@@ -256,27 +269,23 @@ int echo_main(int argc, char **argv)
256 /* optimization for very common case */ 269 /* optimization for very common case */
257 p += strlen(arg); 270 p += strlen(arg);
258 } else while ((c = *arg++)) { 271 } else while ((c = *arg++)) {
259 if (c == eflag) { /* Check for escape seq. */ 272 if (c == eflag) {
273 /* This is an "\x" sequence */
274
260 if (*arg == 'c') { 275 if (*arg == 'c') {
261 /* '\c' means cancel newline and 276 /* "\c" means cancel newline and
262 * ignore all subsequent chars. */ 277 * ignore all subsequent chars. */
263 cur_io->iov_len = p - (char*)cur_io->iov_base; 278 cur_io->iov_len = p - (char*)cur_io->iov_base;
264 cur_io++; 279 cur_io++;
265 goto ret; 280 goto ret;
266 } 281 }
267#if !ENABLE_FEATURE_FANCY_ECHO 282 /* Since SUSv3 mandates a first digit of 0, 4-digit octals
268 /* SUSv3 specifies that octal escapes must begin with '0'. */ 283 * of the form \0### are accepted. */
269 if ( (((unsigned char)*arg) - '1') >= 7) 284 if (*arg == '0' && (unsigned char)(arg[1] - '0') < 8) {
270#endif 285 arg++;
271 {
272 /* Since SUSv3 mandates a first digit of 0, 4-digit octals
273 * of the form \0### are accepted. */
274 if (*arg == '0' && ((unsigned char)(arg[1]) - '0') < 8) {
275 arg++;
276 }
277 /* bb_process_escape_sequence can handle nul correctly */
278 c = bb_process_escape_sequence( (void*) &arg);
279 } 286 }
287 /* bb_process_escape_sequence can handle nul correctly */
288 c = bb_process_escape_sequence( (void*) &arg);
280 } 289 }
281 *p++ = c; 290 *p++ = c;
282 } 291 }
diff --git a/coreutils/id.c b/coreutils/id.c
index ed1dc862e..0639325c3 100644
--- a/coreutils/id.c
+++ b/coreutils/id.c
@@ -176,10 +176,9 @@ int id_main(int argc UNUSED_PARAM, char **argv)
176 prefix = ","; 176 prefix = ",";
177 } 177 }
178 } else if (n < 0) { /* error in get_groups() */ 178 } else if (n < 0) { /* error in get_groups() */
179 if (!ENABLE_DESKTOP) 179 if (ENABLE_DESKTOP)
180 bb_error_msg_and_die("can't get groups"); 180 bb_error_msg_and_die("can't get groups");
181 else 181 return EXIT_FAILURE;
182 return EXIT_FAILURE;
183 } 182 }
184 if (ENABLE_FEATURE_CLEAN_UP) 183 if (ENABLE_FEATURE_CLEAN_UP)
185 free(groups); 184 free(groups);
diff --git a/coreutils/length.c b/coreutils/length.c.disabled
index 7f0b48ccd..7f0b48ccd 100644
--- a/coreutils/length.c
+++ b/coreutils/length.c.disabled
diff --git a/coreutils/stty.c b/coreutils/stty.c
index 1dd01c4dd..d8184a34f 100644
--- a/coreutils/stty.c
+++ b/coreutils/stty.c
@@ -345,7 +345,7 @@ static const char mode_name[] =
345 MI_ENTRY("icrnl", input, SANE_SET | REV, ICRNL, 0 ) 345 MI_ENTRY("icrnl", input, SANE_SET | REV, ICRNL, 0 )
346 MI_ENTRY("ixon", input, REV, IXON, 0 ) 346 MI_ENTRY("ixon", input, REV, IXON, 0 )
347 MI_ENTRY("ixoff", input, SANE_UNSET | REV, IXOFF, 0 ) 347 MI_ENTRY("ixoff", input, SANE_UNSET | REV, IXOFF, 0 )
348 MI_ENTRY("tandem", input, REV | OMIT, IXOFF, 0 ) 348 MI_ENTRY("tandem", input, OMIT | REV, IXOFF, 0 )
349#if IUCLC 349#if IUCLC
350 MI_ENTRY("iuclc", input, SANE_UNSET | REV, IUCLC, 0 ) 350 MI_ENTRY("iuclc", input, SANE_UNSET | REV, IUCLC, 0 )
351#endif 351#endif
@@ -425,7 +425,7 @@ static const char mode_name[] =
425#endif 425#endif
426 MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 ) 426 MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 )
427 MI_ENTRY("echoe", local, SANE_SET | REV, ECHOE, 0 ) 427 MI_ENTRY("echoe", local, SANE_SET | REV, ECHOE, 0 )
428 MI_ENTRY("crterase", local, REV | OMIT, ECHOE, 0 ) 428 MI_ENTRY("crterase", local, OMIT | REV, ECHOE, 0 )
429 MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 ) 429 MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 )
430 MI_ENTRY("echonl", local, SANE_UNSET | REV, ECHONL, 0 ) 430 MI_ENTRY("echonl", local, SANE_UNSET | REV, ECHONL, 0 )
431 MI_ENTRY("noflsh", local, SANE_UNSET | REV, NOFLSH, 0 ) 431 MI_ENTRY("noflsh", local, SANE_UNSET | REV, NOFLSH, 0 )
@@ -437,15 +437,15 @@ static const char mode_name[] =
437#endif 437#endif
438#if ECHOPRT 438#if ECHOPRT
439 MI_ENTRY("echoprt", local, SANE_UNSET | REV, ECHOPRT, 0 ) 439 MI_ENTRY("echoprt", local, SANE_UNSET | REV, ECHOPRT, 0 )
440 MI_ENTRY("prterase", local, REV | OMIT, ECHOPRT, 0 ) 440 MI_ENTRY("prterase", local, OMIT | REV, ECHOPRT, 0 )
441#endif 441#endif
442#if ECHOCTL 442#if ECHOCTL
443 MI_ENTRY("echoctl", local, SANE_SET | REV, ECHOCTL, 0 ) 443 MI_ENTRY("echoctl", local, SANE_SET | REV, ECHOCTL, 0 )
444 MI_ENTRY("ctlecho", local, REV | OMIT, ECHOCTL, 0 ) 444 MI_ENTRY("ctlecho", local, OMIT | REV, ECHOCTL, 0 )
445#endif 445#endif
446#if ECHOKE 446#if ECHOKE
447 MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 ) 447 MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 )
448 MI_ENTRY("crtkill", local, REV | OMIT, ECHOKE, 0 ) 448 MI_ENTRY("crtkill", local, OMIT | REV, ECHOKE, 0 )
449#endif 449#endif
450 ; 450 ;
451 451
@@ -502,7 +502,7 @@ static const struct mode_info mode_info[] = {
502 MI_ENTRY("icrnl", input, SANE_SET | REV, ICRNL, 0 ) 502 MI_ENTRY("icrnl", input, SANE_SET | REV, ICRNL, 0 )
503 MI_ENTRY("ixon", input, REV, IXON, 0 ) 503 MI_ENTRY("ixon", input, REV, IXON, 0 )
504 MI_ENTRY("ixoff", input, SANE_UNSET | REV, IXOFF, 0 ) 504 MI_ENTRY("ixoff", input, SANE_UNSET | REV, IXOFF, 0 )
505 MI_ENTRY("tandem", input, REV | OMIT, IXOFF, 0 ) 505 MI_ENTRY("tandem", input, OMIT | REV, IXOFF, 0 )
506#if IUCLC 506#if IUCLC
507 MI_ENTRY("iuclc", input, SANE_UNSET | REV, IUCLC, 0 ) 507 MI_ENTRY("iuclc", input, SANE_UNSET | REV, IUCLC, 0 )
508#endif 508#endif
@@ -582,7 +582,7 @@ static const struct mode_info mode_info[] = {
582#endif 582#endif
583 MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 ) 583 MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 )
584 MI_ENTRY("echoe", local, SANE_SET | REV, ECHOE, 0 ) 584 MI_ENTRY("echoe", local, SANE_SET | REV, ECHOE, 0 )
585 MI_ENTRY("crterase", local, REV | OMIT, ECHOE, 0 ) 585 MI_ENTRY("crterase", local, OMIT | REV, ECHOE, 0 )
586 MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 ) 586 MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 )
587 MI_ENTRY("echonl", local, SANE_UNSET | REV, ECHONL, 0 ) 587 MI_ENTRY("echonl", local, SANE_UNSET | REV, ECHONL, 0 )
588 MI_ENTRY("noflsh", local, SANE_UNSET | REV, NOFLSH, 0 ) 588 MI_ENTRY("noflsh", local, SANE_UNSET | REV, NOFLSH, 0 )
@@ -594,15 +594,15 @@ static const struct mode_info mode_info[] = {
594#endif 594#endif
595#if ECHOPRT 595#if ECHOPRT
596 MI_ENTRY("echoprt", local, SANE_UNSET | REV, ECHOPRT, 0 ) 596 MI_ENTRY("echoprt", local, SANE_UNSET | REV, ECHOPRT, 0 )
597 MI_ENTRY("prterase", local, REV | OMIT, ECHOPRT, 0 ) 597 MI_ENTRY("prterase", local, OMIT | REV, ECHOPRT, 0 )
598#endif 598#endif
599#if ECHOCTL 599#if ECHOCTL
600 MI_ENTRY("echoctl", local, SANE_SET | REV, ECHOCTL, 0 ) 600 MI_ENTRY("echoctl", local, SANE_SET | REV, ECHOCTL, 0 )
601 MI_ENTRY("ctlecho", local, REV | OMIT, ECHOCTL, 0 ) 601 MI_ENTRY("ctlecho", local, OMIT | REV, ECHOCTL, 0 )
602#endif 602#endif
603#if ECHOKE 603#if ECHOKE
604 MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 ) 604 MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 )
605 MI_ENTRY("crtkill", local, REV | OMIT, ECHOKE, 0 ) 605 MI_ENTRY("crtkill", local, OMIT | REV, ECHOKE, 0 )
606#endif 606#endif
607}; 607};
608 608