Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 Nov 2013 08:57:21 +0000 (UTC)
From:      Eitan Adler <eadler@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r257884 - head/usr.bin/split
Message-ID:  <201311090857.rA98vLVM092525@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Sat Nov  9 08:57:21 2013
New Revision: 257884
URL: http://svnweb.freebsd.org/changeset/base/257884

Log:
  Change manual string conversion to expand_number
  
  Reviewed by:	adrian

Modified:
  head/usr.bin/split/Makefile
  head/usr.bin/split/split.c

Modified: head/usr.bin/split/Makefile
==============================================================================
--- head/usr.bin/split/Makefile	Sat Nov  9 08:27:55 2013	(r257883)
+++ head/usr.bin/split/Makefile	Sat Nov  9 08:57:21 2013	(r257884)
@@ -2,5 +2,6 @@
 # $FreeBSD$
 
 PROG=	split
+LDADD=	-lutil
 
 .include <bsd.prog.mk>

Modified: head/usr.bin/split/split.c
==============================================================================
--- head/usr.bin/split/split.c	Sat Nov  9 08:27:55 2013	(r257883)
+++ head/usr.bin/split/split.c	Sat Nov  9 08:57:21 2013	(r257884)
@@ -49,6 +49,7 @@ static const char sccsid[] = "@(#)split.
 #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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201311090857.rA98vLVM092525>