summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/cal.c4
-rw-r--r--coreutils/cut.c16
-rw-r--r--coreutils/dd.c12
-rw-r--r--coreutils/diff.c2
-rw-r--r--coreutils/du.c2
-rw-r--r--coreutils/fold.c2
-rw-r--r--coreutils/head.c36
-rw-r--r--coreutils/ls.c8
-rw-r--r--coreutils/mknod.c9
-rw-r--r--coreutils/nice.c2
-rw-r--r--coreutils/printf.c40
-rw-r--r--coreutils/sleep.c12
-rw-r--r--coreutils/stty.c36
-rw-r--r--coreutils/tail.c4
-rw-r--r--coreutils/uniq.c2
-rw-r--r--coreutils/usleep.c2
-rw-r--r--coreutils/watch.c2
17 files changed, 83 insertions, 108 deletions
diff --git a/coreutils/cal.c b/coreutils/cal.c
index ef91412..e2bc5ab 100644
--- a/coreutils/cal.c
+++ b/coreutils/cal.c
@@ -112,9 +112,9 @@ int cal_main(int argc, char **argv)
}
} else {
if (argc == 2) {
- month = bb_xgetularg10_bnd(*argv++, 1, 12);
+ month = xatoul_range(*argv++, 1, 12);
}
- year = bb_xgetularg10_bnd(*argv, 1, 9999);
+ year = xatoul_range(*argv, 1, 9999);
}
blank_string(day_headings, sizeof(day_headings) - 7 + 7*julian);
diff --git a/coreutils/cut.c b/coreutils/cut.c
index 69f28fa..7ba947f 100644
--- a/coreutils/cut.c
+++ b/coreutils/cut.c
@@ -163,17 +163,7 @@ static void cut_file(FILE * file)
}
}
-static int getval(char *ntok)
-{
- char *junk;
- int i = strtoul(ntok, &junk, 10);
-
- if (*junk != '\0' || i < 0)
- bb_error_msg_and_die("invalid byte or field list");
- return i;
-}
-
-static const char * const _op_on_field = " only when operating on fields";
+static const char _op_on_field[] = " only when operating on fields";
int cut_main(int argc, char **argv)
{
@@ -231,7 +221,7 @@ int cut_main(int argc, char **argv)
} else if (strlen(ntok) == 0) {
s = BOL;
} else {
- s = getval(ntok);
+ s = xatoi_u(ntok);
/* account for the fact that arrays are zero based, while
* the user expects the first char on the line to be char #1 */
if (s != 0)
@@ -245,7 +235,7 @@ int cut_main(int argc, char **argv)
} else if (strlen(ntok) == 0) {
e = EOL;
} else {
- e = getval(ntok);
+ e = xatoi_u(ntok);
/* if the user specified and end position of 0, that means "til the
* end of the line */
if (e == 0)
diff --git a/coreutils/dd.c b/coreutils/dd.c
index e63244d..d557ae4 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -62,19 +62,19 @@ int dd_main(int argc, char **argv)
for (n = 1; n < argc; n++) {
// FIXME: make them capable of eating LARGE numbers
if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("ibs=", argv[n], 4)) {
- ibs = bb_xparse_number(argv[n]+4, dd_suffixes);
+ ibs = xatoul_sfx(argv[n]+4, dd_suffixes);
flags |= twobufs_flag;
} else if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("obs=", argv[n], 4)) {
- obs = bb_xparse_number(argv[n]+4, dd_suffixes);
+ obs = xatoul_sfx(argv[n]+4, dd_suffixes);
flags |= twobufs_flag;
} else if (!strncmp("bs=", argv[n], 3))
- ibs = obs = bb_xparse_number(argv[n]+3, dd_suffixes);
+ ibs = obs = xatoul_sfx(argv[n]+3, dd_suffixes);
else if (!strncmp("count=", argv[n], 6))
- count = bb_xparse_number(argv[n]+6, dd_suffixes);
+ count = xatoul_sfx(argv[n]+6, dd_suffixes);
else if (!strncmp("seek=", argv[n], 5))
- seek = bb_xparse_number(argv[n]+5, dd_suffixes);
+ seek = xatoul_sfx(argv[n]+5, dd_suffixes);
else if (!strncmp("skip=", argv[n], 5))
- skip = bb_xparse_number(argv[n]+5, dd_suffixes);
+ skip = xatoul_sfx(argv[n]+5, dd_suffixes);
else if (!strncmp("if=", argv[n], 3))
infile = argv[n]+3;
else if (!strncmp("of=", argv[n], 3))
diff --git a/coreutils/diff.c b/coreutils/diff.c
index b30aad5..65757d7 100644
--- a/coreutils/diff.c
+++ b/coreutils/diff.c
@@ -1192,7 +1192,7 @@ int diff_main(int argc, char **argv)
context = 3; /* This is the default number of lines of context. */
if (cmd_flags & FLAG_U) {
- context = bb_xgetlarg(U_opt, 10, 1, INT_MAX);
+ context = xatoul_range(U_opt, 1, INT_MAX);
}
argc -= optind;
argv += optind;
diff --git a/coreutils/du.c b/coreutils/du.c
index 1452e58..f61d978 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -215,7 +215,7 @@ int du_main(int argc, char **argv)
one_file_system = opt & (1 << 5); /* -x opt */
if((opt & (1 << 6))) {
/* -d opt */
- max_print_depth = bb_xgetularg10_bnd(smax_print_depth, 0, INT_MAX);
+ max_print_depth = xatoi_u(smax_print_depth);
}
if((opt & (1 << 7))) {
/* -l opt */
diff --git a/coreutils/fold.c b/coreutils/fold.c
index 3b5be64..45f4472 100644
--- a/coreutils/fold.c
+++ b/coreutils/fold.c
@@ -62,7 +62,7 @@ int fold_main(int argc, char **argv)
flags = getopt32(argc, argv, "bsw:", &w_opt);
if (flags & FLAG_WIDTH)
- width = bb_xgetlarg(w_opt, 10, 1, 10000);
+ width = xatoul_range(w_opt, 1, 10000);
argv += optind;
if (!*argv) {
diff --git a/coreutils/head.c b/coreutils/head.c
index 7d5f219..060febc 100644
--- a/coreutils/head.c
+++ b/coreutils/head.c
@@ -64,32 +64,30 @@ int head_main(int argc, char **argv)
while ((opt = getopt(argc, argv, head_opts)) > 0) {
switch (opt) {
#if ENABLE_FEATURE_FANCY_HEAD
- case 'q':
- header_threshhold = INT_MAX;
- break;
- case 'v':
- header_threshhold = -1;
- break;
- case 'c':
- count_bytes = 1;
- /* fall through */
+ case 'q':
+ header_threshhold = INT_MAX;
+ break;
+ case 'v':
+ header_threshhold = -1;
+ break;
+ case 'c':
+ count_bytes = 1;
+ /* fall through */
#endif
- case 'n':
- p = optarg;
+ case 'n':
+ p = optarg;
#if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
- GET_COUNT:
+ GET_COUNT:
#endif
#if !ENABLE_FEATURE_FANCY_HEAD
- count = bb_xgetularg10(p);
+ count = xatoul(p);
#else
- count = bb_xgetularg_bnd_sfx(p, 10,
- 0, ULONG_MAX,
- head_suffixes);
+ count = xatoul_sfx(p, head_suffixes);
#endif
- break;
- default:
- bb_show_usage();
+ break;
+ default:
+ bb_show_usage();
}
}
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 8ba4ab7..f34e83e 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -163,8 +163,8 @@ static int list_single(struct dnode *);
static unsigned int all_fmt;
#ifdef CONFIG_FEATURE_AUTOWIDTH
-static int terminal_width = TERMINAL_WIDTH;
-static unsigned short tabstops = COLUMN_GAP;
+static unsigned terminal_width = TERMINAL_WIDTH;
+static unsigned tabstops = COLUMN_GAP;
#else
#define tabstops COLUMN_GAP
#define terminal_width TERMINAL_WIDTH
@@ -915,10 +915,10 @@ int ls_main(int argc, char **argv)
#endif
);
if (tabstops_str) {
- tabstops = atoi(tabstops_str);
+ tabstops = xatou(tabstops_str);
}
if (terminal_width_str) {
- terminal_width = atoi(terminal_width_str);
+ terminal_width = xatou(terminal_width_str);
}
#else
opt = getopt32(argc, argv, ls_options
diff --git a/coreutils/mknod.c b/coreutils/mknod.c
index 9c97b03..7cc478f 100644
--- a/coreutils/mknod.c
+++ b/coreutils/mknod.c
@@ -9,11 +9,8 @@
/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
#include <sys/sysmacros.h> // For makedev
-#include <unistd.h>
+
#include "busybox.h"
#include "libcoreutils/coreutils.h"
@@ -37,8 +34,8 @@ int mknod_main(int argc, char **argv)
if ((*name != 'p') && ((argc -= 2) == 2)) {
/* Autodetect what the system supports; thexe macros should
* optimize out to two constants. */
- dev = makedev(bb_xgetularg10_bnd(argv[2], 0, major(UINT_MAX)),
- bb_xgetularg10_bnd(argv[3], 0, minor(UINT_MAX)));
+ dev = makedev(xatoul_range(argv[2], 0, major(UINT_MAX)),
+ xatoul_range(argv[3], 0, minor(UINT_MAX)));
}
if (argc == 2) {
diff --git a/coreutils/nice.c b/coreutils/nice.c
index 4c54ddd..a347001 100644
--- a/coreutils/nice.c
+++ b/coreutils/nice.c
@@ -52,7 +52,7 @@ int nice_main(int argc, char **argv)
if (argc < 4) { /* Missing priority and/or utility! */
bb_show_usage();
}
- adjustment = bb_xgetlarg(argv[1], 10, INT_MIN, INT_MAX);
+ adjustment = xatoi(argv[1]);
argv += 2;
}
diff --git a/coreutils/printf.c b/coreutils/printf.c
index 4a20804..1511034 100644
--- a/coreutils/printf.c
+++ b/coreutils/printf.c
@@ -30,7 +30,7 @@
%b = print an argument string, interpreting backslash escapes
- The `format' argument is re-used as many times as necessary
+ The 'format' argument is re-used as many times as necessary
to convert all of the given arguments.
David MacKenzie <djm@gnu.ai.mit.edu> */
@@ -57,7 +57,7 @@ static void multiconvert(char *arg, void *result, converter convert)
fputs(arg, stderr);
}
-static unsigned long xstrtoul(char *arg)
+static unsigned long my_xstrtoul(char *arg)
{
unsigned long result;
@@ -65,14 +65,14 @@ static unsigned long xstrtoul(char *arg)
return result;
}
-static long xstrtol(char *arg)
+static long my_xstrtol(char *arg)
{
long result;
multiconvert(arg, &result, (converter)safe_strtol);
return result;
}
-static double xstrtod(char *arg)
+static double my_xstrtod(char *arg)
{
double result;
multiconvert(arg, &result, (converter)safe_strtod);
@@ -120,13 +120,13 @@ int printf_main(int argc, char **argv)
}
/* Print the text in FORMAT, using ARGV (with ARGC elements) for
- arguments to any `%' directives.
+ arguments to any '%' directives.
Return the number of elements of ARGV used. */
static int print_formatted(char *format, int argc, char **argv)
{
int save_argc = argc; /* Preserve original value. */
- char *f; /* Pointer into `format'. */
+ char *f; /* Pointer into 'format'. */
char *direc_start; /* Start of % directive. */
size_t direc_length; /* Length of % directive. */
int field_width; /* Arg to first '*', or -1 if none. */
@@ -158,7 +158,7 @@ static int print_formatted(char *format, int argc, char **argv)
++f;
++direc_length;
if (argc > 0) {
- field_width = xstrtoul(*argv);
+ field_width = my_xstrtoul(*argv);
++argv;
--argc;
} else
@@ -175,7 +175,7 @@ static int print_formatted(char *format, int argc, char **argv)
++f;
++direc_length;
if (argc > 0) {
- precision = xstrtoul(*argv);
+ precision = my_xstrtoul(*argv);
++argv;
--argc;
} else
@@ -235,14 +235,14 @@ print_direc(char *start, size_t length, int field_width, int precision,
case 'i':
if (field_width < 0) {
if (precision < 0)
- printf(p, xstrtol(argument));
+ printf(p, my_xstrtol(argument));
else
- printf(p, precision, xstrtol(argument));
+ printf(p, precision, my_xstrtol(argument));
} else {
if (precision < 0)
- printf(p, field_width, xstrtol(argument));
+ printf(p, field_width, my_xstrtol(argument));
else
- printf(p, field_width, precision, xstrtol(argument));
+ printf(p, field_width, precision, my_xstrtol(argument));
}
break;
@@ -252,14 +252,14 @@ print_direc(char *start, size_t length, int field_width, int precision,
case 'X':
if (field_width < 0) {
if (precision < 0)
- printf(p, xstrtoul(argument));
+ printf(p, my_xstrtoul(argument));
else
- printf(p, precision, xstrtoul(argument));
+ printf(p, precision, my_xstrtoul(argument));
} else {
if (precision < 0)
- printf(p, field_width, xstrtoul(argument));
+ printf(p, field_width, my_xstrtoul(argument));
else
- printf(p, field_width, precision, xstrtoul(argument));
+ printf(p, field_width, precision, my_xstrtoul(argument));
}
break;
@@ -270,14 +270,14 @@ print_direc(char *start, size_t length, int field_width, int precision,
case 'G':
if (field_width < 0) {
if (precision < 0)
- printf(p, xstrtod(argument));
+ printf(p, my_xstrtod(argument));
else
- printf(p, precision, xstrtod(argument));
+ printf(p, precision, my_xstrtod(argument));
} else {
if (precision < 0)
- printf(p, field_width, xstrtod(argument));
+ printf(p, field_width, my_xstrtod(argument));
else
- printf(p, field_width, precision, xstrtod(argument));
+ printf(p, field_width, precision, my_xstrtod(argument));
}
break;
diff --git a/coreutils/sleep.c b/coreutils/sleep.c
index 3946c34..e32e215 100644
--- a/coreutils/sleep.c
+++ b/coreutils/sleep.c
@@ -24,7 +24,7 @@
#include "busybox.h"
#ifdef CONFIG_FEATURE_FANCY_SLEEP
-static const struct suffix_mult sleep_suffixes[] = {
+static const struct suffix_mult sfx[] = {
{ "s", 1 },
{ "m", 60 },
{ "h", 60*60 },
@@ -46,9 +46,7 @@ int sleep_main(int argc, char **argv)
++argv;
duration = 0;
do {
- duration += bb_xgetularg_bnd_sfx(*argv, 10,
- 0, UINT_MAX-duration,
- sleep_suffixes);
+ duration += xatoul_range_sfx(*argv, 0, UINT_MAX-duration, sfx);
} while (*++argv);
#else /* CONFIG_FEATURE_FANCY_SLEEP */
@@ -57,11 +55,7 @@ int sleep_main(int argc, char **argv)
bb_show_usage();
}
-#if UINT_MAX == ULONG_MAX
- duration = bb_xgetularg10(argv[1]);
-#else
- duration = bb_xgetularg10_bnd(argv[1], 0, UINT_MAX);
-#endif
+ duration = xatou(argv[1]);
#endif /* CONFIG_FEATURE_FANCY_SLEEP */
diff --git a/coreutils/stty.c b/coreutils/stty.c
index a41faaf..8c16c27 100644
--- a/coreutils/stty.c
+++ b/coreutils/stty.c
@@ -370,9 +370,9 @@ enum {
};
/* The width of the screen, for output wrapping */
-static int max_col;
+static unsigned max_col = 80; /* default */
/* Current position, to know when to wrap */
-static int current_col;
+static unsigned current_col;
static const char *device_name = bb_msg_standard_input;
/* Return a string that is the printable representation of character CH */
@@ -422,7 +422,7 @@ static tcflag_t *mode_type_flag(unsigned type, const struct termios *mode)
static speed_t string_to_baud_or_die(const char *arg)
{
- return tty_value_to_baud(bb_xparse_number(arg, 0));
+ return tty_value_to_baud(xatou(arg));
}
static void set_speed_or_die(enum speed_setting type, const char *arg,
@@ -556,9 +556,8 @@ static inline void display_window_size(int fancy) {}
#endif /* !TIOCGWINSZ */
-static int screen_columns(void)
+static int screen_columns_or_die(void)
{
- int columns;
const char *s;
#ifdef TIOCGWINSZ
@@ -574,11 +573,10 @@ static int screen_columns(void)
return win.ws_col;
#endif
- columns = 80;
- if ((s = getenv("COLUMNS"))) {
- columns = atoi(s);
- }
- return columns;
+ s = getenv("COLUMNS");
+ if (s)
+ return xatoi_u(s);
+ return 80;
}
static const struct suffix_mult stty_suffixes[] = {
@@ -745,14 +743,14 @@ end_option:
#ifdef HAVE_C_LINE
case param_line:
# ifndef TIOCGWINSZ
- bb_xparse_number(argnext, stty_suffixes);
+ xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes);
break;
# endif /* else fall-through */
#endif
#ifdef TIOCGWINSZ
case param_rows:
case param_cols:
- bb_xparse_number(argnext, stty_suffixes);
+ xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes);
break;
case param_size:
#endif
@@ -802,7 +800,7 @@ end_option:
perror_on_device_and_die("%s");
if (verbose_output || recoverable_output || noargs) {
- max_col = screen_columns();
+ max_col = screen_columns_or_die();
output_func(&mode);
return EXIT_SUCCESS;
}
@@ -846,24 +844,22 @@ end_option:
switch (param) {
#ifdef HAVE_C_LINE
case param_line:
- mode.c_line = bb_xparse_number(argnext, stty_suffixes);
+ mode.c_line = xatoul_sfx(argnext, stty_suffixes);
require_set_attr = 1;
break;
#endif
#ifdef TIOCGWINSZ
case param_cols:
- set_window_size(-1, (int) bb_xparse_number(argnext, stty_suffixes));
+ set_window_size(-1, xatoul_sfx(argnext, stty_suffixes));
break;
case param_size:
- max_col = screen_columns();
display_window_size(0);
break;
case param_rows:
- set_window_size((int) bb_xparse_number(argnext, stty_suffixes), -1);
+ set_window_size(xatoul_sfx(argnext, stty_suffixes), -1);
break;
#endif
case param_speed:
- max_col = screen_columns();
display_speed(&mode, 0);
break;
case param_ispeed:
@@ -1096,7 +1092,7 @@ static void set_control_char_or_die(const struct control_info *info,
unsigned char value;
if (info->name == stty_min || info->name == stty_time)
- value = bb_xparse_number(arg, stty_suffixes);
+ value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes);
else if (arg[0] == '\0' || arg[1] == '\0')
value = arg[0];
else if (streq(arg, "^-") || streq(arg, "undef"))
@@ -1106,7 +1102,7 @@ static void set_control_char_or_die(const struct control_info *info,
if (arg[1] == '?')
value = 127;
} else
- value = bb_xparse_number(arg, stty_suffixes);
+ value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes);
mode->c_cc[info->offset] = value;
}
diff --git a/coreutils/tail.c b/coreutils/tail.c
index 49f1bcd..82c0d99 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -132,7 +132,7 @@ int tail_main(int argc, char **argv)
#if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_TAIL
GET_COUNT:
#endif
- count = bb_xgetlarg10_sfx(optarg, tail_suffixes);
+ count = xatol_sfx(optarg, tail_suffixes);
/* Note: Leading whitespace is an error trapped above. */
if (*optarg == '+') {
from_top = 1;
@@ -148,7 +148,7 @@ int tail_main(int argc, char **argv)
header_threshhold = INT_MAX;
break;
case 's':
- sleep_period =bb_xgetularg10_bnd(optarg, 0, UINT_MAX);
+ sleep_period = xatou(optarg);
break;
case 'v':
header_threshhold = 0;
diff --git a/coreutils/uniq.c b/coreutils/uniq.c
index 26afc00..1b201af 100644
--- a/coreutils/uniq.c
+++ b/coreutils/uniq.c
@@ -37,7 +37,7 @@ int uniq_main(int argc, char **argv)
while ((opt = getopt(argc, argv, uniq_opts)) > 0) {
if ((opt == 'f') || (opt == 's')) {
- int t = bb_xgetularg10(optarg);
+ int t = xatoul(optarg);
if (opt == 'f') {
skip_fields = t;
} else {
diff --git a/coreutils/usleep.c b/coreutils/usleep.c
index 90ddc5a..de473a7 100644
--- a/coreutils/usleep.c
+++ b/coreutils/usleep.c
@@ -20,7 +20,7 @@ int usleep_main(int argc, char **argv)
bb_show_usage();
}
- if (usleep(bb_xgetularg10_bnd(argv[1], 0, UINT_MAX))) {
+ if (usleep(xatou(argv[1]))) {
bb_perror_nomsg_and_die();
}
diff --git a/coreutils/watch.c b/coreutils/watch.c
index 7b9c669..b1a7d90 100644
--- a/coreutils/watch.c
+++ b/coreutils/watch.c
@@ -28,7 +28,7 @@ int watch_main(int argc, char **argv)
/* don't use getopt, because it permutes the arguments */
++argv;
if ((argc > 3) && argv[0][0] == '-' && argv[0][1] == 'n') {
- period = bb_xgetularg10_bnd(argv[1], 1, UINT_MAX);
+ period = xatou(argv[1]);
argv += 2;
}
watched_argv = argv;