Most of the functionality in place.
[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.1  1994-09-26 16:08:00  quinn
8  * Most of the functionality in place.
9  *
10  */
11
12 /*
13  * Read and write the blocktype header.
14  */
15
16 #include <isam.h>
17 #include "rootblk.h"
18
19 int is_rb_write(isam_blocktype *ib, is_type_header *hd)
20 {
21     int pt = 0, ct = 0, towrite;
22
23     while ((towrite = sizeof(*hd) - pt) > 0)
24     {
25         if (towrite > bf_blocksize(ib->bf))
26                 towrite = bf_blocksize(ib->bf);
27         if (bf_write(ib->bf, ct, 0, towrite, (char *)hd + pt) < 0)
28             return -1;
29         pt += bf_blocksize(ib->bf);
30         ct++;
31     }
32     return ct;
33 }
34
35 int is_rb_read(isam_blocktype *ib, is_type_header *hd)
36 {
37     int pt = 0, ct = 0, rs, toread;
38
39     while ((toread = sizeof(*hd) - pt) > 0)
40     {
41         if (toread > bf_blocksize(ib->bf))
42             toread = bf_blocksize(ib->bf);
43         if ((rs = bf_read(ib->bf, ct, 0, toread, (char*)hd + pt)) <= 0)
44             return rs;
45         pt += bf_blocksize(ib->bf);
46         ct++;
47     }
48     return ct;
49 }