Date: Thu, 2 Sep 2010 11:46:55 +0000 From: Alexander Best <arundel@freebsd.org> To: Dag-Erling =?iso-8859-15?Q?Sm=F8rgrav?= <des@des.no> Cc: freebsd-hackers@freebsd.org Subject: Re: expand_number() for fetch'es -B and -S switches Message-ID: <20100902114655.GA9071@freebsd.org> In-Reply-To: <864oe8mpga.fsf@ds4.des.no> References: <20100831180103.GA92584@freebsd.org> <86fwxt5ng1.fsf@ds4.des.no> <20100901222834.GA66517@freebsd.org> <864oe8mpga.fsf@ds4.des.no>
next in thread | previous in thread | raw e-mail | index | archive | help
--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 <arundel@freebsd.org> 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 <ctype.h> #include <err.h> #include <errno.h> +#include <libutil.h> #include <signal.h> #include <stdint.h> #include <stdio.h> @@ -48,6 +49,7 @@ __FBSDID("$FreeBSD$"); #include <fetch.h> #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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100902114655.GA9071>