From owner-freebsd-hackers@FreeBSD.ORG Thu Sep 2 11:46:55 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 1233) id 21C601065760; Thu, 2 Sep 2010 11:46:55 +0000 (UTC) Date: Thu, 2 Sep 2010 11:46:55 +0000 From: Alexander Best To: Dag-Erling =?iso-8859-15?Q?Sm=F8rgrav?= Message-ID: <20100902114655.GA9071@freebsd.org> References: <20100831180103.GA92584@freebsd.org> <86fwxt5ng1.fsf@ds4.des.no> <20100901222834.GA66517@freebsd.org> <864oe8mpga.fsf@ds4.des.no> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="gBBFr7Ir9EOA20Yy" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <864oe8mpga.fsf@ds4.des.no> Cc: freebsd-hackers@freebsd.org Subject: Re: expand_number() for fetch'es -B and -S switches X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Sep 2010 11:46:55 -0000 --gBBFr7Ir9EOA20Yy Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Thu Sep 2 10, Dag-Erling Smørgrav wrote: > Alexander Best writes: > > since you're the originator of fetch(1): should i send you a patch to add > > expand_numer() to the -B switch or do you think fetch is better off as it is > > now without humanised numbers? > > Sure, but we need to commit the expand_number() patch first. so how about something like this? the fetch(1) manual would have to be changed a bit to state that if '-B val' > 1G it silently gets set to 1G. however it might be better to simply fail in that case, since a failure will occur anyway, if val exceeds uint64_t (see expand_number(3)). cheers. alex > > > i'm not sure, but i think fetch(1) is BSD specific so no POSIX regulations need > > to be taken into consideration. but you probably know more about this matter. > > fetch(1) is 100% home-grown. > > DES > -- > Dag-Erling Smørgrav - des@des.no -- a13x --gBBFr7Ir9EOA20Yy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="fetch.diff" diff --git a/usr.bin/fetch/Makefile b/usr.bin/fetch/Makefile index 6f0db80..a21ab50 100644 --- a/usr.bin/fetch/Makefile +++ b/usr.bin/fetch/Makefile @@ -4,8 +4,8 @@ PROG= fetch CSTD?= c99 -DPADD= ${LIBFETCH} ${LIBMD} -LDADD= -lfetch -lmd +DPADD= ${LIBFETCH} ${LIBMD} ${LIBUTIL} +LDADD= -lfetch -lmd -lutil .if ${MK_OPENSSL} != "no" DPADD+= ${LIBSSL} ${LIBCRYPTO} LDADD+= -lssl -lcrypto diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c index 7553bd8..99a82b0 100644 --- a/usr.bin/fetch/fetch.c +++ b/usr.bin/fetch/fetch.c @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -48,6 +49,7 @@ __FBSDID("$FreeBSD$"); #include #define MINBUFSIZE 4096 +#define MAXBUFSIZE 1073741824 #define TIMEOUT 120 /* Option flags */ @@ -772,8 +774,9 @@ main(int argc, char *argv[]) a_flag = 1; break; case 'B': - B_size = (off_t)strtol(optarg, &end, 10); - if (*optarg == '\0' || *end != '\0') + errno = 0; + expand_number(optarg, &B_size); + if(errno) errx(1, "invalid buffer size (%s)", optarg); break; case 'b': @@ -898,6 +901,8 @@ main(int argc, char *argv[]) /* allocate buffer */ if (B_size < MINBUFSIZE) B_size = MINBUFSIZE; + if (B_size > MAXBUFSIZE) + B_size = MAXBUFSIZE; if ((buf = malloc(B_size)) == NULL) errx(1, "%s", strerror(ENOMEM)); --gBBFr7Ir9EOA20Yy--