43274afe4cfd2a097e500114c16a2eadccac07f9
[idzebra-moved-to-github.git] / isam / rootblk.c
1 /*
2  * Copyright (C) 1994-1999, Index Data
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: rootblk.c,v $
7  * Revision 1.3  1999-02-02 14:51:24  adam
8  * Updated WIN32 code specific sections. Changed header.
9  *
10  * Revision 1.2  1995/09/04 12:33:47  adam
11  * Various cleanup. YAZ util used instead.
12  *
13  * Revision 1.1  1994/09/26  16:08:00  quinn
14  * Most of the functionality in place.
15  *
16  */
17
18 /*
19  * Read and write the blocktype header.
20  */
21
22 #include <stdio.h>
23 #include <isam.h>
24 #include "rootblk.h"
25
26 int is_rb_write(isam_blocktype *ib, is_type_header *hd)
27 {
28     int pt = 0, ct = 0, towrite;
29
30     while ((towrite = sizeof(*hd) - pt) > 0)
31     {
32         if (towrite > bf_blocksize(ib->bf))
33                 towrite = bf_blocksize(ib->bf);
34         if (bf_write(ib->bf, ct, 0, towrite, (char *)hd + pt) < 0)
35             return -1;
36         pt += bf_blocksize(ib->bf);
37         ct++;
38     }
39     return ct;
40 }
41
42 int is_rb_read(isam_blocktype *ib, is_type_header *hd)
43 {
44     int pt = 0, ct = 0, rs, toread;
45
46     while ((toread = sizeof(*hd) - pt) > 0)
47     {
48         if (toread > bf_blocksize(ib->bf))
49             toread = bf_blocksize(ib->bf);
50         if ((rs = bf_read(ib->bf, ct, 0, toread, (char*)hd + pt)) <= 0)
51             return rs;
52         pt += bf_blocksize(ib->bf);
53         ct++;
54     }
55     return ct;
56 }