]> err.no Git - varnish/commitdiff
Extend the str2bytes() function to also cope with percentages of a
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 8 Jan 2008 10:35:29 +0000 (10:35 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 8 Jan 2008 10:35:29 +0000 (10:35 +0000)
size given as parameter.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2333 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/varnishd.c
varnish-cache/include/libvarnish.h
varnish-cache/lib/libvarnish/num.c

index 87eb2fbf05c8a7c1dc2c6d8fbdcab9bde9a8c63c..56875c2969ce2208ea431d94f3949f95a8254747 100644 (file)
@@ -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);
index e94176e56bd986a47fbda3d5d8413f2f6f8ae492..0beed6d5b0511b7bdbe1a27619af349723076655 100644 (file)
@@ -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);
index 686a4301cba3b8085b46c150036a6270d8e22bde..941aad4785de1bacdb0f822908adeff51c89327b 100644 (file)
@@ -37,7 +37,7 @@
 #include <libvarnish.h>
 
 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");
                }