36#include <yaz/snprintf.h>
46static void r_pos(
RSFD rfd,
double *current,
double *total);
94 log_level = yaz_log_module_level(
"rstemp");
133 if (info->
fd == -1 && info->
fname)
141 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"rstemp: open failed %s", info->
fname);
149 rfd->
priv = (
void *)prfd;
169 if (!info->
fname && mk)
175 yaz_snprintf(
template,
sizeof(
template) - 80,
178 strcpy(
template,
"");
179 strcat(
template,
"zrs_");
181 yaz_snprintf(
template + strlen(
template), 40,
"%ld_", (
long) getpid());
183 strcat(
template,
"XXXXXX");
185 info->
fd = mkstemp(
template);
188 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"rstemp: mkstemp %s",
template);
193 char *s = (
char*) tempnam(info->
temp_path,
"zrs");
195 yaz_log(
log_level,
"creating tempfile %s", s);
196 info->
fd = open(s,
O_BINARY|O_RDWR|O_CREAT, 0666);
199 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"rstemp: open %s", s);
210 if (lseek(info->
fd, info->
pos_buf, SEEK_SET) == -1)
212 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"rstemp: lseek (1) %s", info->
fname);
218 if ((r = write(info->
fd, info->
buf_mem, count)) < (
int) count)
221 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"rstemp: write %s", info->
fname);
223 yaz_log(YLOG_FATAL,
"rstemp: write of %ld but got %ld",
224 (
long) count, (
long) r);
237 if (info->
fname && info->
fd != -1)
267 if (lseek(info->
fd, info->
pos_buf, SEEK_SET) == -1)
269 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"rstemp: lseek (2) %s fd=%d", info->
fname, info->
fd);
272 if ((r = read(info->
fd, info->
buf_mem, count)) < (
int) count)
275 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"rstemp: read %s", info->
fname);
277 yaz_log(YLOG_FATAL,
"read of %ld but got %ld",
278 (
long) count, (
long) r);
336static void r_pos(
RSFD rfd,
double *current,
double *total)
341 *current = (double) mrfd->
cur;
342 *total = (double) info->
hits;
static const struct rset_control control
static int r_read(RSFD rfd, void *buf, TERMID *term)
static void r_delete(RSET ct)
static void r_pos(RSFD rfd, double *current, double *total)
static int log_level_initialized
static RSFD r_open(RSET ct, int flag)
static void r_close(RSFD rfd)
int rfd_is_last(RSFD rfd)
Test for last use of RFD.
RSET rset_create_base(const struct rset_control *sel, NMEM nmem, struct rset_key_control *kcontrol, int scope, TERMID term, int no_children, RSET *children)
Common constuctor for RSETs.
struct rset_term * TERMID
RSFD rfd_create_base(RSET rs)
Common constuctor for RFDs.
void rset_get_one_term(RSET ct, TERMID *terms, int maxterms, int *curterm)
is a getterms function for those that don't have any
static int r_write(RSFD rfd, const void *buf)
static int r_read(RSFD rfd, void *buf, TERMID *term)
static void r_delete(RSET ct)
static void r_flush(RSFD rfd, int mk)
static void r_reread(RSFD rfd)
RSET rset_create_temp(NMEM nmem, struct rset_key_control *kcontrol, int scope, const char *temp_path, TERMID term)
static void r_pos(RSFD rfd, double *current, double *total)
static RSFD r_open(RSET ct, int flag)
static void r_close(RSFD rfd)
struct rset_key_control * keycontrol
void zebra_exit(const char *msg)