summaryrefslogtreecommitdiff
path: root/busybox/coreutils
diff options
context:
space:
mode:
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 e1f0516..5a521b5 100644
--- a/busybox/coreutils/Config.in
+++ b/busybox/coreutils/Config.in
@@ -545,7 +545,7 @@ config CONFIG_WC
config CONFIG_WHO
bool "who"
default n
- select CONFIG_FEATURE_U_W_TMP
+ select CONFIG_FEATURE_UTMP
help
who is used to show who is logged on.
diff --git a/busybox/coreutils/cp.c b/busybox/coreutils/cp.c
index 6a82f6b..97731e8 100644
--- a/busybox/coreutils/cp.c
+++ b/busybox/coreutils/cp.c
@@ -42,7 +42,7 @@
#include "libcoreutils/coreutils.h"
/* WARNING!! ORDER IS IMPORTANT!! */
-static const char cp_opts[] = "pdRfiar";
+static const char cp_opts[] = "pdRfiarP";
extern int cp_main(int argc, char **argv)
{
@@ -73,6 +73,12 @@ extern int cp_main(int argc, char **argv)
*/
flags |= FILEUTILS_RECUR;
}
+ if (flags & 128) {
+ /* Make -P a synonym for -d,
+ * -d is the GNU option while -P is the POSIX 2003 option
+ */
+ flags |= FILEUTILS_DEREFERENCE;
+ }
flags ^= FILEUTILS_DEREFERENCE; /* The sense of this flag was reversed. */
diff --git a/busybox/coreutils/cut.c b/busybox/coreutils/cut.c
index d26e80e..e5fb5af 100644
--- a/busybox/coreutils/cut.c
+++ b/busybox/coreutils/cut.c
@@ -300,7 +300,7 @@ extern int cut_main(int argc, char **argv)
part = opt & (OPT_BYTE_FLGS|OPT_CHAR_FLGS|OPT_FIELDS_FLGS);
if(part == 0)
bb_error_msg_and_die("you must specify a list of bytes, characters, or fields");
- if(opt & 0x80000000UL)
+ if(opt & BB_GETOPT_ERROR)
bb_error_msg_and_die("only one type of list may be specified");
parse_lists(sopt);
if((opt & (OPT_DELIM_FLGS))) {
diff --git a/busybox/coreutils/date.c b/busybox/coreutils/date.c
index 3608df6..70484e2 100644
--- a/busybox/coreutils/date.c
+++ b/busybox/coreutils/date.c
@@ -136,7 +136,6 @@ int date_main(int argc, char **argv)
{
char *date_str = NULL;
char *date_fmt = NULL;
- char *t_buff;
int set_time;
int utc;
int use_arg = 0;
@@ -166,7 +165,7 @@ int date_main(int argc, char **argv)
bb_error_msg_and_die(bb_msg_memory_exhausted);
}
use_arg = opt & DATE_OPT_DATE;
- if(opt & 0x80000000UL)
+ if(opt & BB_GETOPT_ERROR)
bb_show_usage();
#ifdef CONFIG_FEATURE_DATE_ISOFMT
if(opt & DATE_OPT_TIMESPEC) {
@@ -283,10 +282,13 @@ int date_main(int argc, char **argv)
date_fmt = "%Y.%m.%d-%H:%M:%S";
}
- /* Print OUTPUT (after ALL that!) */
- t_buff = xmalloc(201);
- strftime(t_buff, 200, date_fmt, &tm_time);
- puts(t_buff);
+ {
+ /* Print OUTPUT (after ALL that!) */
+ RESERVE_CONFIG_BUFFER(t_buff, 201);
+ strftime(t_buff, 200, date_fmt, &tm_time);
+ puts(t_buff);
+ RELEASE_CONFIG_BUFFER(t_buff);
+ }
return EXIT_SUCCESS;
}
diff --git a/busybox/coreutils/expr.c b/busybox/coreutils/expr.c
index cbbd4cd..3f052d9 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)
static VALUE *docolon (VALUE *sv, VALUE *pv)
{
VALUE *v;
- const char *errmsg;
- struct re_pattern_buffer re_buffer;
- struct re_registers re_regs;
- int len;
+ regex_t re_buffer;
+ const int NMATCH = 2;
+ regmatch_t re_regs[NMATCH];
tostring (sv);
tostring (pv);
@@ -260,27 +259,22 @@ of a basic regular expression is not portable; it is being ignored",
pv->u.s);
}
- len = strlen (pv->u.s);
memset (&re_buffer, 0, sizeof (re_buffer));
- memset (&re_regs, 0, sizeof (re_regs));
- re_buffer.allocated = 2 * len;
- re_buffer.buffer = (unsigned char *) xmalloc (re_buffer.allocated);
- re_buffer.translate = 0;
- re_syntax_options = RE_SYNTAX_POSIX_BASIC;
- errmsg = re_compile_pattern (pv->u.s, len, &re_buffer);
- if (errmsg) {
- bb_error_msg_and_die("%s", errmsg);
- }
-
- len = re_match (&re_buffer, sv->u.s, strlen (sv->u.s), 0, &re_regs);
- if (len >= 0) {
+ memset (re_regs, 0, sizeof (*re_regs));
+ if( regcomp (&re_buffer, pv->u.s, 0) != 0 )
+ bb_error_msg_and_die("Invalid regular expression");
+
+ /* expr uses an anchored pattern match, so check that there was a
+ * match and that the match starts at offset 0. */
+ if (regexec (&re_buffer, sv->u.s, NMATCH, re_regs, 0) != REG_NOMATCH &&
+ re_regs[0].rm_so == 0) {
/* Were \(...\) used? */
- if (re_buffer.re_nsub > 0) { /* was (re_regs.start[1] >= 0) */
- sv->u.s[re_regs.end[1]] = '\0';
- v = str_value (sv->u.s + re_regs.start[1]);
+ if (re_buffer.re_nsub > 0) {
+ sv->u.s[re_regs[1].rm_eo] = '\0';
+ v = str_value (sv->u.s + re_regs[1].rm_so);
}
else
- v = int_value (len);
+ v = int_value (re_regs[0].rm_eo);
}
else {
/* Match failed -- return the right kind of null. */
@@ -289,7 +283,6 @@ of a basic regular expression is not portable; it is being ignored",
else
v = int_value (0);
}
- free (re_buffer.buffer);
return v;
}
diff --git a/busybox/coreutils/id.c b/busybox/coreutils/id.c
index d5182b9..b10a7c1 100644
--- a/busybox/coreutils/id.c
+++ b/busybox/coreutils/id.c
@@ -68,7 +68,7 @@ extern int id_main(int argc, char **argv)
bb_opt_complementaly = "u~g:g~u";
flags = bb_getopt_ulflags(argc, argv, "rnug");
- if ((flags & 0x80000000UL)
+ if ((flags & BB_GETOPT_ERROR)
/* Don't allow -n -r -nr */
|| (flags <= 3 && flags > 0)
/* Don't allow more than one username */
diff --git a/busybox/coreutils/install.c b/busybox/coreutils/install.c
index 36dc1d6..345e75a 100644
--- a/busybox/coreutils/install.c
+++ b/busybox/coreutils/install.c
@@ -69,7 +69,7 @@ extern int install_main(int argc, char **argv)
flags = bb_getopt_ulflags(argc, argv, "cdpsg:m:o:", &gid_str, &mode_str, &uid_str); /* 'a' must be 2nd */
/* Check valid options were given */
- if(flags & 0x80000000UL) {
+ if(flags & BB_GETOPT_ERROR) {
bb_show_usage();
}
diff --git a/busybox/coreutils/md5_sha1_sum.c b/busybox/coreutils/md5_sha1_sum.c
index bd1c9fc..543c2ab 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,
max = (hash_length * 2) + 2;
hex_value = xmalloc(max);
for (x = len = 0; x < hash_length; x++) {
- len += snprintf(hex_value + len, max - len, "%02x", hash_value[x]);
+ len += snprintf((char*)(hex_value + len), max - len, "%02x", hash_value[x]);
}
return (hex_value);
}
static uint8_t *hash_file(const char *filename, uint8_t hash_algo)
{
- uint8_t *hash_value_bin;
- uint8_t *hash_value = NULL;
- uint8_t hash_length;
- int src_fd;
-
- if (strcmp(filename, "-") == 0) {
- src_fd = STDIN_FILENO;
- } else {
- src_fd = open(filename, O_RDONLY);
- }
-
- if (hash_algo == HASH_MD5) {
- hash_length = 16;
- } else {
- hash_length = 20;
- }
-
- hash_value_bin = xmalloc(hash_length);
-
- if ((src_fd != -1) && (hash_fd(src_fd, -1, hash_algo, hash_value_bin) != -2)) {
- hash_value = hash_bin_to_hex(hash_value_bin, hash_length);
- } else {
+ int src_fd = strcmp(filename, "-") == 0 ? STDIN_FILENO :
+ open(filename, O_RDONLY);
+ if (src_fd == -1) {
bb_perror_msg("%s", filename);
+ return NULL;
+ } else {
+ uint8_t *hash_value;
+ RESERVE_CONFIG_UBUFFER(hash_value_bin, 20);
+ hash_value = hash_fd(src_fd, -1, hash_algo, hash_value_bin) != -2 ?
+ hash_bin_to_hex(hash_value_bin, hash_algo == HASH_MD5 ? 16 : 20) :
+ NULL;
+ RELEASE_CONFIG_BUFFER(hash_value_bin);
+ close(src_fd);
+ return hash_value;
}
-
- close(src_fd);
-
- return(hash_value);
}
/* 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)
FILE *pre_computed_stream;
int count_total = 0;
int count_failed = 0;
- unsigned char *file_ptr = argv[optind];
+ char *file_ptr = argv[optind];
char *line;
if (optind + 1 != argc) {
@@ -142,7 +129,7 @@ extern int hash_files(int argc, char **argv, const uint8_t hash_algo)
hash_value = hash_file(filename_ptr, hash_algo);
- if (hash_value && (strcmp(hash_value, line) == 0)) {
+ if (hash_value && (strcmp((char*)hash_value, line) == 0)) {
if (!(flags & FLAG_SILENT))
printf("%s: OK\n", filename_ptr);
} else {
@@ -175,7 +162,7 @@ extern int hash_files(int argc, char **argv, const uint8_t hash_algo)
hash_value = xmalloc(hash_length);
while (optind < argc) {
- unsigned char *file_ptr = argv[optind++];
+ char *file_ptr = argv[optind++];
hash_value = hash_file(file_ptr, hash_algo);
if (hash_value == NULL) {
diff --git a/busybox/coreutils/mv.c b/busybox/coreutils/mv.c
index 4f08ded..e1c4529 100644
--- a/busybox/coreutils/mv.c
+++ b/busybox/coreutils/mv.c
@@ -99,10 +99,10 @@ DO_MOVE:
struct stat source_stat;
int source_exists;
- if (errno != EXDEV) {
+ if (errno != EXDEV ||
+ (source_exists = cp_mv_stat(*argv, &source_stat)) < 1) {
bb_perror_msg("unable to rename `%s'", *argv);
- }
- else if ((source_exists = cp_mv_stat(*argv, &source_stat)) >= 0) {
+ } else {
if (dest_exists) {
if (dest_exists == 3) {
if (source_exists != 3) {
diff --git a/busybox/coreutils/test.c b/busybox/coreutils/test.c
index 8fa6d16..5195faf 100644
--- a/busybox/coreutils/test.c
+++ b/busybox/coreutils/test.c
@@ -304,7 +304,7 @@ static arith_t primary(enum token n)
return strlen(*t_wp) > 0;
}
-static int binop()
+static int binop(void)
{
const char *opnd1, *opnd2;
struct t_op const *op;
@@ -531,7 +531,7 @@ static int test_eaccess(char *path, int mode)
return (-1);
}
-static void initialize_group_array()
+static void initialize_group_array(void)
{
ngroups = getgroups(0, NULL);
group_array = xrealloc(group_array, ngroups * sizeof(gid_t));
diff --git a/busybox/coreutils/watch.c b/busybox/coreutils/watch.c
index f9f4018..31fadfb 100644
--- a/busybox/coreutils/watch.c
+++ b/busybox/coreutils/watch.c
@@ -82,7 +82,7 @@ extern int watch_main(int argc, char **argv)
header[len] = 0;
/* thanks to lye, who showed me how to redirect stdin/stdout */
- old_stdout = dup(1);
+ old_stdout = dup(STDOUT_FILENO);
while (1) {
time(&t);
@@ -98,13 +98,11 @@ extern int watch_main(int argc, char **argv)
sleep(period);
} else if (0 == pid) {
//child
- close(1);
- dup(old_stdout);
- if (execvp(*watched_argv, watched_argv)) {
- bb_error_msg_and_die("Couldn't run command\n");
- }
+ dup2(old_stdout, STDOUT_FILENO);
+ execvp(*watched_argv, watched_argv);
+ bb_perror_msg_and_die(*watched_argv);
} else {
- bb_error_msg_and_die("Couldn't vfork\n");
+ bb_perror_msg_and_die("vfork");
}
}
}
diff --git a/busybox/coreutils/who.c b/busybox/coreutils/who.c
index 9561db1..0531326 100644
--- a/busybox/coreutils/who.c
+++ b/busybox/coreutils/who.c
@@ -74,7 +74,7 @@ extern int who_main(int argc, char **argv)
} else
printf("%-8s ", "?");
- printf("%-12.12s %s\n", ctime(&(ut->ut_tv.tv_sec)) + 4, ut->ut_host);
+ printf("%-12.12s %s\n", ctime((time_t*)&(ut->ut_tv.tv_sec)) + 4, ut->ut_host);
}
}
endutent();