]> err.no Git - varnish/commitdiff
Portability tweaks: use our own sbuf.h and queue.h; get rid of __DECONST; get
authordes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 4 Apr 2006 07:24:07 +0000 (07:24 +0000)
committerdes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 4 Apr 2006 07:24:07 +0000 (07:24 +0000)
rid of digittoint() (which is pointless since ISO C guarantees that digits
are consecutive in the execution character set); get rid of __unused.

Also fix a buglet in argv.c's BackSlash() (parsing of octal numbers), and
constify the array passed around by ParseArgv() and FreeArgv().

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

varnish-cache/bin/varnishd/cache_acceptor.c
varnish-cache/include/cli_priv.h
varnish-cache/include/libvarnish.h
varnish-cache/lib/libvarnish/argv.c
varnish-cache/lib/libvarnish/cli.c
varnish-cache/lib/libvcl/vcl_compile.c

index 48a19a5b95245a5a3957d4e1fcffabd84ffdb2a6..c613b405ba66b05572b525836ffa91ae76ad9273 100644 (file)
@@ -69,7 +69,7 @@ http_read_f(int fd, short event, void *arg)
 }
 
 static void
-accept_f(int fd, short event, void *arg __unused)
+accept_f(int fd, short event, void *arg)
 {
        socklen_t l;
        struct sessmem *sm;
@@ -77,6 +77,7 @@ accept_f(int fd, short event, void *arg __unused)
        struct sess *sp;
        char port[10];
 
+       (void)arg;
        sm = calloc(sizeof *sm, 1);
        assert(sm != NULL);     /*
                                 * XXX: this is probably one we should handle
index 841b3d4f3a9e718c87af3a0f4d58247dca0bdfb3..24bb76d544bb98c1fc4b8e46064c88a34afe2c2d 100644 (file)
@@ -11,7 +11,7 @@
 
 struct cli;    /* NB: struct cli is opaque at this level.  */
 
-typedef void cli_func_t(struct cli*, char **av, void *priv);
+typedef void cli_func_t(struct cli*, const char **av, void *priv);
 
 struct cli_proto {
        /* These must match the CLI_* macros in cli.h */
index 4ce0313e5166b122e15f1f9767728a0f8df27da0..8c332a2b5396b577eee33b59efab6c5fe166e45e 100644 (file)
@@ -3,10 +3,9 @@
  */
 
 /* from libvarnish/argv.c */
-void FreeArgv(char **argv);
-char **ParseArgv(const char *s, int comment);
+void FreeArgv(const char **argv);
+const char **ParseArgv(const char *s, int comment);
 
 
 /* Assert zero return value */
 #define AZ(foo)        do { assert((foo) == 0); } while (0)
-
index 98c3a120adfeeaf944b131781b4aebd91b68f4bc..50e31c681f42ec8d9ce3f722c7843b017145112e 100644 (file)
@@ -1,12 +1,12 @@
 /*
  * $Id$
  *
- * char **ParseArgv(const char *s, int comment)
+ * const char **ParseArgv(const char *s, int comment)
  *     Parse a command like line into an argv[]
  *     Index zero contains NULL or an error message
  *     "double quotes" and backslash substitution is handled.
  *
- * void FreeArgv(char **argv)
+ * void FreeArgv(const char **argv)
  *     Free the result of ParseArgv()
  *
  */
@@ -48,15 +48,15 @@ BackSlash(const char *s, int *res)
                i = '\\';
                r = 2;
                break;
-       case '0': case '1': case '2': case 3:
-       case '4': case '5': case '6': case 7:
+       case '0': case '1': case '2': case '3':
+       case '4': case '5': case '6': case '7':
                for (r = 1; r < 4; r++) {
                        if (!isdigit(s[r]))
                                break;
-                       if (digittoint(s[r]) > 7)
+                       if (s[r] - '0' > 7)
                                break;
                        i <<= 3;
-                       i |= digittoint(s[r]);
+                       i |= s[r] - '0';
                }
                break;
        case 'x':
@@ -96,10 +96,10 @@ BackSlashDecode(const char *s, const char *e)
        return (p);
 }
 
-char **
+const char **
 ParseArgv(const char *s, int comment)
 {
-       char **argv;
+       const char **argv;
        const char *p;
        int nargv, largv;
        int i, quote;
@@ -131,8 +131,7 @@ ParseArgv(const char *s, int comment)
                        if (*s == '\\') {
                                i = BackSlash(s, NULL);
                                if (i == 0) {
-                                       argv[0] = __DECONST(void *,
-                                           "Illegal backslash sequence");
+                                       argv[0] = "Illegal backslash sequence";
                                        return (argv);
                                }
                                s += i;
@@ -147,8 +146,7 @@ ParseArgv(const char *s, int comment)
                        if (*s == '"')
                                break;
                        if (*s == '\0') {
-                               argv[0] = __DECONST(void *,
-                                   "Missing '\"'");
+                               argv[0] = "Missing '\"'";
                                return (argv);
                        }
                        s++;
@@ -166,12 +164,12 @@ ParseArgv(const char *s, int comment)
 }
 
 void
-FreeArgv(char **argv)
+FreeArgv(const char **argv)
 {
        int i;
        
        for (i = 1; argv[i] != NULL; i++)
-               free(argv[i]);
+               free((void *)(uintptr_t)argv[i]);
        free(argv);
 }
 
index 1e6653031f042444bd10952569a7a6aee04f8c79..4e75acf02f87145ec9c58b19c91ccffc920598da 100644 (file)
@@ -19,7 +19,7 @@
  */
 
 void
-cli_func_help(struct cli *cli, char **av, void *priv)
+cli_func_help(struct cli *cli, const char **av, void *priv)
 {
        struct cli_proto *cp;
 
@@ -41,7 +41,7 @@ cli_func_help(struct cli *cli, char **av, void *priv)
 void
 cli_dispatch(struct cli *cli, struct cli_proto *clp, const char *line)
 {
-       char **av;
+       const char **av;
        unsigned u;
        struct cli_proto *cp;
 
index 738b327570eee10af243d2d9adc39b3b680e5581..f10301ab8bd1bf6debd427a5f93f4cb729e26f49 100644 (file)
  *     and all the rest...
  */
 
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+
 #include <assert.h>
-#include <string.h>
 #include <ctype.h>
-#include <unistd.h>
-#include <fcntl.h>
 #include <errno.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <sbuf.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/sbuf.h>
-#include <sys/stat.h>
-#include <sys/queue.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
+#include <string.h>
+#include <queue.h>
+#include <unistd.h>
 
 #include "vcl_priv.h"
 
@@ -316,15 +316,15 @@ EncString(struct token *t)
                case 'b':       *q++ = '\b';    r += 2; break;
                case '0': case '1': case '2': case '3':
                case '4': case '5': case '6': case '7':
-                       u = digittoint(r[1]);
+                       u = r[1] - '0';
                        r += 2;
-                       if (isdigit(r[0]) && digittoint(r[0]) < 8) {
+                       if (isdigit(r[0]) && (r[0] - '0') < 8) {
                                u <<= 3;
-                               u |= digittoint(r[0]);
+                               u |= r[0] - '0';
                                r++;
-                               if (isdigit(r[0]) && digittoint(r[0]) < 8) {
+                               if (isdigit(r[0]) && (r[0] - '0') < 8) {
                                        u <<= 3;
-                                       u |= digittoint(r[0]);
+                                       u |= r[0] - '0';
                                        r++;
                                }
                        }
@@ -471,7 +471,7 @@ UintVal(struct tokenlist *tl)
        Expect(tl, CNUM);
        for (p = tl->t->b; p < tl->t->e; p++) {
                d *= 10;
-               d += digittoint(*p);
+               d += *p - '0';
        }
        NextToken(tl);
        return (d);
@@ -490,7 +490,7 @@ DoubleVal(struct tokenlist *tl)
        Expect(tl, CNUM);
        for (p = tl->t->b; p < tl->t->e; p++) {
                d *= 10;
-               d += digittoint(*p);
+               d += *p - '0';
        }
        NextToken(tl);
        if (tl->t->tok != '.') 
@@ -499,7 +499,7 @@ DoubleVal(struct tokenlist *tl)
        if (tl->t->tok != CNUM)
                return (d);
        for (p = tl->t->b; p < tl->t->e; p++) {
-               d += digittoint(*p) * e;
+               d += (*p - '0') * e;
                e *= 0.1;
        }
        NextToken(tl);
@@ -645,9 +645,10 @@ Cond_Ip(struct var *vp, struct tokenlist *tl)
 }
 
 static void
-Cond_String(struct var *vp __unused, struct tokenlist *tl)
+Cond_String(struct var *vp, struct tokenlist *tl)
 {
 
+       (void)vp;
        switch (tl->t->tok) {
        case '~':
                I(tl); sbuf_printf(tl->fc, "string_match(%s, ", vp->cname);