aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2012-03-23 11:13:23 +0000
committerRon Yorston <rmy@pobox.com>2012-03-23 11:13:23 +0000
commit40514a0309939f2446f0d4ed9600cad5de396e7f (patch)
tree0f5f4a57d4bb7893418b5bb11d482858eb17ba8b /coreutils
parent9db164d6e39050d09f38288c6045cd2a2cbf6d63 (diff)
parentc0cae52662ccced9df19f19ec94238d1b1e3bd71 (diff)
downloadbusybox-w32-40514a0309939f2446f0d4ed9600cad5de396e7f.tar.gz
busybox-w32-40514a0309939f2446f0d4ed9600cad5de396e7f.tar.bz2
busybox-w32-40514a0309939f2446f0d4ed9600cad5de396e7f.zip
Merge commit 'c0cae52662ccced9df19f19ec94238d1b1e3bd71' into merge
Conflicts: Makefile.flags scripts/basic/fixdep.c
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/Config.src7
-rw-r--r--coreutils/Kbuild.src1
-rw-r--r--coreutils/du.c3
-rw-r--r--coreutils/expr.c3
-rw-r--r--coreutils/hostid.c13
-rw-r--r--coreutils/pwd.c52
-rw-r--r--coreutils/stty.c12
-rw-r--r--coreutils/tail.c9
-rw-r--r--coreutils/uudecode.c5
9 files changed, 85 insertions, 20 deletions
diff --git a/coreutils/Config.src b/coreutils/Config.src
index cff2ce216..81be71993 100644
--- a/coreutils/Config.src
+++ b/coreutils/Config.src
@@ -269,13 +269,6 @@ config FEATURE_FANCY_HEAD
269 help 269 help
270 This enables the head options (-c, -q, and -v). 270 This enables the head options (-c, -q, and -v).
271 271
272config HOSTID
273 bool "hostid"
274 default y
275 help
276 hostid prints the numeric identifier (in hexadecimal) for
277 the current host.
278
279config INSTALL 272config INSTALL
280 bool "install" 273 bool "install"
281 default y 274 default y
diff --git a/coreutils/Kbuild.src b/coreutils/Kbuild.src
index 53d88b391..d6453f014 100644
--- a/coreutils/Kbuild.src
+++ b/coreutils/Kbuild.src
@@ -36,7 +36,6 @@ lib-$(CONFIG_FALSE) += false.o
36lib-$(CONFIG_FOLD) += fold.o 36lib-$(CONFIG_FOLD) += fold.o
37lib-$(CONFIG_FSYNC) += fsync.o 37lib-$(CONFIG_FSYNC) += fsync.o
38lib-$(CONFIG_HEAD) += head.o 38lib-$(CONFIG_HEAD) += head.o
39lib-$(CONFIG_HOSTID) += hostid.o
40lib-$(CONFIG_INSTALL) += install.o 39lib-$(CONFIG_INSTALL) += install.o
41#lib-$(CONFIG_LENGTH) += length.o 40#lib-$(CONFIG_LENGTH) += length.o
42lib-$(CONFIG_LN) += ln.o 41lib-$(CONFIG_LN) += ln.o
diff --git a/coreutils/du.c b/coreutils/du.c
index b8bbe3d9e..34a549f02 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -88,6 +88,7 @@ struct globals {
88 dev_t dir_dev; 88 dev_t dir_dev;
89} FIX_ALIASING; 89} FIX_ALIASING;
90#define G (*(struct globals*)&bb_common_bufsiz1) 90#define G (*(struct globals*)&bb_common_bufsiz1)
91#define INIT_G() do { } while (0)
91 92
92 93
93static void print(unsigned long size, const char *filename) 94static void print(unsigned long size, const char *filename)
@@ -193,6 +194,8 @@ int du_main(int argc UNUSED_PARAM, char **argv)
193 int slink_depth_save; 194 int slink_depth_save;
194 unsigned opt; 195 unsigned opt;
195 196
197 INIT_G();
198
196#if ENABLE_FEATURE_HUMAN_READABLE 199#if ENABLE_FEATURE_HUMAN_READABLE
197 IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 1024;) 200 IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 1024;)
198 IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 512;) 201 IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 512;)
diff --git a/coreutils/expr.c b/coreutils/expr.c
index 24e75b556..c986f9327 100644
--- a/coreutils/expr.c
+++ b/coreutils/expr.c
@@ -100,6 +100,7 @@ struct globals {
100 char **args; 100 char **args;
101} FIX_ALIASING; 101} FIX_ALIASING;
102#define G (*(struct globals*)&bb_common_bufsiz1) 102#define G (*(struct globals*)&bb_common_bufsiz1)
103#define INIT_G() do { } while (0)
103 104
104/* forward declarations */ 105/* forward declarations */
105static VALUE *eval(void); 106static VALUE *eval(void);
@@ -519,6 +520,8 @@ int expr_main(int argc UNUSED_PARAM, char **argv)
519{ 520{
520 VALUE *v; 521 VALUE *v;
521 522
523 INIT_G();
524
522 xfunc_error_retval = 2; /* coreutils compat */ 525 xfunc_error_retval = 2; /* coreutils compat */
523 G.args = argv + 1; 526 G.args = argv + 1;
524 if (*G.args == NULL) { 527 if (*G.args == NULL) {
diff --git a/coreutils/hostid.c b/coreutils/hostid.c
index 49409b9de..5c1a4e086 100644
--- a/coreutils/hostid.c
+++ b/coreutils/hostid.c
@@ -9,6 +9,17 @@
9 9
10/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */ 10/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
11 11
12//config:config HOSTID
13//config: bool "hostid"
14//config: default y
15//config: help
16//config: hostid prints the numeric identifier (in hexadecimal) for
17//config: the current host.
18
19//applet:IF_HOSTID(APPLET_NOFORK(hostid, hostid, BB_DIR_USR_BIN, BB_SUID_DROP, hostid))
20
21//kbuild:lib-$(CONFIG_HOSTID) += hostid.o
22
12//usage:#define hostid_trivial_usage 23//usage:#define hostid_trivial_usage
13//usage: "" 24//usage: ""
14//usage:#define hostid_full_usage "\n\n" 25//usage:#define hostid_full_usage "\n\n"
@@ -25,7 +36,7 @@ int hostid_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
25 bb_show_usage(); 36 bb_show_usage();
26 } 37 }
27 38
28 printf("%lx\n", gethostid()); 39 printf("%08lx\n", gethostid());
29 40
30 return fflush_all(); 41 return fflush_all();
31} 42}
diff --git a/coreutils/pwd.c b/coreutils/pwd.c
index 739b835b5..bb3ad04fc 100644
--- a/coreutils/pwd.c
+++ b/coreutils/pwd.c
@@ -20,13 +20,63 @@
20 20
21/* This is a NOFORK applet. Be very careful! */ 21/* This is a NOFORK applet. Be very careful! */
22 22
23static int logical_getcwd(void)
24{
25 struct stat st1;
26 struct stat st2;
27 char *wd;
28 char *p;
29
30 wd = getenv("PWD");
31 if (!wd || wd[0] != '/')
32 return 0;
33
34 p = wd;
35 while (*p) {
36 /* doing strstr(p, "/.") by hand is smaller and faster... */
37 if (*p++ != '/')
38 continue;
39 if (*p != '.')
40 continue;
41 /* we found "/.", skip to next char */
42 p++;
43 if (*p == '.')
44 p++; /* we found "/.." */
45 if (*p == '\0' || *p == '/')
46 return 0; /* "/./" or "/../" component: bad */
47 }
48
49 if (stat(wd, &st1) != 0)
50 return 0;
51 if (stat(".", &st2) != 0)
52 return 0;
53 if (st1.st_ino != st2.st_ino)
54 return 0;
55 if (st1.st_dev != st2.st_dev)
56 return 0;
57
58 puts(wd);
59 return 1;
60}
61
23int pwd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 62int pwd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
24int pwd_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) 63int pwd_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
25{ 64{
26 char *buf; 65 char *buf;
27 66
67 if (ENABLE_DESKTOP) {
68 /* TODO: assume -L if $POSIXLY_CORRECT? (coreutils does that)
69 * Rationale:
70 * POSIX requires a default of -L, but most scripts expect -P
71 */
72 unsigned opt = getopt32(argv, "LP");
73 if ((opt & 1) && logical_getcwd())
74 return fflush_all();
75 }
76
28 buf = xrealloc_getcwd_or_warn(NULL); 77 buf = xrealloc_getcwd_or_warn(NULL);
29 if (buf != NULL) { 78
79 if (buf) {
30 puts(buf); 80 puts(buf);
31 free(buf); 81 free(buf);
32 return fflush_all(); 82 return fflush_all();
diff --git a/coreutils/stty.c b/coreutils/stty.c
index 7f057ead2..0668cf7be 100644
--- a/coreutils/stty.c
+++ b/coreutils/stty.c
@@ -1404,13 +1404,15 @@ int stty_main(int argc UNUSED_PARAM, char **argv)
1404 1404
1405 /* Specifying both -a and -g is an error */ 1405 /* Specifying both -a and -g is an error */
1406 if ((stty_state & (STTY_verbose_output | STTY_recoverable_output)) == 1406 if ((stty_state & (STTY_verbose_output | STTY_recoverable_output)) ==
1407 (STTY_verbose_output | STTY_recoverable_output)) 1407 (STTY_verbose_output | STTY_recoverable_output)
1408 bb_error_msg_and_die("verbose and stty-readable output styles are mutually exclusive"); 1408 ) {
1409 bb_error_msg_and_die("-a and -g are mutually exclusive");
1410 }
1409 /* Specifying -a or -g with non-options is an error */ 1411 /* Specifying -a or -g with non-options is an error */
1410 if (!(stty_state & STTY_noargs) 1412 if ((stty_state & (STTY_verbose_output | STTY_recoverable_output))
1411 && (stty_state & (STTY_verbose_output | STTY_recoverable_output)) 1413 && !(stty_state & STTY_noargs)
1412 ) { 1414 ) {
1413 bb_error_msg_and_die("modes may not be set when specifying an output style"); 1415 bb_error_msg_and_die("modes may not be set when -a or -g is used");
1414 } 1416 }
1415 1417
1416 /* Now it is safe to start doing things */ 1418 /* Now it is safe to start doing things */
diff --git a/coreutils/tail.c b/coreutils/tail.c
index 454c25936..b376ec863 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -62,6 +62,7 @@ struct globals {
62 bool exitcode; 62 bool exitcode;
63} FIX_ALIASING; 63} FIX_ALIASING;
64#define G (*(struct globals*)&bb_common_bufsiz1) 64#define G (*(struct globals*)&bb_common_bufsiz1)
65#define INIT_G() do { } while (0)
65 66
66static void tail_xprint_header(const char *fmt, const char *filename) 67static void tail_xprint_header(const char *fmt, const char *filename)
67{ 68{
@@ -120,6 +121,8 @@ int tail_main(int argc, char **argv)
120 int *fds; 121 int *fds;
121 const char *fmt; 122 const char *fmt;
122 123
124 INIT_G();
125
123#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_TAIL 126#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_TAIL
124 /* Allow legacy syntax of an initial numeric option without -n. */ 127 /* Allow legacy syntax of an initial numeric option without -n. */
125 if (argv[1] && (argv[1][0] == '+' || argv[1][0] == '-') 128 if (argv[1] && (argv[1][0] == '+' || argv[1][0] == '-')
@@ -203,7 +206,7 @@ int tail_main(int argc, char **argv)
203 int fd = fds[i]; 206 int fd = fds[i];
204 207
205 if (ENABLE_FEATURE_FANCY_TAIL && fd < 0) 208 if (ENABLE_FEATURE_FANCY_TAIL && fd < 0)
206 continue; /* may happen with -E */ 209 continue; /* may happen with -F */
207 210
208 if (nfiles > header_threshhold) { 211 if (nfiles > header_threshhold) {
209 tail_xprint_header(fmt, argv[i]); 212 tail_xprint_header(fmt, argv[i]);
@@ -252,14 +255,14 @@ int tail_main(int argc, char **argv)
252 * Used only by +N code ("start from Nth", 1-based): */ 255 * Used only by +N code ("start from Nth", 1-based): */
253 seen = 1; 256 seen = 1;
254 newlines_seen = 0; 257 newlines_seen = 0;
255 while ((nread = tail_read(fd, buf, tailbufsize-taillen)) > 0) { 258 while ((nread = tail_read(fd, buf, tailbufsize - taillen)) > 0) {
256 if (G.from_top) { 259 if (G.from_top) {
257 int nwrite = nread; 260 int nwrite = nread;
258 if (seen < count) { 261 if (seen < count) {
259 /* We need to skip a few more bytes/lines */ 262 /* We need to skip a few more bytes/lines */
260 if (COUNT_BYTES) { 263 if (COUNT_BYTES) {
261 nwrite -= (count - seen); 264 nwrite -= (count - seen);
262 seen = count; 265 seen += nread;
263 } else { 266 } else {
264 char *s = buf; 267 char *s = buf;
265 do { 268 do {
diff --git a/coreutils/uudecode.c b/coreutils/uudecode.c
index 6ecfe6cef..23ff711fa 100644
--- a/coreutils/uudecode.c
+++ b/coreutils/uudecode.c
@@ -125,10 +125,11 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv)
125 mode = bb_strtou(line_ptr, NULL, 8); 125 mode = bb_strtou(line_ptr, NULL, 8);
126 if (outname == NULL) { 126 if (outname == NULL) {
127 outname = strchr(line_ptr, ' '); 127 outname = strchr(line_ptr, ' ');
128 if ((outname == NULL) || (*outname == '\0')) { 128 if (!outname)
129 break; 129 break;
130 }
131 outname++; 130 outname++;
131 if (!outname[0])
132 break;
132 } 133 }
133 dst_stream = stdout; 134 dst_stream = stdout;
134 if (NOT_LONE_DASH(outname)) { 135 if (NOT_LONE_DASH(outname)) {