4 static void write_tree_header (BTree *tree);
5 static void write_block (BTree *tree, uchar *block, uint num);
7 BTree *btree_create (const char *filename, unsigned int block_size)
12 tree = malloc (sizeof(BTree));
16 tree->fp = fopen (filename, "wb");
22 /* Nombre de archivo */
23 tree->filename = malloc(sizeof(char)+1);
24 strcpy (tree->filename, filename);
26 /* Inicializo el header */
27 tree->header.block_size = block_size;
28 write_tree_header (tree);
30 /* Creo el primer bloque vacio */
31 node = calloc (1, block_size);
32 write_block (tree, node, 0);
37 int btree_close (BTree *tree)
40 free (tree->filename);
46 static void write_tree_header (BTree *tree)
48 fseek (tree->fp, 0L, SEEK_SET);
49 fwrite (&tree->header, 1, sizeof (BTreeHeader), tree->fp);
52 static void write_block (BTree *tree, uchar *block, uint num)
54 fseek (tree->fp, num*tree->header.block_size + sizeof (BTreeHeader), SEEK_SET);
55 fwrite (block, 1, tree->header.block_size, tree->fp);