+ memcpy (src, &nextpos, sizeof(nextpos));
+ memcpy (src + sizeof(nextpos), &size, sizeof(size));
+ return isamc_write_block (is, cat, pos, src);
+}
+
+#if ISAMC_FREELIST_CHUNK
+static void flush_block (ISAMC is, int cat)
+{
+ char *abuf = is->files[cat].alloc_buf;
+ zint block = is->files[cat].head.freelist;
+ if (block && is->files[cat].alloc_entries_num)
+ {
+ memcpy (abuf, &is->files[cat].alloc_entries_num, sizeof(block));
+ bf_write (is->files[cat].bf, block, 0, 0, abuf);
+ is->files[cat].alloc_entries_num = 0;
+ }
+}
+
+static zint alloc_block (ISAMC is, int cat)
+{
+ zint block = is->files[cat].head.freelist;
+ char *abuf = is->files[cat].alloc_buf;
+
+ (is->files[cat].no_allocated)++;
+
+ if (!block)
+ {
+ block = (is->files[cat].head.lastblock)++; /* no free list */
+ is->files[cat].head_is_dirty = 1;
+ }
+ else
+ {
+ if (!is->files[cat].alloc_entries_num) /* read first time */
+ {
+ bf_read (is->files[cat].bf, block, 0, 0, abuf);
+ memcpy (&is->files[cat].alloc_entries_num, abuf,
+ sizeof(is->files[cat].alloc_entries_num));
+ assert (is->files[cat].alloc_entries_num > 0);
+ }
+ /* have some free blocks now */
+ assert (is->files[cat].alloc_entries_num > 0);
+ is->files[cat].alloc_entries_num--;
+ if (!is->files[cat].alloc_entries_num) /* last one in block? */
+ {
+ memcpy (&is->files[cat].head.freelist, abuf + sizeof(int),
+ sizeof(zint));
+ is->files[cat].head_is_dirty = 1;
+
+ if (is->files[cat].head.freelist)
+ {
+ bf_read (is->files[cat].bf, is->files[cat].head.freelist,
+ 0, 0, abuf);
+ memcpy (&is->files[cat].alloc_entries_num, abuf,
+ sizeof(is->files[cat].alloc_entries_num));
+ assert (is->files[cat].alloc_entries_num);
+ }
+ }
+ else
+ memcpy (&block, abuf + sizeof(zint) + sizeof(int) *
+ is->files[cat].alloc_entries_num, sizeof(zint));
+ }
+ return block;