diff options
author | eadler <eadler@FreeBSD.org> | 2013-11-09 08:57:21 +0000 |
---|---|---|
committer | eadler <eadler@FreeBSD.org> | 2013-11-09 08:57:21 +0000 |
commit | c56ee6b0c20eaf721c4b2493222552adb193f8c8 (patch) | |
tree | 6b901212fae8c1a3a6a9e42f25cc2a78c9c657b6 | |
parent | 649c12d2d7aba75a53b8ba712a17f07a99c9c2a8 (diff) | |
download | FreeBSD-src-c56ee6b0c20eaf721c4b2493222552adb193f8c8.zip FreeBSD-src-c56ee6b0c20eaf721c4b2493222552adb193f8c8.tar.gz |
Change manual string conversion to expand_number
Reviewed by: adrian
-rw-r--r-- | usr.bin/split/Makefile | 1 | ||||
-rw-r--r-- | usr.bin/split/split.c | 20 |
2 files changed, 5 insertions, 16 deletions
diff --git a/usr.bin/split/Makefile b/usr.bin/split/Makefile index d176fdd..cf23990 100644 --- a/usr.bin/split/Makefile +++ b/usr.bin/split/Makefile @@ -2,5 +2,6 @@ # $FreeBSD$ PROG= split +LDADD= -lutil .include <bsd.prog.mk> diff --git a/usr.bin/split/split.c b/usr.bin/split/split.c index 572af59..9a0b0ec 100644 --- a/usr.bin/split/split.c +++ b/usr.bin/split/split.c @@ -49,6 +49,7 @@ static const char sccsid[] = "@(#)split.c 8.2 (Berkeley) 4/16/94"; #include <errno.h> #include <fcntl.h> #include <inttypes.h> +#include <libutil.h> #include <limits.h> #include <locale.h> #include <stdbool.h> @@ -83,9 +84,8 @@ static void usage(void); int main(int argc, char **argv) { - intmax_t bytecnti; - long scale; int ch; + int error; char *ep, *p; setlocale(LC_ALL, ""); @@ -118,21 +118,9 @@ main(int argc, char **argv) break; case 'b': /* Byte count. */ errno = 0; - if ((bytecnti = strtoimax(optarg, &ep, 10)) <= 0 || - strchr("kKmMgG", *ep) == NULL || errno != 0) - errx(EX_USAGE, - "%s: illegal byte count", optarg); - if (*ep == 'k' || *ep == 'K') - scale = 1024; - else if (*ep == 'm' || *ep == 'M') - scale = 1024 * 1024; - else if (*ep == 'g' || *ep == 'G') - scale = 1024 * 1024 * 1024; - else - scale = 1; - if (bytecnti > OFF_MAX / scale) + error = expand_number(optarg, &bytecnt); + if (error == -1) errx(EX_USAGE, "%s: offset too large", optarg); - bytecnt = (off_t)(bytecnti * scale); break; case 'd': /* Decimal suffix */ dflag = true; |