From: phk Date: Tue, 8 Jan 2008 10:35:29 +0000 (+0000) Subject: Extend the str2bytes() function to also cope with percentages of a X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=908148c6208856a781ce6f8b3c141bfb6a23bd3a;p=varnish Extend the str2bytes() function to also cope with percentages of a size given as parameter. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2333 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/varnishd.c b/varnish-cache/bin/varnishd/varnishd.c index 87eb2fbf..56875c29 100644 --- a/varnish-cache/bin/varnishd/varnishd.c +++ b/varnish-cache/bin/varnishd/varnishd.c @@ -466,7 +466,7 @@ main(int argc, char *argv[]) usage(); } - q = str2bytes(l_arg, &l_size); + q = str2bytes(l_arg, &l_size, 0); if (q != NULL) { fprintf(stderr, "Parameter error:\n"); fprintf(stderr, "\t-l ...: %s\n", q); diff --git a/varnish-cache/include/libvarnish.h b/varnish-cache/include/libvarnish.h index e94176e5..0beed6d5 100644 --- a/varnish-cache/include/libvarnish.h +++ b/varnish-cache/include/libvarnish.h @@ -46,7 +46,7 @@ uint32_t crc32(uint32_t crc, const void *p1, unsigned l); uint32_t crc32_l(const void *p1, unsigned l); /* from libvarnish/num.c */ -const char *str2bytes(const char *p, uintmax_t *r); +const char *str2bytes(const char *p, uintmax_t *r, uintmax_t rel); /* from libvarnish/time.c */ void TIM_format(double t, char *p); diff --git a/varnish-cache/lib/libvarnish/num.c b/varnish-cache/lib/libvarnish/num.c index 686a4301..941aad47 100644 --- a/varnish-cache/lib/libvarnish/num.c +++ b/varnish-cache/lib/libvarnish/num.c @@ -37,7 +37,7 @@ #include const char * -str2bytes(const char *p, uintmax_t *r) +str2bytes(const char *p, uintmax_t *r, uintmax_t rel) { int i; double l; @@ -62,6 +62,13 @@ str2bytes(const char *p, uintmax_t *r) case 't': l *= ((uintmax_t)1 << 40); break; case 'p': l *= ((uintmax_t)1 << 50); break; case 'e': l *= ((uintmax_t)1 << 60); break; + case '%': + /* Percentage of 'rel' arg */ + if (rel != 0) { + l *= 1e-2 * rel; + break; + } + /*FALLTHROUGH*/ default: return ("Unknown scaling suffix [bkmgtpe] allowed"); }