+#include <string.h>
+#include <assert.h>
+#ifdef WIN32
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+#include <zebrautl.h>
+#include <bfile.h>
+
+#include "cfile.h"
+
+struct BFiles_struct {
+ MFile_area commit_area;
+ MFile_area_struct *register_area;
+ char *base;
+ char *cache_fname;
+};
+
+BFiles bfs_create (const char *spec, const char *base)
+{
+ BFiles bfs = (BFiles) xmalloc (sizeof(*bfs));
+ bfs->commit_area = NULL;
+ bfs->base = 0;
+ bfs->cache_fname = 0;
+ if (base)
+ bfs->base = xstrdup (base);
+ bfs->register_area = mf_init("register", spec, base);
+ if (!bfs->register_area)
+ {
+ bfs_destroy(bfs);
+ return 0;
+ }
+ return bfs;
+}
+
+void bfs_destroy (BFiles bfs)
+{
+ if (!bfs)
+ return;
+ xfree (bfs->cache_fname);
+ xfree (bfs->base);
+ mf_destroy (bfs->commit_area);
+ mf_destroy (bfs->register_area);
+ xfree (bfs);
+}
+
+static FILE *open_cache (BFiles bfs, const char *flags)
+{
+ FILE *file;
+
+ file = fopen (bfs->cache_fname, flags);
+ return file;
+}
+
+static void unlink_cache (BFiles bfs)
+{
+ unlink (bfs->cache_fname);
+}
+
+void bf_cache (BFiles bfs, const char *spec)
+{
+ if (spec)
+ {
+ yaz_log (LOG_LOG, "enabling cache spec=%s", spec);
+ if (!bfs->commit_area)
+ bfs->commit_area = mf_init ("shadow", spec, bfs->base);
+ if (bfs->commit_area)
+ {
+ bfs->cache_fname = xmalloc (strlen(bfs->commit_area->dirs->name)+
+ 8);
+ strcpy (bfs->cache_fname, bfs->commit_area->dirs->name);
+ strcat (bfs->cache_fname, "/cache");
+ yaz_log (LOG_LOG, "cache_fname = %s", bfs->cache_fname);
+ }
+ }
+ else
+ bfs->commit_area = NULL;
+}