From: des Date: Mon, 30 Jun 2008 02:03:58 +0000 (+0000) Subject: Convert from FILE * to fd. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f633516dce7675ec5494a365c526b66ed76a0092;p=varnish Convert from FILE * to fd. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2863 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/lib/libvarnishapi/shmlog.c b/varnish-cache/lib/libvarnishapi/shmlog.c index ef17080b..c0de0598 100644 --- a/varnish-cache/lib/libvarnishapi/shmlog.c +++ b/varnish-cache/lib/libvarnishapi/shmlog.c @@ -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); - perror(opt); - return (-1); + vd->fd = open(opt, O_RDONLY); + if (vd->fd < 0) { + perror(opt); + return (-1); + } + return (1); } /*--------------------------------------------------------------------*/