+
+ *sysnop = -1;
+ if (ref_count)
+ {
+ unsigned int csize = 0; /* indicate compression "not performed yet" */
+ compression_method = p->compression_method;
+ switch (compression_method)
+ {
+ case REC_COMPRESS_BZIP2:
+#if HAVE_BZLIB_H
+ csize = out_offset + (out_offset >> 6) + 620;
+ rec_tmp_expand(p, csize);
+#ifdef BZ_CONFIG_ERROR
+ i = BZ2_bzBuffToBuffCompress
+#else
+ i = bzBuffToBuffCompress
+#endif
+ (p->tmp_buf+sizeof(zint)+sizeof(short)+
+ sizeof(char),
+ &csize, out_buf, out_offset, 1, 0, 30);
+ if (i != BZ_OK)
+ {
+ yaz_log(YLOG_WARN, "bzBuffToBuffCompress error code=%d", i);
+ csize = 0;
+ }
+ yaz_log(YLOG_LOG, "compress %4d %5d %5d", ref_count, out_offset,
+ csize);
+#endif
+ break;
+ case REC_COMPRESS_NONE:
+ break;
+ }
+ if (!csize)
+ {
+ /* either no compression or compression not supported ... */
+ csize = out_offset;
+ rec_tmp_expand(p, csize);
+ memcpy(p->tmp_buf + sizeof(zint) + sizeof(short) + sizeof(char),
+ out_buf, out_offset);
+ csize = out_offset;
+ compression_method = REC_COMPRESS_NONE;
+ }
+ memcpy(p->tmp_buf + sizeof(zint), &ref_count, sizeof(ref_count));
+ memcpy(p->tmp_buf + sizeof(zint)+sizeof(short),
+ &compression_method, sizeof(compression_method));
+
+ /* -------- compression */
+ rec_write_tmp_buf(p, csize + sizeof(short) + sizeof(char), sysnos);
+ }
+ xfree(out_buf);
+ xfree(sysnos);
+}
+
+static void rec_cache_flush(Records p, int saveCount)
+{
+ int i, j;
+
+ if (saveCount >= p->cache_cur)
+ saveCount = 0;
+
+ rec_write_multiple(p, saveCount);
+
+ for (i = 0; i<p->cache_cur - saveCount; i++)
+ {
+ struct record_cache_entry *e = p->record_cache + i;
+ rec_rm(&e->rec);
+ }
+ /* i still being used ... */
+ for (j = 0; j<saveCount; j++, i++)
+ memcpy(p->record_cache+j, p->record_cache+i,
+ sizeof(*p->record_cache));
+ p->cache_cur = saveCount;