+static int r_forward_or(RSFD rfd, void *buf,
+ TERMID *term, const void *untilbuf)
+{ /* while heap head behind untilbuf, forward it and rebalance heap */
+ struct rfd_private *p = rfd->priv;
+ const struct rset_key_control *kctrl = rfd->rset->keycontrol;
+ if (heap_empty(p->h))
+ return 0;
+ while ( (*kctrl->cmp)(p->h->heap[1]->buf,untilbuf) < -rfd->rset->scope )
+ {
+ if (rset_forward(p->h->heap[1]->fd,p->h->heap[1]->buf,
+ &p->h->heap[1]->term, untilbuf))
+ heap_balance(p->h);
+ else
+ {
+ heap_delete(p->h);
+ if (heap_empty(p->h))
+ return 0;
+ }
+
+ }
+ return r_read_or(rfd, buf, term);
+}
+
+
+static int r_read_or (RSFD rfd, void *buf, TERMID *term)