-
+/*
+ * Copyright (C) 1998-2002, Index Data ApS
+ * All rights reserved.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Id: sortidx.c,v 1.6 2002-02-18 11:46:58 adam Exp $
+ */
+
#include <string.h>
-#include <log.h>
+#include <yaz/log.h>
#include <bfile.h>
#include <sortidx.h>
SortIdx sortIdx_open (BFiles bfs, int write_flag)
{
- SortIdx si = xmalloc (sizeof(*si));
+ SortIdx si = (SortIdx) xmalloc (sizeof(*si));
si->bfs = bfs;
si->write_flag = write_flag;
si->current_file = NULL;
si->files = NULL;
- si->entry_buf = xmalloc (SORT_IDX_ENTRYSIZE);
+ si->entry_buf = (char *) xmalloc (SORT_IDX_ENTRYSIZE);
return si;
}
si->current_file = sf;
return 0;
}
- sf = xmalloc (sizeof(*sf));
+ sf = (struct sortFile *) xmalloc (sizeof(*sf));
sf->type = type;
sf->bf = NULL;
- sf->next = si->files;
- si->current_file = si->files = sf;
sprintf (fname, "sort%d", type);
logf (LOG_DEBUG, "sort idx %s wr=%d", fname, si->write_flag);
sf->bf = bf_open (si->bfs, fname, SORT_IDX_BLOCKSIZE, si->write_flag);
if (!sf->bf)
+ {
+ xfree (sf);
return -1;
+ }
if (!bf_read (sf->bf, 0, 0, sizeof(sf->head), &sf->head))
{
sf->head.sysno_max = 0;
if (!si->write_flag)
+ {
+ bf_close (sf->bf);
+ xfree (sf);
return -1;
+ }
}
+ sf->next = si->files;
+ si->current_file = si->files = sf;
return 0;
}