34 #include <sys/types.h>
36 #include <yaz/snprintf.h>
46 static 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)
260 info->pos_border = mrfd->
pos_cur +
262 if (info->pos_border > info->pos_end)
263 info->pos_border = info->pos_end;
264 count = info->pos_border - info->pos_buf;
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);
284 info->pos_border = info->pos_end;
294 if (mrfd->
pos_cur < info->pos_buf || nc > info->pos_border)
296 if (nc > info->pos_end)
302 memcpy(buf, info->buf_mem + (mrfd->
pos_cur - info->pos_buf),
319 if (nc > info->pos_buf + info->buf_size)
323 if (info->pos_buf < info->pos_end)
327 memcpy(info->buf_mem + (mrfd->
pos_cur - info->pos_buf), buf,
330 if (nc > info->pos_end)
331 info->pos_border = info->pos_end = nc;
336 static void r_pos(
RSFD rfd,
double *current,
double *total)
341 *current = (double) mrfd->
cur;
342 *total = (
double) info->hits;
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.
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 const struct rset_control control
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 int log_level_initialized
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)