Commit fc19b37e authored by Dag Erling Smørgrav's avatar Dag Erling Smørgrav

Convert from FILE * to fd.


git-svn-id: http://www.varnish-cache.org/svn/trunk@2863 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 06842574
...@@ -65,7 +65,7 @@ struct VSL_data { ...@@ -65,7 +65,7 @@ struct VSL_data {
unsigned char *ptr; unsigned char *ptr;
/* for -r option */ /* for -r option */
FILE *fi; int fd;
unsigned char rbuf[SHMLOG_NEXTTAG + 255 + 1]; unsigned char rbuf[SHMLOG_NEXTTAG + 255 + 1];
int b_opt; int b_opt;
...@@ -171,6 +171,7 @@ VSL_New(void) ...@@ -171,6 +171,7 @@ VSL_New(void)
assert(vd != NULL); assert(vd != NULL);
vd->regflags = REG_EXTENDED | REG_NOSUB; vd->regflags = REG_EXTENDED | REG_NOSUB;
vd->magic = VSL_MAGIC; vd->magic = VSL_MAGIC;
vd->fd = -1;
return (vd); return (vd);
} }
...@@ -192,7 +193,7 @@ VSL_OpenLog(struct VSL_data *vd, const char *varnish_name) ...@@ -192,7 +193,7 @@ VSL_OpenLog(struct VSL_data *vd, const char *varnish_name)
unsigned char *p; unsigned char *p;
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
if (vd->fi != NULL) if (vd->fd != -1)
return (0); return (0);
if (vsl_shmem_map(varnish_name)) if (vsl_shmem_map(varnish_name))
...@@ -203,7 +204,7 @@ VSL_OpenLog(struct VSL_data *vd, const char *varnish_name) ...@@ -203,7 +204,7 @@ VSL_OpenLog(struct VSL_data *vd, const char *varnish_name)
vd->logend = vd->logstart + vsl_lh->size; vd->logend = vd->logstart + vsl_lh->size;
vd->ptr = vd->logstart; vd->ptr = vd->logstart;
if (!vd->d_opt && vd->fi == NULL) { if (!vd->d_opt && vd->fd == -1) {
for (p = vd->ptr; *p != SLT_ENDMARKER; ) for (p = vd->ptr; *p != SLT_ENDMARKER; )
p += SHMLOG_LEN(p) + SHMLOG_NEXTTAG; p += SHMLOG_LEN(p) + SHMLOG_NEXTTAG;
vd->ptr = p; vd->ptr = p;
...@@ -232,13 +233,13 @@ vsl_nextlog(struct VSL_data *vd, unsigned char **pp) ...@@ -232,13 +233,13 @@ vsl_nextlog(struct VSL_data *vd, unsigned char **pp)
int i; int i;
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
if (vd->fi != NULL) { if (vd->fd != -1) {
i = fread(vd->rbuf, SHMLOG_DATA, 1, vd->fi); i = read(vd->fd, vd->rbuf, SHMLOG_DATA);
if (i != 1) if (i != SHMLOG_DATA)
return (-1); return (-1);
i = fread(vd->rbuf + SHMLOG_DATA, i = read(vd->fd, vd->rbuf + SHMLOG_DATA,
SHMLOG_LEN(vd->rbuf) + 1, 1, vd->fi); SHMLOG_LEN(vd->rbuf) + 1);
if (i != 1) if (i != SHMLOG_LEN(vd->rbuf) + 1)
return (-1); return (-1);
*pp = vd->rbuf; *pp = vd->rbuf;
return (1); return (1);
...@@ -394,13 +395,14 @@ vsl_r_arg(struct VSL_data *vd, const char *opt) ...@@ -394,13 +395,14 @@ vsl_r_arg(struct VSL_data *vd, const char *opt)
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
if (!strcmp(opt, "-")) if (!strcmp(opt, "-"))
vd->fi = stdin; vd->fd = STDIN_FILENO;
else else
vd->fi = fopen(opt, "r"); vd->fd = open(opt, O_RDONLY);
if (vd->fi != NULL) if (vd->fd < 0) {
return (1);
perror(opt); perror(opt);
return (-1); return (-1);
}
return (1);
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment