aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-10-08 12:49:22 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-10-08 12:49:22 +0000
commit87d25a2b8535dc627a02eb539fa3946be2a24647 (patch)
treefc4d14a910593d1235318bb36abe5e9f72d2039e /coreutils
parent81177b14907e73f11560f69e0b4ec34371f1a7d5 (diff)
downloadbusybox-w32-87d25a2b8535dc627a02eb539fa3946be2a24647.tar.gz
busybox-w32-87d25a2b8535dc627a02eb539fa3946be2a24647.tar.bz2
busybox-w32-87d25a2b8535dc627a02eb539fa3946be2a24647.zip
attempt to regularize atoi mess.
git-svn-id: svn://busybox.net/trunk/busybox@16342 69ca8d6d-28ef-0310-b511-8ec308f3f277
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 ef914128c..e2bc5ab12 100644
--- a/coreutils/cal.c
+++ b/coreutils/cal.c
@@ -112,9 +112,9 @@ int cal_main(int argc, char **argv)
112 } 112 }
113 } else { 113 } else {
114 if (argc == 2) { 114 if (argc == 2) {
115 month = bb_xgetularg10_bnd(*argv++, 1, 12); 115 month = xatoul_range(*argv++, 1, 12);
116 } 116 }
117 year = bb_xgetularg10_bnd(*argv, 1, 9999); 117 year = xatoul_range(*argv, 1, 9999);
118 } 118 }
119 119
120 blank_string(day_headings, sizeof(day_headings) - 7 + 7*julian); 120 blank_string(day_headings, sizeof(day_headings) - 7 + 7*julian);
diff --git a/coreutils/cut.c b/coreutils/cut.c
index 69f28fa8d..7ba947fae 100644
--- a/coreutils/cut.c
+++ b/coreutils/cut.c
@@ -163,17 +163,7 @@ static void cut_file(FILE * file)
163 } 163 }
164} 164}
165 165
166static int getval(char *ntok) 166static const char _op_on_field[] = " only when operating on fields";
167{
168 char *junk;
169 int i = strtoul(ntok, &junk, 10);
170
171 if (*junk != '\0' || i < 0)
172 bb_error_msg_and_die("invalid byte or field list");
173 return i;
174}
175
176static const char * const _op_on_field = " only when operating on fields";
177 167
178int cut_main(int argc, char **argv) 168int cut_main(int argc, char **argv)
179{ 169{
@@ -231,7 +221,7 @@ int cut_main(int argc, char **argv)
231 } else if (strlen(ntok) == 0) { 221 } else if (strlen(ntok) == 0) {
232 s = BOL; 222 s = BOL;
233 } else { 223 } else {
234 s = getval(ntok); 224 s = xatoi_u(ntok);
235 /* account for the fact that arrays are zero based, while 225 /* account for the fact that arrays are zero based, while
236 * the user expects the first char on the line to be char #1 */ 226 * the user expects the first char on the line to be char #1 */
237 if (s != 0) 227 if (s != 0)
@@ -245,7 +235,7 @@ int cut_main(int argc, char **argv)
245 } else if (strlen(ntok) == 0) { 235 } else if (strlen(ntok) == 0) {
246 e = EOL; 236 e = EOL;
247 } else { 237 } else {
248 e = getval(ntok); 238 e = xatoi_u(ntok);
249 /* if the user specified and end position of 0, that means "til the 239 /* if the user specified and end position of 0, that means "til the
250 * end of the line */ 240 * end of the line */
251 if (e == 0) 241 if (e == 0)
diff --git a/coreutils/dd.c b/coreutils/dd.c
index e63244d81..d557ae46d 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -62,19 +62,19 @@ int dd_main(int argc, char **argv)
62 for (n = 1; n < argc; n++) { 62 for (n = 1; n < argc; n++) {
63 // FIXME: make them capable of eating LARGE numbers 63 // FIXME: make them capable of eating LARGE numbers
64 if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("ibs=", argv[n], 4)) { 64 if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("ibs=", argv[n], 4)) {
65 ibs = bb_xparse_number(argv[n]+4, dd_suffixes); 65 ibs = xatoul_sfx(argv[n]+4, dd_suffixes);
66 flags |= twobufs_flag; 66 flags |= twobufs_flag;
67 } else if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("obs=", argv[n], 4)) { 67 } else if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("obs=", argv[n], 4)) {
68 obs = bb_xparse_number(argv[n]+4, dd_suffixes); 68 obs = xatoul_sfx(argv[n]+4, dd_suffixes);
69 flags |= twobufs_flag; 69 flags |= twobufs_flag;
70 } else if (!strncmp("bs=", argv[n], 3)) 70 } else if (!strncmp("bs=", argv[n], 3))
71 ibs = obs = bb_xparse_number(argv[n]+3, dd_suffixes); 71 ibs = obs = xatoul_sfx(argv[n]+3, dd_suffixes);
72 else if (!strncmp("count=", argv[n], 6)) 72 else if (!strncmp("count=", argv[n], 6))
73 count = bb_xparse_number(argv[n]+6, dd_suffixes); 73 count = xatoul_sfx(argv[n]+6, dd_suffixes);
74 else if (!strncmp("seek=", argv[n], 5)) 74 else if (!strncmp("seek=", argv[n], 5))
75 seek = bb_xparse_number(argv[n]+5, dd_suffixes); 75 seek = xatoul_sfx(argv[n]+5, dd_suffixes);
76 else if (!strncmp("skip=", argv[n], 5)) 76 else if (!strncmp("skip=", argv[n], 5))
77 skip = bb_xparse_number(argv[n]+5, dd_suffixes); 77 skip = xatoul_sfx(argv[n]+5, dd_suffixes);
78 else if (!strncmp("if=", argv[n], 3)) 78 else if (!strncmp("if=", argv[n], 3))
79 infile = argv[n]+3; 79 infile = argv[n]+3;
80 else if (!strncmp("of=", argv[n], 3)) 80 else if (!strncmp("of=", argv[n], 3))
diff --git a/coreutils/diff.c b/coreutils/diff.c
index b30aad5a7..65757d7d1 100644
--- a/coreutils/diff.c
+++ b/coreutils/diff.c
@@ -1192,7 +1192,7 @@ int diff_main(int argc, char **argv)
1192 1192
1193 context = 3; /* This is the default number of lines of context. */ 1193 context = 3; /* This is the default number of lines of context. */
1194 if (cmd_flags & FLAG_U) { 1194 if (cmd_flags & FLAG_U) {
1195 context = bb_xgetlarg(U_opt, 10, 1, INT_MAX); 1195 context = xatoul_range(U_opt, 1, INT_MAX);
1196 } 1196 }
1197 argc -= optind; 1197 argc -= optind;
1198 argv += optind; 1198 argv += optind;
diff --git a/coreutils/du.c b/coreutils/du.c
index 1452e5883..f61d978b7 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -215,7 +215,7 @@ int du_main(int argc, char **argv)
215 one_file_system = opt & (1 << 5); /* -x opt */ 215 one_file_system = opt & (1 << 5); /* -x opt */
216 if((opt & (1 << 6))) { 216 if((opt & (1 << 6))) {
217 /* -d opt */ 217 /* -d opt */
218 max_print_depth = bb_xgetularg10_bnd(smax_print_depth, 0, INT_MAX); 218 max_print_depth = xatoi_u(smax_print_depth);
219 } 219 }
220 if((opt & (1 << 7))) { 220 if((opt & (1 << 7))) {
221 /* -l opt */ 221 /* -l opt */
diff --git a/coreutils/fold.c b/coreutils/fold.c
index 3b5be64fe..45f4472e4 100644
--- a/coreutils/fold.c
+++ b/coreutils/fold.c
@@ -62,7 +62,7 @@ int fold_main(int argc, char **argv)
62 62
63 flags = getopt32(argc, argv, "bsw:", &w_opt); 63 flags = getopt32(argc, argv, "bsw:", &w_opt);
64 if (flags & FLAG_WIDTH) 64 if (flags & FLAG_WIDTH)
65 width = bb_xgetlarg(w_opt, 10, 1, 10000); 65 width = xatoul_range(w_opt, 1, 10000);
66 66
67 argv += optind; 67 argv += optind;
68 if (!*argv) { 68 if (!*argv) {
diff --git a/coreutils/head.c b/coreutils/head.c
index 7d5f219d2..060febcf7 100644
--- a/coreutils/head.c
+++ b/coreutils/head.c
@@ -64,32 +64,30 @@ int head_main(int argc, char **argv)
64 while ((opt = getopt(argc, argv, head_opts)) > 0) { 64 while ((opt = getopt(argc, argv, head_opts)) > 0) {
65 switch (opt) { 65 switch (opt) {
66#if ENABLE_FEATURE_FANCY_HEAD 66#if ENABLE_FEATURE_FANCY_HEAD
67 case 'q': 67 case 'q':
68 header_threshhold = INT_MAX; 68 header_threshhold = INT_MAX;
69 break; 69 break;
70 case 'v': 70 case 'v':
71 header_threshhold = -1; 71 header_threshhold = -1;
72 break; 72 break;
73 case 'c': 73 case 'c':
74 count_bytes = 1; 74 count_bytes = 1;
75 /* fall through */ 75 /* fall through */
76#endif 76#endif
77 case 'n': 77 case 'n':
78 p = optarg; 78 p = optarg;
79#if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_HEAD 79#if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
80 GET_COUNT: 80 GET_COUNT:
81#endif 81#endif
82 82
83#if !ENABLE_FEATURE_FANCY_HEAD 83#if !ENABLE_FEATURE_FANCY_HEAD
84 count = bb_xgetularg10(p); 84 count = xatoul(p);
85#else 85#else
86 count = bb_xgetularg_bnd_sfx(p, 10, 86 count = xatoul_sfx(p, head_suffixes);
87 0, ULONG_MAX,
88 head_suffixes);
89#endif 87#endif
90 break; 88 break;
91 default: 89 default:
92 bb_show_usage(); 90 bb_show_usage();
93 } 91 }
94 } 92 }
95 93
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 8ba4ab758..f34e83ebe 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -163,8 +163,8 @@ static int list_single(struct dnode *);
163static unsigned int all_fmt; 163static unsigned int all_fmt;
164 164
165#ifdef CONFIG_FEATURE_AUTOWIDTH 165#ifdef CONFIG_FEATURE_AUTOWIDTH
166static int terminal_width = TERMINAL_WIDTH; 166static unsigned terminal_width = TERMINAL_WIDTH;
167static unsigned short tabstops = COLUMN_GAP; 167static unsigned tabstops = COLUMN_GAP;
168#else 168#else
169#define tabstops COLUMN_GAP 169#define tabstops COLUMN_GAP
170#define terminal_width TERMINAL_WIDTH 170#define terminal_width TERMINAL_WIDTH
@@ -915,10 +915,10 @@ int ls_main(int argc, char **argv)
915#endif 915#endif
916 ); 916 );
917 if (tabstops_str) { 917 if (tabstops_str) {
918 tabstops = atoi(tabstops_str); 918 tabstops = xatou(tabstops_str);
919 } 919 }
920 if (terminal_width_str) { 920 if (terminal_width_str) {
921 terminal_width = atoi(terminal_width_str); 921 terminal_width = xatou(terminal_width_str);
922 } 922 }
923#else 923#else
924 opt = getopt32(argc, argv, ls_options 924 opt = getopt32(argc, argv, ls_options
diff --git a/coreutils/mknod.c b/coreutils/mknod.c
index 9c97b0302..7cc478f17 100644
--- a/coreutils/mknod.c
+++ b/coreutils/mknod.c
@@ -9,11 +9,8 @@
9 9
10/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */ 10/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
11 11
12#include <stdlib.h>
13#include <string.h>
14#include <sys/stat.h>
15#include <sys/sysmacros.h> // For makedev 12#include <sys/sysmacros.h> // For makedev
16#include <unistd.h> 13
17#include "busybox.h" 14#include "busybox.h"
18#include "libcoreutils/coreutils.h" 15#include "libcoreutils/coreutils.h"
19 16
@@ -37,8 +34,8 @@ int mknod_main(int argc, char **argv)
37 if ((*name != 'p') && ((argc -= 2) == 2)) { 34 if ((*name != 'p') && ((argc -= 2) == 2)) {
38 /* Autodetect what the system supports; thexe macros should 35 /* Autodetect what the system supports; thexe macros should
39 * optimize out to two constants. */ 36 * optimize out to two constants. */
40 dev = makedev(bb_xgetularg10_bnd(argv[2], 0, major(UINT_MAX)), 37 dev = makedev(xatoul_range(argv[2], 0, major(UINT_MAX)),
41 bb_xgetularg10_bnd(argv[3], 0, minor(UINT_MAX))); 38 xatoul_range(argv[3], 0, minor(UINT_MAX)));
42 } 39 }
43 40
44 if (argc == 2) { 41 if (argc == 2) {
diff --git a/coreutils/nice.c b/coreutils/nice.c
index 4c54dddbb..a347001e3 100644
--- a/coreutils/nice.c
+++ b/coreutils/nice.c
@@ -52,7 +52,7 @@ int nice_main(int argc, char **argv)
52 if (argc < 4) { /* Missing priority and/or utility! */ 52 if (argc < 4) { /* Missing priority and/or utility! */
53 bb_show_usage(); 53 bb_show_usage();
54 } 54 }
55 adjustment = bb_xgetlarg(argv[1], 10, INT_MIN, INT_MAX); 55 adjustment = xatoi(argv[1]);
56 argv += 2; 56 argv += 2;
57 } 57 }
58 58
diff --git a/coreutils/printf.c b/coreutils/printf.c
index 4a208040f..1511034a1 100644
--- a/coreutils/printf.c
+++ b/coreutils/printf.c
@@ -30,7 +30,7 @@
30 30
31 %b = print an argument string, interpreting backslash escapes 31 %b = print an argument string, interpreting backslash escapes
32 32
33 The `format' argument is re-used as many times as necessary 33 The 'format' argument is re-used as many times as necessary
34 to convert all of the given arguments. 34 to convert all of the given arguments.
35 35
36 David MacKenzie <djm@gnu.ai.mit.edu> */ 36 David MacKenzie <djm@gnu.ai.mit.edu> */
@@ -57,7 +57,7 @@ static void multiconvert(char *arg, void *result, converter convert)
57 fputs(arg, stderr); 57 fputs(arg, stderr);
58} 58}
59 59
60static unsigned long xstrtoul(char *arg) 60static unsigned long my_xstrtoul(char *arg)
61{ 61{
62 unsigned long result; 62 unsigned long result;
63 63
@@ -65,14 +65,14 @@ static unsigned long xstrtoul(char *arg)
65 return result; 65 return result;
66} 66}
67 67
68static long xstrtol(char *arg) 68static long my_xstrtol(char *arg)
69{ 69{
70 long result; 70 long result;
71 multiconvert(arg, &result, (converter)safe_strtol); 71 multiconvert(arg, &result, (converter)safe_strtol);
72 return result; 72 return result;
73} 73}
74 74
75static double xstrtod(char *arg) 75static double my_xstrtod(char *arg)
76{ 76{
77 double result; 77 double result;
78 multiconvert(arg, &result, (converter)safe_strtod); 78 multiconvert(arg, &result, (converter)safe_strtod);
@@ -120,13 +120,13 @@ int printf_main(int argc, char **argv)
120} 120}
121 121
122/* Print the text in FORMAT, using ARGV (with ARGC elements) for 122/* Print the text in FORMAT, using ARGV (with ARGC elements) for
123 arguments to any `%' directives. 123 arguments to any '%' directives.
124 Return the number of elements of ARGV used. */ 124 Return the number of elements of ARGV used. */
125 125
126static int print_formatted(char *format, int argc, char **argv) 126static int print_formatted(char *format, int argc, char **argv)
127{ 127{
128 int save_argc = argc; /* Preserve original value. */ 128 int save_argc = argc; /* Preserve original value. */
129 char *f; /* Pointer into `format'. */ 129 char *f; /* Pointer into 'format'. */
130 char *direc_start; /* Start of % directive. */ 130 char *direc_start; /* Start of % directive. */
131 size_t direc_length; /* Length of % directive. */ 131 size_t direc_length; /* Length of % directive. */
132 int field_width; /* Arg to first '*', or -1 if none. */ 132 int field_width; /* Arg to first '*', or -1 if none. */
@@ -158,7 +158,7 @@ static int print_formatted(char *format, int argc, char **argv)
158 ++f; 158 ++f;
159 ++direc_length; 159 ++direc_length;
160 if (argc > 0) { 160 if (argc > 0) {
161 field_width = xstrtoul(*argv); 161 field_width = my_xstrtoul(*argv);
162 ++argv; 162 ++argv;
163 --argc; 163 --argc;
164 } else 164 } else
@@ -175,7 +175,7 @@ static int print_formatted(char *format, int argc, char **argv)
175 ++f; 175 ++f;
176 ++direc_length; 176 ++direc_length;
177 if (argc > 0) { 177 if (argc > 0) {
178 precision = xstrtoul(*argv); 178 precision = my_xstrtoul(*argv);
179 ++argv; 179 ++argv;
180 --argc; 180 --argc;
181 } else 181 } else
@@ -235,14 +235,14 @@ print_direc(char *start, size_t length, int field_width, int precision,
235 case 'i': 235 case 'i':
236 if (field_width < 0) { 236 if (field_width < 0) {
237 if (precision < 0) 237 if (precision < 0)
238 printf(p, xstrtol(argument)); 238 printf(p, my_xstrtol(argument));
239 else 239 else
240 printf(p, precision, xstrtol(argument)); 240 printf(p, precision, my_xstrtol(argument));
241 } else { 241 } else {
242 if (precision < 0) 242 if (precision < 0)
243 printf(p, field_width, xstrtol(argument)); 243 printf(p, field_width, my_xstrtol(argument));
244 else 244 else
245 printf(p, field_width, precision, xstrtol(argument)); 245 printf(p, field_width, precision, my_xstrtol(argument));
246 } 246 }
247 break; 247 break;
248 248
@@ -252,14 +252,14 @@ print_direc(char *start, size_t length, int field_width, int precision,
252 case 'X': 252 case 'X':
253 if (field_width < 0) { 253 if (field_width < 0) {
254 if (precision < 0) 254 if (precision < 0)
255 printf(p, xstrtoul(argument)); 255 printf(p, my_xstrtoul(argument));
256 else 256 else
257 printf(p, precision, xstrtoul(argument)); 257 printf(p, precision, my_xstrtoul(argument));
258 } else { 258 } else {
259 if (precision < 0) 259 if (precision < 0)
260 printf(p, field_width, xstrtoul(argument)); 260 printf(p, field_width, my_xstrtoul(argument));
261 else 261 else
262 printf(p, field_width, precision, xstrtoul(argument)); 262 printf(p, field_width, precision, my_xstrtoul(argument));
263 } 263 }
264 break; 264 break;
265 265
@@ -270,14 +270,14 @@ print_direc(char *start, size_t length, int field_width, int precision,
270 case 'G': 270 case 'G':
271 if (field_width < 0) { 271 if (field_width < 0) {
272 if (precision < 0) 272 if (precision < 0)
273 printf(p, xstrtod(argument)); 273 printf(p, my_xstrtod(argument));
274 else 274 else
275 printf(p, precision, xstrtod(argument)); 275 printf(p, precision, my_xstrtod(argument));
276 } else { 276 } else {
277 if (precision < 0) 277 if (precision < 0)
278 printf(p, field_width, xstrtod(argument)); 278 printf(p, field_width, my_xstrtod(argument));
279 else 279 else
280 printf(p, field_width, precision, xstrtod(argument)); 280 printf(p, field_width, precision, my_xstrtod(argument));
281 } 281 }
282 break; 282 break;
283 283
diff --git a/coreutils/sleep.c b/coreutils/sleep.c
index 3946c3433..e32e2157d 100644
--- a/coreutils/sleep.c
+++ b/coreutils/sleep.c
@@ -24,7 +24,7 @@
24#include "busybox.h" 24#include "busybox.h"
25 25
26#ifdef CONFIG_FEATURE_FANCY_SLEEP 26#ifdef CONFIG_FEATURE_FANCY_SLEEP
27static const struct suffix_mult sleep_suffixes[] = { 27static const struct suffix_mult sfx[] = {
28 { "s", 1 }, 28 { "s", 1 },
29 { "m", 60 }, 29 { "m", 60 },
30 { "h", 60*60 }, 30 { "h", 60*60 },
@@ -46,9 +46,7 @@ int sleep_main(int argc, char **argv)
46 ++argv; 46 ++argv;
47 duration = 0; 47 duration = 0;
48 do { 48 do {
49 duration += bb_xgetularg_bnd_sfx(*argv, 10, 49 duration += xatoul_range_sfx(*argv, 0, UINT_MAX-duration, sfx);
50 0, UINT_MAX-duration,
51 sleep_suffixes);
52 } while (*++argv); 50 } while (*++argv);
53 51
54#else /* CONFIG_FEATURE_FANCY_SLEEP */ 52#else /* CONFIG_FEATURE_FANCY_SLEEP */
@@ -57,11 +55,7 @@ int sleep_main(int argc, char **argv)
57 bb_show_usage(); 55 bb_show_usage();
58 } 56 }
59 57
60#if UINT_MAX == ULONG_MAX 58 duration = xatou(argv[1]);
61 duration = bb_xgetularg10(argv[1]);
62#else
63 duration = bb_xgetularg10_bnd(argv[1], 0, UINT_MAX);
64#endif
65 59
66#endif /* CONFIG_FEATURE_FANCY_SLEEP */ 60#endif /* CONFIG_FEATURE_FANCY_SLEEP */
67 61
diff --git a/coreutils/stty.c b/coreutils/stty.c
index a41faaf1e..8c16c27a9 100644
--- a/coreutils/stty.c
+++ b/coreutils/stty.c
@@ -370,9 +370,9 @@ enum {
370}; 370};
371 371
372/* The width of the screen, for output wrapping */ 372/* The width of the screen, for output wrapping */
373static int max_col; 373static unsigned max_col = 80; /* default */
374/* Current position, to know when to wrap */ 374/* Current position, to know when to wrap */
375static int current_col; 375static unsigned current_col;
376static const char *device_name = bb_msg_standard_input; 376static const char *device_name = bb_msg_standard_input;
377 377
378/* Return a string that is the printable representation of character CH */ 378/* 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)
422 422
423static speed_t string_to_baud_or_die(const char *arg) 423static speed_t string_to_baud_or_die(const char *arg)
424{ 424{
425 return tty_value_to_baud(bb_xparse_number(arg, 0)); 425 return tty_value_to_baud(xatou(arg));
426} 426}
427 427
428static void set_speed_or_die(enum speed_setting type, const char *arg, 428static void set_speed_or_die(enum speed_setting type, const char *arg,
@@ -556,9 +556,8 @@ static inline void display_window_size(int fancy) {}
556 556
557#endif /* !TIOCGWINSZ */ 557#endif /* !TIOCGWINSZ */
558 558
559static int screen_columns(void) 559static int screen_columns_or_die(void)
560{ 560{
561 int columns;
562 const char *s; 561 const char *s;
563 562
564#ifdef TIOCGWINSZ 563#ifdef TIOCGWINSZ
@@ -574,11 +573,10 @@ static int screen_columns(void)
574 return win.ws_col; 573 return win.ws_col;
575#endif 574#endif
576 575
577 columns = 80; 576 s = getenv("COLUMNS");
578 if ((s = getenv("COLUMNS"))) { 577 if (s)
579 columns = atoi(s); 578 return xatoi_u(s);
580 } 579 return 80;
581 return columns;
582} 580}
583 581
584static const struct suffix_mult stty_suffixes[] = { 582static const struct suffix_mult stty_suffixes[] = {
@@ -745,14 +743,14 @@ end_option:
745#ifdef HAVE_C_LINE 743#ifdef HAVE_C_LINE
746 case param_line: 744 case param_line:
747# ifndef TIOCGWINSZ 745# ifndef TIOCGWINSZ
748 bb_xparse_number(argnext, stty_suffixes); 746 xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes);
749 break; 747 break;
750# endif /* else fall-through */ 748# endif /* else fall-through */
751#endif 749#endif
752#ifdef TIOCGWINSZ 750#ifdef TIOCGWINSZ
753 case param_rows: 751 case param_rows:
754 case param_cols: 752 case param_cols:
755 bb_xparse_number(argnext, stty_suffixes); 753 xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes);
756 break; 754 break;
757 case param_size: 755 case param_size:
758#endif 756#endif
@@ -802,7 +800,7 @@ end_option:
802 perror_on_device_and_die("%s"); 800 perror_on_device_and_die("%s");
803 801
804 if (verbose_output || recoverable_output || noargs) { 802 if (verbose_output || recoverable_output || noargs) {
805 max_col = screen_columns(); 803 max_col = screen_columns_or_die();
806 output_func(&mode); 804 output_func(&mode);
807 return EXIT_SUCCESS; 805 return EXIT_SUCCESS;
808 } 806 }
@@ -846,24 +844,22 @@ end_option:
846 switch (param) { 844 switch (param) {
847#ifdef HAVE_C_LINE 845#ifdef HAVE_C_LINE
848 case param_line: 846 case param_line:
849 mode.c_line = bb_xparse_number(argnext, stty_suffixes); 847 mode.c_line = xatoul_sfx(argnext, stty_suffixes);
850 require_set_attr = 1; 848 require_set_attr = 1;
851 break; 849 break;
852#endif 850#endif
853#ifdef TIOCGWINSZ 851#ifdef TIOCGWINSZ
854 case param_cols: 852 case param_cols:
855 set_window_size(-1, (int) bb_xparse_number(argnext, stty_suffixes)); 853 set_window_size(-1, xatoul_sfx(argnext, stty_suffixes));
856 break; 854 break;
857 case param_size: 855 case param_size:
858 max_col = screen_columns();
859 display_window_size(0); 856 display_window_size(0);
860 break; 857 break;
861 case param_rows: 858 case param_rows:
862 set_window_size((int) bb_xparse_number(argnext, stty_suffixes), -1); 859 set_window_size(xatoul_sfx(argnext, stty_suffixes), -1);
863 break; 860 break;
864#endif 861#endif
865 case param_speed: 862 case param_speed:
866 max_col = screen_columns();
867 display_speed(&mode, 0); 863 display_speed(&mode, 0);
868 break; 864 break;
869 case param_ispeed: 865 case param_ispeed:
@@ -1096,7 +1092,7 @@ static void set_control_char_or_die(const struct control_info *info,
1096 unsigned char value; 1092 unsigned char value;
1097 1093
1098 if (info->name == stty_min || info->name == stty_time) 1094 if (info->name == stty_min || info->name == stty_time)
1099 value = bb_xparse_number(arg, stty_suffixes); 1095 value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes);
1100 else if (arg[0] == '\0' || arg[1] == '\0') 1096 else if (arg[0] == '\0' || arg[1] == '\0')
1101 value = arg[0]; 1097 value = arg[0];
1102 else if (streq(arg, "^-") || streq(arg, "undef")) 1098 else if (streq(arg, "^-") || streq(arg, "undef"))
@@ -1106,7 +1102,7 @@ static void set_control_char_or_die(const struct control_info *info,
1106 if (arg[1] == '?') 1102 if (arg[1] == '?')
1107 value = 127; 1103 value = 127;
1108 } else 1104 } else
1109 value = bb_xparse_number(arg, stty_suffixes); 1105 value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes);
1110 mode->c_cc[info->offset] = value; 1106 mode->c_cc[info->offset] = value;
1111} 1107}
1112 1108
diff --git a/coreutils/tail.c b/coreutils/tail.c
index 49f1bcd6a..82c0d99bc 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -132,7 +132,7 @@ int tail_main(int argc, char **argv)
132#if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_TAIL 132#if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_TAIL
133 GET_COUNT: 133 GET_COUNT:
134#endif 134#endif
135 count = bb_xgetlarg10_sfx(optarg, tail_suffixes); 135 count = xatol_sfx(optarg, tail_suffixes);
136 /* Note: Leading whitespace is an error trapped above. */ 136 /* Note: Leading whitespace is an error trapped above. */
137 if (*optarg == '+') { 137 if (*optarg == '+') {
138 from_top = 1; 138 from_top = 1;
@@ -148,7 +148,7 @@ int tail_main(int argc, char **argv)
148 header_threshhold = INT_MAX; 148 header_threshhold = INT_MAX;
149 break; 149 break;
150 case 's': 150 case 's':
151 sleep_period =bb_xgetularg10_bnd(optarg, 0, UINT_MAX); 151 sleep_period = xatou(optarg);
152 break; 152 break;
153 case 'v': 153 case 'v':
154 header_threshhold = 0; 154 header_threshhold = 0;
diff --git a/coreutils/uniq.c b/coreutils/uniq.c
index 26afc00f4..1b201af24 100644
--- a/coreutils/uniq.c
+++ b/coreutils/uniq.c
@@ -37,7 +37,7 @@ int uniq_main(int argc, char **argv)
37 37
38 while ((opt = getopt(argc, argv, uniq_opts)) > 0) { 38 while ((opt = getopt(argc, argv, uniq_opts)) > 0) {
39 if ((opt == 'f') || (opt == 's')) { 39 if ((opt == 'f') || (opt == 's')) {
40 int t = bb_xgetularg10(optarg); 40 int t = xatoul(optarg);
41 if (opt == 'f') { 41 if (opt == 'f') {
42 skip_fields = t; 42 skip_fields = t;
43 } else { 43 } else {
diff --git a/coreutils/usleep.c b/coreutils/usleep.c
index 90ddc5a57..de473a7b2 100644
--- a/coreutils/usleep.c
+++ b/coreutils/usleep.c
@@ -20,7 +20,7 @@ int usleep_main(int argc, char **argv)
20 bb_show_usage(); 20 bb_show_usage();
21 } 21 }
22 22
23 if (usleep(bb_xgetularg10_bnd(argv[1], 0, UINT_MAX))) { 23 if (usleep(xatou(argv[1]))) {
24 bb_perror_nomsg_and_die(); 24 bb_perror_nomsg_and_die();
25 } 25 }
26 26
diff --git a/coreutils/watch.c b/coreutils/watch.c
index 7b9c6698a..b1a7d9086 100644
--- a/coreutils/watch.c
+++ b/coreutils/watch.c
@@ -28,7 +28,7 @@ int watch_main(int argc, char **argv)
28 /* don't use getopt, because it permutes the arguments */ 28 /* don't use getopt, because it permutes the arguments */
29 ++argv; 29 ++argv;
30 if ((argc > 3) && argv[0][0] == '-' && argv[0][1] == 'n') { 30 if ((argc > 3) && argv[0][0] == '-' && argv[0][1] == 'n') {
31 period = bb_xgetularg10_bnd(argv[1], 1, UINT_MAX); 31 period = xatou(argv[1]);
32 argv += 2; 32 argv += 2;
33 } 33 }
34 watched_argv = argv; 34 watched_argv = argv;