X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=isamb%2Fisamb.c;h=8e464ba951e651cb3f18030fd57d9fbe9fff9ecd;hb=0f78f3fe78e859d9f0d3f0d3e13fcd28085dd427;hp=151960e6079081eb1ef756d4bfa5001f7d1805b3;hpb=ecb3935e78cd9bcfdebafdee0834cfb1060d7b5e;p=idzebra-moved-to-github.git diff --git a/isamb/isamb.c b/isamb/isamb.c index 151960e..8e464ba 100644 --- a/isamb/isamb.c +++ b/isamb/isamb.c @@ -1,5 +1,5 @@ -/* $Id: isamb.c,v 1.82 2006-05-10 08:13:26 adam Exp $ - Copyright (C) 1995-2005 +/* $Id: isamb.c,v 1.85 2006-11-14 08:12:08 adam Exp $ + Copyright (C) 1995-2006 Index Data ApS This file is part of the Zebra server. @@ -15,9 +15,9 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with Zebra; see the file LICENSE.zebra. If not, write to the -Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ #include @@ -157,14 +157,13 @@ static void encode_ptr(char **dst, zint pos) #define decode_item_len decode_ptr #if ISAMB_PTR_CODEC -static void decode_ptr(const char **src1, zint *pos) +static void decode_ptr(const char **src, zint *pos) { - const unsigned char **src = (const unsigned char **) src1; zint d = 0; unsigned char c; unsigned r = 0; - while (((c = *(*src)++) & 128)) + while (((c = *(const unsigned char *)((*src)++)) & 128)) { d += ((zint) (c & 127) << r); r += 7; @@ -200,12 +199,19 @@ ISAMB isamb_open(BFiles bfs, const char *name, int writeflag, ISAMC_M *method, assert(cache == 0); isamb->file = xmalloc(sizeof(*isamb->file) * isamb->no_cat); + + for (i = 0; i < isamb->no_cat; i++) + { + isamb->file[i].bf = 0; + isamb->file[i].head_dirty = 0; + isamb->file[i].cache_entries = 0; + } + for (i = 0; i < isamb->no_cat; i++) { char fname[DST_BUF_SIZE]; char hbuf[DST_BUF_SIZE]; - isamb->file[i].cache_entries = 0; - isamb->file[i].head_dirty = 0; + sprintf(fname, "%s%c", name, i+'A'); if (cache) isamb->file[i].bf = bf_open(bfs, fname, ISAMB_CACHE_ENTRY_SIZE, @@ -213,6 +219,12 @@ ISAMB isamb_open(BFiles bfs, const char *name, int writeflag, ISAMC_M *method, else isamb->file[i].bf = bf_open(bfs, fname, b_size, writeflag); + if (!isamb->file[i].bf) + { + isamb_close(isamb); + return 0; + } + /* fill-in default values (for empty isamb) */ isamb->file[i].head.first_block = ISAMB_CACHE_ENTRY_SIZE/b_size+1; isamb->file[i].head.last_block = isamb->file[i].head.first_block; @@ -415,7 +427,8 @@ void isamb_close (ISAMB isamb) bf_write(isamb->file[i].bf, pos, 0, 0, hbuf + pos*b_size); } } - bf_close (isamb->file[i].bf); + if (isamb->file[i].bf) + bf_close (isamb->file[i].bf); } xfree(isamb->file); xfree(isamb->method);