unsigned char *ptr;
/* for -r option */
- FILE *fi;
+ int fd;
unsigned char rbuf[SHMLOG_NEXTTAG + 255 + 1];
int b_opt;
assert(vd != NULL);
vd->regflags = REG_EXTENDED | REG_NOSUB;
vd->magic = VSL_MAGIC;
+ vd->fd = -1;
return (vd);
}
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))
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;
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);
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);
- perror(opt);
- return (-1);
+ vd->fd = open(opt, O_RDONLY);
+ if (vd->fd < 0) {
+ perror(opt);
+ return (-1);
+ }
+ return (1);
}
/*--------------------------------------------------------------------*/