summaryrefslogtreecommitdiff
path: root/apps/tagdb/file.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tagdb/file.h')
-rw-r--r--apps/tagdb/file.h84
1 files changed, 84 insertions, 0 deletions
diff --git a/apps/tagdb/file.h b/apps/tagdb/file.h
new file mode 100644
index 0000000000..d2538a7569
--- /dev/null
+++ b/apps/tagdb/file.h
@@ -0,0 +1,84 @@
1#ifndef __FILE_H__
2#define __FILE_H__
3
4#include "config.h"
5#include <stdio.h>
6#include <stdint.h>
7
8struct file_entry {
9 char* name; // song name
10
11 uint32_t hash;
12 uint32_t song; // pointer to song
13 uint32_t rundb; // pointer to rundb
14
15 struct file_size {
16 uint32_t name_len; // must be mulitple of 4
17 } size;
18 unsigned char flag; // flags
19};
20
21struct 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
25 */
26
27int 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
30 */
31
32inline 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
35 */
36
37int 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
40 */
41
42int 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
48 */
49
50int 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
53 */
54
55inline 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
60 */
61
62struct file_size* new_file_size();
63/* Creates a new size structure
64 * returns a pointer to the structure on success,
65 * NULL on failure
66 */
67
68inline 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
71 */
72
73inline 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
77 */
78
79int file_size_destruct(struct file_size *s);
80/* destructs the file_size structure
81 * returns 0 on success, 1 on failure
82 */
83
84#endif