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 {
unsigned char *ptr;
/* for -r option */
FILE *fi;
int fd;
unsigned char rbuf[SHMLOG_NEXTTAG + 255 + 1];
int b_opt;
......@@ -171,6 +171,7 @@ VSL_New(void)
assert(vd != NULL);
vd->regflags = REG_EXTENDED | REG_NOSUB;
vd->magic = VSL_MAGIC;
vd->fd = -1;
return (vd);
}
......@@ -192,7 +193,7 @@ VSL_OpenLog(struct VSL_data *vd, const char *varnish_name)
unsigned char *p;
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
if (vd->fi != NULL)
if (vd->fd != -1)
return (0);
if (vsl_shmem_map(varnish_name))
......@@ -203,7 +204,7 @@ VSL_OpenLog(struct VSL_data *vd, const char *varnish_name)
vd->logend = vd->logstart + vsl_lh->size;
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; )
p += SHMLOG_LEN(p) + SHMLOG_NEXTTAG;
vd->ptr = p;
......@@ -232,13 +233,13 @@ vsl_nextlog(struct VSL_data *vd, unsigned char **pp)
int i;
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
if (vd->fi != NULL) {
i = fread(vd->rbuf, SHMLOG_DATA, 1, vd->fi);
if (i != 1)
if (vd->fd != -1) {
i = read(vd->fd, vd->rbuf, SHMLOG_DATA);
if (i != SHMLOG_DATA)
return (-1);
i = fread(vd->rbuf + SHMLOG_DATA,
SHMLOG_LEN(vd->rbuf) + 1, 1, vd->fi);
if (i != 1)
i = read(vd->fd, vd->rbuf + SHMLOG_DATA,
SHMLOG_LEN(vd->rbuf) + 1);
if (i != SHMLOG_LEN(vd->rbuf) + 1)
return (-1);
*pp = vd->rbuf;
return (1);
......@@ -394,13 +395,14 @@ vsl_r_arg(struct VSL_data *vd, const char *opt)
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
if (!strcmp(opt, "-"))
vd->fi = stdin;
vd->fd = STDIN_FILENO;
else
vd->fi = fopen(opt, "r");
if (vd->fi != NULL)
return (1);
vd->fd = open(opt, O_RDONLY);
if (vd->fd < 0) {
perror(opt);
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