lots of old and new edits
[kugel-rb.git] / apps / tagdb / file.h
blobd2538a7569052367c16bac550868eef7667a7330
1 #ifndef __FILE_H__
2 #define __FILE_H__
4 #include "config.h"
5 #include <stdio.h>
6 #include <stdint.h>
8 struct file_entry {
9 char* name; // song name
11 uint32_t hash;
12 uint32_t song; // pointer to song
13 uint32_t rundb; // pointer to rundb
15 struct file_size {
16 uint32_t name_len; // must be mulitple of 4
17 } size;
18 unsigned char flag; // flags
21 struct file_entry* new_file_entry(const uint32_t name_len);
22 /* Creates a new file_entry with the specified sizes
23 * Returns a pointer to the structure on success,
24 * NULL on failure
27 int file_entry_destruct(struct file_entry *e);
28 /* Destructs the given file_entry and free()'s it's memory
29 * returns 0 on success, 1 on failure
32 inline int file_entry_resize(struct file_entry *e, const uint32_t name_len);
33 /* Change the size of the entry
34 * returns 0 on succes, 1 on failure
37 int file_entry_serialize(FILE *fd, const struct file_entry *e);
38 /* Serializes the entry in the file at the current position
39 * returns 0 on success, 1 on failure
42 int file_entry_unserialize(struct file_entry* *e, FILE *fd);
43 /* Unserializes an entry from file into a new structure
44 * The address of the structure is saved into *e
45 * returns 0 on success
46 * 1 on malloc() failure
47 * 2 on fread() failure
50 int file_entry_write(FILE *fd, struct file_entry *e, struct file_size *s);
51 /* Writes the entry to file in the final form
52 * returns 0 (0) on success, 1 (1) on failure
55 inline int file_entry_compare(const struct file_entry *a, const struct file_entry *b);
56 /* Compares 2 entries
57 * When a < b it returns <0
58 * a = b 0
59 * a > b >0
62 struct file_size* new_file_size();
63 /* Creates a new size structure
64 * returns a pointer to the structure on success,
65 * NULL on failure
68 inline uint32_t file_size_get_length(const struct file_size *size);
69 /* Calculates the length of the entry when written by file_entry_write()
70 * returns the length on success, 0xffffffff on failure
73 inline int file_size_max(struct file_size *s, const struct file_entry *e);
74 /* Updates the file_size structure to contain the maximal lengths of either
75 * the original entry in s, or the entry e
76 * returns 0 on success, 1 on failure
79 int file_size_destruct(struct file_size *s);
80 /* destructs the file_size structure
81 * returns 0 on success, 1 on failure
84 #endif