summaryrefslogtreecommitdiff
path: root/findutils
diff options
context:
space:
mode:
authorDenis Vlasenko2006-10-08 12:49:22 +0000
committerDenis Vlasenko2006-10-08 12:49:22 +0000
commit1385899416a4396385ad421ae1f532be7103738a (patch)
treefc4d14a910593d1235318bb36abe5e9f72d2039e /findutils
parent5625415085e68ac5e150f54e685417c866620d76 (diff)
downloadbusybox-1385899416a4396385ad421ae1f532be7103738a.zip
busybox-1385899416a4396385ad421ae1f532be7103738a.tar.gz
attempt to regularize atoi mess.
Diffstat (limited to 'findutils')
-rw-r--r--findutils/find.c45
-rw-r--r--findutils/xargs.c4
2 files changed, 20 insertions, 29 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 7e3613a..913a778 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -216,53 +216,47 @@ int find_main(int argc, char **argv)
#endif
#ifdef CONFIG_FEATURE_FIND_PERM
} else if (strcmp(argv[i], "-perm") == 0) {
- char *end;
if (++i == argc)
bb_error_msg_and_die(bb_msg_requires_arg, "-perm");
- perm_mask = strtol(argv[i], &end, 8);
- if ((end[0] != '\0') || (perm_mask > 07777))
- bb_error_msg_and_die(bb_msg_invalid_arg, argv[i], "-perm");
- if ((perm_char = argv[i][0]) == '-')
+ perm_mask = xstrtol_range(argv[i], 8, 0, 07777);
+ perm_char = argv[i][0];
+ if (perm_char == '-')
perm_mask = -perm_mask;
#endif
#ifdef CONFIG_FEATURE_FIND_MTIME
} else if (strcmp(argv[i], "-mtime") == 0) {
- char *end;
if (++i == argc)
bb_error_msg_and_die(bb_msg_requires_arg, "-mtime");
- mtime_days = strtol(argv[i], &end, 10);
- if (end[0] != '\0')
- bb_error_msg_and_die(bb_msg_invalid_arg, argv[i], "-mtime");
- if ((mtime_char = argv[i][0]) == '-')
+ mtime_days = xatol(argv[i]);
+ mtime_char = argv[i][0];
+ if (mtime_char == '-')
mtime_days = -mtime_days;
#endif
#ifdef CONFIG_FEATURE_FIND_MMIN
} else if (strcmp(argv[i], "-mmin") == 0) {
- char *end;
if (++i == argc)
bb_error_msg_and_die(bb_msg_requires_arg, "-mmin");
- mmin_mins = strtol(argv[i], &end, 10);
- if (end[0] != '\0')
- bb_error_msg_and_die(bb_msg_invalid_arg, argv[i], "-mmin");
- if ((mmin_char = argv[i][0]) == '-')
+ mmin_mins = xatol(argv[i]);
+ mmin_char = argv[i][0];
+ if (mmin_char == '-')
mmin_mins = -mmin_mins;
#endif
#ifdef CONFIG_FEATURE_FIND_XDEV
} else if (strcmp(argv[i], "-xdev") == 0) {
struct stat stbuf;
- xdev_count = ( firstopt - 1 ) ? ( firstopt - 1 ) : 1;
- xdev_dev = xmalloc ( xdev_count * sizeof( dev_t ));
+ xdev_count = (firstopt - 1) ? (firstopt - 1) : 1;
+ xdev_dev = xmalloc(xdev_count * sizeof(dev_t));
- if ( firstopt == 1 ) {
- xstat ( ".", &stbuf );
- xdev_dev [0] = stbuf. st_dev;
+ if (firstopt == 1) {
+ xstat(".", &stbuf);
+ xdev_dev[0] = stbuf.st_dev;
}
else {
for (i = 1; i < firstopt; i++) {
- xstat ( argv [i], &stbuf );
- xdev_dev [i-1] = stbuf. st_dev;
+ xstat(argv[i], &stbuf);
+ xdev_dev[i-1] = stbuf.st_dev;
}
}
#endif
@@ -271,17 +265,14 @@ int find_main(int argc, char **argv)
struct stat stat_newer;
if (++i == argc)
bb_error_msg_and_die(bb_msg_requires_arg, "-newer");
- xstat (argv[i], &stat_newer);
+ xstat(argv[i], &stat_newer);
newer_mtime = stat_newer.st_mtime;
#endif
#ifdef CONFIG_FEATURE_FIND_INUM
} else if (strcmp(argv[i], "-inum") == 0) {
- char *end;
if (++i == argc)
bb_error_msg_and_die(bb_msg_requires_arg, "-inum");
- inode_num = strtol(argv[i], &end, 10);
- if (end[0] != '\0')
- bb_error_msg_and_die(bb_msg_invalid_arg, argv[i], "-inum");
+ inode_num = xatoul(argv[i]);
#endif
#ifdef CONFIG_FEATURE_FIND_EXEC
} else if (strcmp(argv[i], "-exec") == 0) {
diff --git a/findutils/xargs.c b/findutils/xargs.c
index 81997b6..e7cc7c3 100644
--- a/findutils/xargs.c
+++ b/findutils/xargs.c
@@ -426,7 +426,7 @@ int xargs_main(int argc, char **argv)
orig_arg_max -= 2048; /* POSIX.2 requires subtracting 2048 */
if (opt & OPT_UPTO_SIZE) {
- n_max_chars = bb_xgetularg10_bnd(max_chars, 1, orig_arg_max);
+ n_max_chars = xatoul_range(max_chars, 1, orig_arg_max);
for (i = 0; i < argc; i++) {
n_chars += strlen(*argv) + 1;
}
@@ -446,7 +446,7 @@ int xargs_main(int argc, char **argv)
max_chars = xmalloc(n_max_chars);
if (opt & OPT_UPTO_NUMBER) {
- n_max_arg = bb_xgetularg10_bnd(max_args, 1, INT_MAX);
+ n_max_arg = xatoul_range(max_args, 1, INT_MAX);
} else {
n_max_arg = n_max_chars;
}