From: phk Date: Mon, 25 Jun 2007 20:44:06 +0000 (+0000) Subject: Make it possible to pass a filedescriptor to VCC_CompileFile() if the file X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1bdb0e8013f6fcd7edf9108cdac576b4ac5e746c;p=varnish Make it possible to pass a filedescriptor to VCC_CompileFile() if the file is already open. The filedescriptor will be closed. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1571 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/mgt_vcc.c b/varnish-cache/bin/varnishd/mgt_vcc.c index b8deb024..ad10083a 100644 --- a/varnish-cache/bin/varnishd/mgt_vcc.c +++ b/varnish-cache/bin/varnishd/mgt_vcc.c @@ -258,7 +258,7 @@ mgt_VccCompileFile(struct vsb *sb, const char *fn, int C_flag) { char *csrc, *vf = NULL; - csrc = VCC_CompileFile(sb, fn); + csrc = VCC_CompileFile(sb, fn, -1); if (csrc != NULL) { if (C_flag) fputs(csrc, stdout); diff --git a/varnish-cache/include/libvcl.h b/varnish-cache/include/libvcl.h index 0ba8951d..070f2ec2 100644 --- a/varnish-cache/include/libvcl.h +++ b/varnish-cache/include/libvcl.h @@ -30,7 +30,7 @@ */ char *VCC_Compile(struct vsb *sb, const char *b, const char *e); -char *VCC_CompileFile(struct vsb *sb, const char *fn); +char *VCC_CompileFile(struct vsb *sb, const char *fn, int fd); void VCC_InitCompile(const char *default_vcl); diff --git a/varnish-cache/lib/libvcl/vcc_compile.c b/varnish-cache/lib/libvcl/vcc_compile.c index 14fe8e81..e2daa613 100644 --- a/varnish-cache/lib/libvcl/vcc_compile.c +++ b/varnish-cache/lib/libvcl/vcc_compile.c @@ -377,17 +377,19 @@ vcc_destroy_source(struct source *sp) /*--------------------------------------------------------------------*/ static struct source * -vcc_file_source(struct vsb *sb, const char *fn) +vcc_file_source(struct vsb *sb, const char *fn, int fd) { char *f; - int fd, i; + int i; struct stat st; - fd = open(fn, O_RDONLY); if (fd < 0) { - vsb_printf(sb, "Cannot open file '%s': %s\n", - fn, strerror(errno)); - return (NULL); + fd = open(fn, O_RDONLY); + if (fd < 0) { + vsb_printf(sb, "Cannot open file '%s': %s\n", + fn, strerror(errno)); + return (NULL); + } } assert(0 == fstat(fd, &st)); f = malloc(st.st_size + 1); @@ -429,7 +431,7 @@ vcc_resolve_includes(struct tokenlist *tl) } assert(t2 != NULL); - sp = vcc_file_source(tl->sb, t1->dec); + sp = vcc_file_source(tl->sb, t1->dec, -1); if (sp == NULL) { vcc_ErrWhere(tl, t1); return; @@ -653,12 +655,12 @@ VCC_Compile(struct vsb *sb, const char *b, const char *e) */ char * -VCC_CompileFile(struct vsb *sb, const char *fn) +VCC_CompileFile(struct vsb *sb, const char *fn, int fd) { struct source *sp; char *r; - sp = vcc_file_source(sb, fn); + sp = vcc_file_source(sb, fn, fd); if (sp == NULL) return (NULL); r = vcc_CompileSource(sb, sp);