r3621 - in branches/2.0/varnish-cache: include lib/libvarnish lib/libvcl
tfheen at projects.linpro.no
tfheen at projects.linpro.no
Thu Feb 5 13:19:36 CET 2009
Author: tfheen
Date: 2009-02-05 13:19:35 +0100 (Thu, 05 Feb 2009)
New Revision: 3621
Modified:
branches/2.0/varnish-cache/include/libvarnish.h
branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c
branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c
Log:
Merge r3414: Add a vreadfile() utility function, which reads a file into malloc'ed memory
Modified: branches/2.0/varnish-cache/include/libvarnish.h
===================================================================
--- branches/2.0/varnish-cache/include/libvarnish.h 2009-02-05 12:14:59 UTC (rev 3620)
+++ branches/2.0/varnish-cache/include/libvarnish.h 2009-02-05 12:19:35 UTC (rev 3621)
@@ -86,6 +86,7 @@
/* from libvarnish/vtmpfile.c */
int vtmpfile(char *);
+char *vreadfile(int fd);
/*
* assert(), AN() and AZ() are static checks that should not happen.
Modified: branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c
===================================================================
--- branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c 2009-02-05 12:14:59 UTC (rev 3620)
+++ branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c 2009-02-05 12:19:35 UTC (rev 3621)
@@ -35,7 +35,10 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
#include "libvarnish.h"
int
@@ -74,3 +77,21 @@
}
/* not reached */
}
+
+char *
+vreadfile(int fd)
+{
+ struct stat st;
+ char *f;
+ int i;
+
+ assert(0 == fstat(fd, &st));
+ if (!S_ISREG(st.st_mode))
+ return (NULL);
+ f = malloc(st.st_size + 1);
+ assert(f != NULL);
+ i = read(fd, f, st.st_size);
+ assert(i == st.st_size);
+ f[i] = '\0';
+ return (f);
+}
Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c
===================================================================
--- branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-05 12:14:59 UTC (rev 3620)
+++ branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-05 12:19:35 UTC (rev 3621)
@@ -402,8 +402,6 @@
vcc_file_source(struct vsb *sb, const char *fn, int fd)
{
char *f;
- int i;
- struct stat st;
struct source *sp;
if (fd < 0) {
@@ -414,19 +412,10 @@
return (NULL);
}
}
- assert(0 == fstat(fd, &st));
- if (! S_ISREG(st.st_mode)) {
- vsb_printf(sb, "File '%s' is not a regular file\n", fn);
- AZ(close(fd));
- return (NULL);
- }
- f = malloc(st.st_size + 1);
- assert(f != NULL);
- i = read(fd, f, st.st_size);
- assert(i == st.st_size);
+ f = vreadfile(fd);
+ AN(f);
AZ(close(fd));
- f[i] = '\0';
- sp = vcc_new_source(f, f + i, fn);
+ sp = vcc_new_source(f, NULL, fn);
sp->freeit = f;
return (sp);
}
More information about the varnish-commit
mailing list