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