summaryrefslogtreecommitdiff
path: root/busybox/coreutils
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2005-07-18 23:51:27 +0000
committerEric Andersen <andersen@codepoet.org>2005-07-18 23:51:27 +0000
commit164a716f964bba247c660bc70149234f95146871 (patch)
tree95a8a6f75cb2ed1bb07cb6019088db7348ebf4d4 /busybox/coreutils
parent8c59a0bf0e9e2d87b0ff273ea3f0bf05bbbf6373 (diff)
downloadbusybox-w32-164a716f964bba247c660bc70149234f95146871.tar.gz
busybox-w32-164a716f964bba247c660bc70149234f95146871.tar.bz2
busybox-w32-164a716f964bba247c660bc70149234f95146871.zip
busybox-1.0.1-rc1.patch
http://busybox.net/lists/busybox/2005-July/014974.html
Diffstat (limited to 'busybox/coreutils')
-rw-r--r--busybox/coreutils/Config.in2
-rw-r--r--busybox/coreutils/cp.c8
-rw-r--r--busybox/coreutils/cut.c2
-rw-r--r--busybox/coreutils/date.c14
-rw-r--r--busybox/coreutils/expr.c37
-rw-r--r--busybox/coreutils/id.c2
-rw-r--r--busybox/coreutils/install.c2
-rw-r--r--busybox/coreutils/md5_sha1_sum.c47
-rw-r--r--busybox/coreutils/mv.c6
-rw-r--r--busybox/coreutils/test.c4
-rw-r--r--busybox/coreutils/watch.c12
-rw-r--r--busybox/coreutils/who.c2
12 files changed, 62 insertions, 76 deletions
diff --git a/busybox/coreutils/Config.in b/busybox/coreutils/Config.in
index e1f0516fd..5a521b536 100644
--- a/busybox/coreutils/Config.in
+++ b/busybox/coreutils/Config.in
@@ -545,7 +545,7 @@ config CONFIG_WC
545config CONFIG_WHO 545config CONFIG_WHO
546 bool "who" 546 bool "who"
547 default n 547 default n
548 select CONFIG_FEATURE_U_W_TMP 548 select CONFIG_FEATURE_UTMP
549 help 549 help
550 who is used to show who is logged on. 550 who is used to show who is logged on.
551 551
diff --git a/busybox/coreutils/cp.c b/busybox/coreutils/cp.c
index 6a82f6bff..97731e83f 100644
--- a/busybox/coreutils/cp.c
+++ b/busybox/coreutils/cp.c
@@ -42,7 +42,7 @@
42#include "libcoreutils/coreutils.h" 42#include "libcoreutils/coreutils.h"
43 43
44/* WARNING!! ORDER IS IMPORTANT!! */ 44/* WARNING!! ORDER IS IMPORTANT!! */
45static const char cp_opts[] = "pdRfiar"; 45static const char cp_opts[] = "pdRfiarP";
46 46
47extern int cp_main(int argc, char **argv) 47extern int cp_main(int argc, char **argv)
48{ 48{
@@ -73,6 +73,12 @@ extern int cp_main(int argc, char **argv)
73 */ 73 */
74 flags |= FILEUTILS_RECUR; 74 flags |= FILEUTILS_RECUR;
75 } 75 }
76 if (flags & 128) {
77 /* Make -P a synonym for -d,
78 * -d is the GNU option while -P is the POSIX 2003 option
79 */
80 flags |= FILEUTILS_DEREFERENCE;
81 }
76 82
77 flags ^= FILEUTILS_DEREFERENCE; /* The sense of this flag was reversed. */ 83 flags ^= FILEUTILS_DEREFERENCE; /* The sense of this flag was reversed. */
78 84
diff --git a/busybox/coreutils/cut.c b/busybox/coreutils/cut.c
index d26e80eee..e5fb5aff7 100644
--- a/busybox/coreutils/cut.c
+++ b/busybox/coreutils/cut.c
@@ -300,7 +300,7 @@ extern int cut_main(int argc, char **argv)
300 part = opt & (OPT_BYTE_FLGS|OPT_CHAR_FLGS|OPT_FIELDS_FLGS); 300 part = opt & (OPT_BYTE_FLGS|OPT_CHAR_FLGS|OPT_FIELDS_FLGS);
301 if(part == 0) 301 if(part == 0)
302 bb_error_msg_and_die("you must specify a list of bytes, characters, or fields"); 302 bb_error_msg_and_die("you must specify a list of bytes, characters, or fields");
303 if(opt & 0x80000000UL) 303 if(opt & BB_GETOPT_ERROR)
304 bb_error_msg_and_die("only one type of list may be specified"); 304 bb_error_msg_and_die("only one type of list may be specified");
305 parse_lists(sopt); 305 parse_lists(sopt);
306 if((opt & (OPT_DELIM_FLGS))) { 306 if((opt & (OPT_DELIM_FLGS))) {
diff --git a/busybox/coreutils/date.c b/busybox/coreutils/date.c
index 3608df69f..70484e2cd 100644
--- a/busybox/coreutils/date.c
+++ b/busybox/coreutils/date.c
@@ -136,7 +136,6 @@ int date_main(int argc, char **argv)
136{ 136{
137 char *date_str = NULL; 137 char *date_str = NULL;
138 char *date_fmt = NULL; 138 char *date_fmt = NULL;
139 char *t_buff;
140 int set_time; 139 int set_time;
141 int utc; 140 int utc;
142 int use_arg = 0; 141 int use_arg = 0;
@@ -166,7 +165,7 @@ int date_main(int argc, char **argv)
166 bb_error_msg_and_die(bb_msg_memory_exhausted); 165 bb_error_msg_and_die(bb_msg_memory_exhausted);
167 } 166 }
168 use_arg = opt & DATE_OPT_DATE; 167 use_arg = opt & DATE_OPT_DATE;
169 if(opt & 0x80000000UL) 168 if(opt & BB_GETOPT_ERROR)
170 bb_show_usage(); 169 bb_show_usage();
171#ifdef CONFIG_FEATURE_DATE_ISOFMT 170#ifdef CONFIG_FEATURE_DATE_ISOFMT
172 if(opt & DATE_OPT_TIMESPEC) { 171 if(opt & DATE_OPT_TIMESPEC) {
@@ -283,10 +282,13 @@ int date_main(int argc, char **argv)
283 date_fmt = "%Y.%m.%d-%H:%M:%S"; 282 date_fmt = "%Y.%m.%d-%H:%M:%S";
284 } 283 }
285 284
286 /* Print OUTPUT (after ALL that!) */ 285 {
287 t_buff = xmalloc(201); 286 /* Print OUTPUT (after ALL that!) */
288 strftime(t_buff, 200, date_fmt, &tm_time); 287 RESERVE_CONFIG_BUFFER(t_buff, 201);
289 puts(t_buff); 288 strftime(t_buff, 200, date_fmt, &tm_time);
289 puts(t_buff);
290 RELEASE_CONFIG_BUFFER(t_buff);
291 }
290 292
291 return EXIT_SUCCESS; 293 return EXIT_SUCCESS;
292} 294}
diff --git a/busybox/coreutils/expr.c b/busybox/coreutils/expr.c
index cbbd4cd03..3f052d92a 100644
--- a/busybox/coreutils/expr.c
+++ b/busybox/coreutils/expr.c
@@ -245,10 +245,9 @@ static int arithmetic_common (VALUE *l, VALUE *r, int op)
245static VALUE *docolon (VALUE *sv, VALUE *pv) 245static VALUE *docolon (VALUE *sv, VALUE *pv)
246{ 246{
247 VALUE *v; 247 VALUE *v;
248 const char *errmsg; 248 regex_t re_buffer;
249 struct re_pattern_buffer re_buffer; 249 const int NMATCH = 2;
250 struct re_registers re_regs; 250 regmatch_t re_regs[NMATCH];
251 int len;
252 251
253 tostring (sv); 252 tostring (sv);
254 tostring (pv); 253 tostring (pv);
@@ -260,27 +259,22 @@ of a basic regular expression is not portable; it is being ignored",
260 pv->u.s); 259 pv->u.s);
261 } 260 }
262 261
263 len = strlen (pv->u.s);
264 memset (&re_buffer, 0, sizeof (re_buffer)); 262 memset (&re_buffer, 0, sizeof (re_buffer));
265 memset (&re_regs, 0, sizeof (re_regs)); 263 memset (re_regs, 0, sizeof (*re_regs));
266 re_buffer.allocated = 2 * len; 264 if( regcomp (&re_buffer, pv->u.s, 0) != 0 )
267 re_buffer.buffer = (unsigned char *) xmalloc (re_buffer.allocated); 265 bb_error_msg_and_die("Invalid regular expression");
268 re_buffer.translate = 0; 266
269 re_syntax_options = RE_SYNTAX_POSIX_BASIC; 267 /* expr uses an anchored pattern match, so check that there was a
270 errmsg = re_compile_pattern (pv->u.s, len, &re_buffer); 268 * match and that the match starts at offset 0. */
271 if (errmsg) { 269 if (regexec (&re_buffer, sv->u.s, NMATCH, re_regs, 0) != REG_NOMATCH &&
272 bb_error_msg_and_die("%s", errmsg); 270 re_regs[0].rm_so == 0) {
273 }
274
275 len = re_match (&re_buffer, sv->u.s, strlen (sv->u.s), 0, &re_regs);
276 if (len >= 0) {
277 /* Were \(...\) used? */ 271 /* Were \(...\) used? */
278 if (re_buffer.re_nsub > 0) { /* was (re_regs.start[1] >= 0) */ 272 if (re_buffer.re_nsub > 0) {
279 sv->u.s[re_regs.end[1]] = '\0'; 273 sv->u.s[re_regs[1].rm_eo] = '\0';
280 v = str_value (sv->u.s + re_regs.start[1]); 274 v = str_value (sv->u.s + re_regs[1].rm_so);
281 } 275 }
282 else 276 else
283 v = int_value (len); 277 v = int_value (re_regs[0].rm_eo);
284 } 278 }
285 else { 279 else {
286 /* Match failed -- return the right kind of null. */ 280 /* Match failed -- return the right kind of null. */
@@ -289,7 +283,6 @@ of a basic regular expression is not portable; it is being ignored",
289 else 283 else
290 v = int_value (0); 284 v = int_value (0);
291 } 285 }
292 free (re_buffer.buffer);
293 return v; 286 return v;
294} 287}
295 288
diff --git a/busybox/coreutils/id.c b/busybox/coreutils/id.c
index d5182b953..b10a7c1bf 100644
--- a/busybox/coreutils/id.c
+++ b/busybox/coreutils/id.c
@@ -68,7 +68,7 @@ extern int id_main(int argc, char **argv)
68 bb_opt_complementaly = "u~g:g~u"; 68 bb_opt_complementaly = "u~g:g~u";
69 flags = bb_getopt_ulflags(argc, argv, "rnug"); 69 flags = bb_getopt_ulflags(argc, argv, "rnug");
70 70
71 if ((flags & 0x80000000UL) 71 if ((flags & BB_GETOPT_ERROR)
72 /* Don't allow -n -r -nr */ 72 /* Don't allow -n -r -nr */
73 || (flags <= 3 && flags > 0) 73 || (flags <= 3 && flags > 0)
74 /* Don't allow more than one username */ 74 /* Don't allow more than one username */
diff --git a/busybox/coreutils/install.c b/busybox/coreutils/install.c
index 36dc1d618..345e75af0 100644
--- a/busybox/coreutils/install.c
+++ b/busybox/coreutils/install.c
@@ -69,7 +69,7 @@ extern int install_main(int argc, char **argv)
69 flags = bb_getopt_ulflags(argc, argv, "cdpsg:m:o:", &gid_str, &mode_str, &uid_str); /* 'a' must be 2nd */ 69 flags = bb_getopt_ulflags(argc, argv, "cdpsg:m:o:", &gid_str, &mode_str, &uid_str); /* 'a' must be 2nd */
70 70
71 /* Check valid options were given */ 71 /* Check valid options were given */
72 if(flags & 0x80000000UL) { 72 if(flags & BB_GETOPT_ERROR) {
73 bb_show_usage(); 73 bb_show_usage();
74 } 74 }
75 75
diff --git a/busybox/coreutils/md5_sha1_sum.c b/busybox/coreutils/md5_sha1_sum.c
index bd1c9fc29..543c2ab3f 100644
--- a/busybox/coreutils/md5_sha1_sum.c
+++ b/busybox/coreutils/md5_sha1_sum.c
@@ -42,41 +42,28 @@ static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
42 max = (hash_length * 2) + 2; 42 max = (hash_length * 2) + 2;
43 hex_value = xmalloc(max); 43 hex_value = xmalloc(max);
44 for (x = len = 0; x < hash_length; x++) { 44 for (x = len = 0; x < hash_length; x++) {
45 len += snprintf(hex_value + len, max - len, "%02x", hash_value[x]); 45 len += snprintf((char*)(hex_value + len), max - len, "%02x", hash_value[x]);
46 } 46 }
47 return (hex_value); 47 return (hex_value);
48} 48}
49 49
50static uint8_t *hash_file(const char *filename, uint8_t hash_algo) 50static uint8_t *hash_file(const char *filename, uint8_t hash_algo)
51{ 51{
52 uint8_t *hash_value_bin; 52 int src_fd = strcmp(filename, "-") == 0 ? STDIN_FILENO :
53 uint8_t *hash_value = NULL; 53 open(filename, O_RDONLY);
54 uint8_t hash_length; 54 if (src_fd == -1) {
55 int src_fd;
56
57 if (strcmp(filename, "-") == 0) {
58 src_fd = STDIN_FILENO;
59 } else {
60 src_fd = open(filename, O_RDONLY);
61 }
62
63 if (hash_algo == HASH_MD5) {
64 hash_length = 16;
65 } else {
66 hash_length = 20;
67 }
68
69 hash_value_bin = xmalloc(hash_length);
70
71 if ((src_fd != -1) && (hash_fd(src_fd, -1, hash_algo, hash_value_bin) != -2)) {
72 hash_value = hash_bin_to_hex(hash_value_bin, hash_length);
73 } else {
74 bb_perror_msg("%s", filename); 55 bb_perror_msg("%s", filename);
56 return NULL;
57 } else {
58 uint8_t *hash_value;
59 RESERVE_CONFIG_UBUFFER(hash_value_bin, 20);
60 hash_value = hash_fd(src_fd, -1, hash_algo, hash_value_bin) != -2 ?
61 hash_bin_to_hex(hash_value_bin, hash_algo == HASH_MD5 ? 16 : 20) :
62 NULL;
63 RELEASE_CONFIG_BUFFER(hash_value_bin);
64 close(src_fd);
65 return hash_value;
75 } 66 }
76
77 close(src_fd);
78
79 return(hash_value);
80} 67}
81 68
82/* This could become a common function for md5 as well, by using md5_stream */ 69/* This could become a common function for md5 as well, by using md5_stream */
@@ -111,7 +98,7 @@ extern int hash_files(int argc, char **argv, const uint8_t hash_algo)
111 FILE *pre_computed_stream; 98 FILE *pre_computed_stream;
112 int count_total = 0; 99 int count_total = 0;
113 int count_failed = 0; 100 int count_failed = 0;
114 unsigned char *file_ptr = argv[optind]; 101 char *file_ptr = argv[optind];
115 char *line; 102 char *line;
116 103
117 if (optind + 1 != argc) { 104 if (optind + 1 != argc) {
@@ -142,7 +129,7 @@ extern int hash_files(int argc, char **argv, const uint8_t hash_algo)
142 129
143 hash_value = hash_file(filename_ptr, hash_algo); 130 hash_value = hash_file(filename_ptr, hash_algo);
144 131
145 if (hash_value && (strcmp(hash_value, line) == 0)) { 132 if (hash_value && (strcmp((char*)hash_value, line) == 0)) {
146 if (!(flags & FLAG_SILENT)) 133 if (!(flags & FLAG_SILENT))
147 printf("%s: OK\n", filename_ptr); 134 printf("%s: OK\n", filename_ptr);
148 } else { 135 } else {
@@ -175,7 +162,7 @@ extern int hash_files(int argc, char **argv, const uint8_t hash_algo)
175 hash_value = xmalloc(hash_length); 162 hash_value = xmalloc(hash_length);
176 163
177 while (optind < argc) { 164 while (optind < argc) {
178 unsigned char *file_ptr = argv[optind++]; 165 char *file_ptr = argv[optind++];
179 166
180 hash_value = hash_file(file_ptr, hash_algo); 167 hash_value = hash_file(file_ptr, hash_algo);
181 if (hash_value == NULL) { 168 if (hash_value == NULL) {
diff --git a/busybox/coreutils/mv.c b/busybox/coreutils/mv.c
index 4f08dedc0..e1c4529ad 100644
--- a/busybox/coreutils/mv.c
+++ b/busybox/coreutils/mv.c
@@ -99,10 +99,10 @@ DO_MOVE:
99 struct stat source_stat; 99 struct stat source_stat;
100 int source_exists; 100 int source_exists;
101 101
102 if (errno != EXDEV) { 102 if (errno != EXDEV ||
103 (source_exists = cp_mv_stat(*argv, &source_stat)) < 1) {
103 bb_perror_msg("unable to rename `%s'", *argv); 104 bb_perror_msg("unable to rename `%s'", *argv);
104 } 105 } else {
105 else if ((source_exists = cp_mv_stat(*argv, &source_stat)) >= 0) {
106 if (dest_exists) { 106 if (dest_exists) {
107 if (dest_exists == 3) { 107 if (dest_exists == 3) {
108 if (source_exists != 3) { 108 if (source_exists != 3) {
diff --git a/busybox/coreutils/test.c b/busybox/coreutils/test.c
index 8fa6d166f..5195fafa1 100644
--- a/busybox/coreutils/test.c
+++ b/busybox/coreutils/test.c
@@ -304,7 +304,7 @@ static arith_t primary(enum token n)
304 return strlen(*t_wp) > 0; 304 return strlen(*t_wp) > 0;
305} 305}
306 306
307static int binop() 307static int binop(void)
308{ 308{
309 const char *opnd1, *opnd2; 309 const char *opnd1, *opnd2;
310 struct t_op const *op; 310 struct t_op const *op;
@@ -531,7 +531,7 @@ static int test_eaccess(char *path, int mode)
531 return (-1); 531 return (-1);
532} 532}
533 533
534static void initialize_group_array() 534static void initialize_group_array(void)
535{ 535{
536 ngroups = getgroups(0, NULL); 536 ngroups = getgroups(0, NULL);
537 group_array = xrealloc(group_array, ngroups * sizeof(gid_t)); 537 group_array = xrealloc(group_array, ngroups * sizeof(gid_t));
diff --git a/busybox/coreutils/watch.c b/busybox/coreutils/watch.c
index f9f40189e..31fadfb85 100644
--- a/busybox/coreutils/watch.c
+++ b/busybox/coreutils/watch.c
@@ -82,7 +82,7 @@ extern int watch_main(int argc, char **argv)
82 header[len] = 0; 82 header[len] = 0;
83 83
84 /* thanks to lye, who showed me how to redirect stdin/stdout */ 84 /* thanks to lye, who showed me how to redirect stdin/stdout */
85 old_stdout = dup(1); 85 old_stdout = dup(STDOUT_FILENO);
86 86
87 while (1) { 87 while (1) {
88 time(&t); 88 time(&t);
@@ -98,13 +98,11 @@ extern int watch_main(int argc, char **argv)
98 sleep(period); 98 sleep(period);
99 } else if (0 == pid) { 99 } else if (0 == pid) {
100 //child 100 //child
101 close(1); 101 dup2(old_stdout, STDOUT_FILENO);
102 dup(old_stdout); 102 execvp(*watched_argv, watched_argv);
103 if (execvp(*watched_argv, watched_argv)) { 103 bb_perror_msg_and_die(*watched_argv);
104 bb_error_msg_and_die("Couldn't run command\n");
105 }
106 } else { 104 } else {
107 bb_error_msg_and_die("Couldn't vfork\n"); 105 bb_perror_msg_and_die("vfork");
108 } 106 }
109 } 107 }
110} 108}
diff --git a/busybox/coreutils/who.c b/busybox/coreutils/who.c
index 9561db132..0531326bd 100644
--- a/busybox/coreutils/who.c
+++ b/busybox/coreutils/who.c
@@ -74,7 +74,7 @@ extern int who_main(int argc, char **argv)
74 } else 74 } else
75 printf("%-8s ", "?"); 75 printf("%-8s ", "?");
76 76
77 printf("%-12.12s %s\n", ctime(&(ut->ut_tv.tv_sec)) + 4, ut->ut_host); 77 printf("%-12.12s %s\n", ctime((time_t*)&(ut->ut_tv.tv_sec)) + 4, ut->ut_host);
78 } 78 }
79 } 79 }
80 endutent(); 80 endutent();