From a5e3d2bb45647da1c787a35ff2d1dceb233f7262 Mon Sep 17 00:00:00 2001 From: des Date: Tue, 4 Apr 2006 07:24:07 +0000 Subject: [PATCH] Portability tweaks: use our own sbuf.h and queue.h; get rid of __DECONST; get 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 | 3 +- varnish-cache/include/cli_priv.h | 2 +- varnish-cache/include/libvarnish.h | 5 ++- varnish-cache/lib/libvarnish/argv.c | 26 +++++++------- varnish-cache/lib/libvarnish/cli.c | 4 +-- varnish-cache/lib/libvcl/vcl_compile.c | 39 +++++++++++---------- 6 files changed, 39 insertions(+), 40 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_acceptor.c b/varnish-cache/bin/varnishd/cache_acceptor.c index 48a19a5b..c613b405 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.c +++ b/varnish-cache/bin/varnishd/cache_acceptor.c @@ -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 diff --git a/varnish-cache/include/cli_priv.h b/varnish-cache/include/cli_priv.h index 841b3d4f..24bb76d5 100644 --- a/varnish-cache/include/cli_priv.h +++ b/varnish-cache/include/cli_priv.h @@ -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 */ diff --git a/varnish-cache/include/libvarnish.h b/varnish-cache/include/libvarnish.h index 4ce0313e..8c332a2b 100644 --- a/varnish-cache/include/libvarnish.h +++ b/varnish-cache/include/libvarnish.h @@ -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) - diff --git a/varnish-cache/lib/libvarnish/argv.c b/varnish-cache/lib/libvarnish/argv.c index 98c3a120..50e31c68 100644 --- a/varnish-cache/lib/libvarnish/argv.c +++ b/varnish-cache/lib/libvarnish/argv.c @@ -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); } diff --git a/varnish-cache/lib/libvarnish/cli.c b/varnish-cache/lib/libvarnish/cli.c index 1e665303..4e75acf0 100644 --- a/varnish-cache/lib/libvarnish/cli.c +++ b/varnish-cache/lib/libvarnish/cli.c @@ -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; diff --git a/varnish-cache/lib/libvcl/vcl_compile.c b/varnish-cache/lib/libvcl/vcl_compile.c index 738b3275..f10301ab 100644 --- a/varnish-cache/lib/libvcl/vcl_compile.c +++ b/varnish-cache/lib/libvcl/vcl_compile.c @@ -33,21 +33,21 @@ * and all the rest... */ +#include +#include +#include + #include -#include #include -#include -#include #include +#include +#include +#include #include #include -#include -#include -#include - -#include -#include -#include +#include +#include +#include #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); -- 2.39.5