1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#ifndef __ARTIST_H__
#define __ARTIST_H__
#include "config.h"
#include <stdio.h>
#include <stdint.h>
struct artist_entry {
char* name; // artist name
uint32_t *album; // album-pointers
struct artist_size {
uint32_t name_len; // length of this field (must be mulitple of 4)
uint32_t album_count; // number of album pointers
} size;
unsigned char flag; // flags
};
struct artist_entry* new_artist_entry(const uint32_t name_len, const uint32_t album_count);
/* Creates a new artist_entry with the specified sizes
* Returns a pointer to the structure on success,
* NULL on failure
*/
int artist_entry_destruct(struct artist_entry *e);
/* Destructs the given artist_entry and free()'s it's memory
* returns ERR_NONE on success (can't fail)
*/
int artist_entry_resize(struct artist_entry *e, const uint32_t name_len, const uint32_t album_count);
/* Change the size of the entry
* returns ERR_NONE on succes
* ERR_MALLOC on malloc() failure
*/
int artist_entry_serialize(FILE *fd, const struct artist_entry *e);
/* Serializes the entry in the file at the current position
* returns ERR_NONE on success
* ERR_FILE on fwrite() failure
*/
int artist_entry_unserialize(struct artist_entry* *e, FILE *fd);
/* Unserializes an entry from file into a new structure
* The address of the structure is saved into *e
* returns ERR_NONE on success
* ERR_MALLOC on malloc() failure
* ERR_FILE on fread() failure
*/
int artist_entry_write(FILE *fd, const struct artist_entry *e, const struct artist_size *s);
/* Writes the entry to file in the final form
* returns ERR_NONE on success
* ERR_FILE on fwrite() failure
*/
inline int artist_entry_compare(const struct artist_entry *a, const struct artist_entry *b);
/* Compares 2 entries
* When a < b it returns <0
* a = b 0
* a > b >0
*/
struct artist_size* new_artist_size();
/* Creates a new size structure
* returns a pointer to the structure on success,
* NULL on failure
*/
inline uint32_t artist_size_get_length(const struct artist_size *size);
/* Calculates the length of the entry when written by artist_entry_write()
* returns the length on success (can't fail)
*/
inline int artist_size_max(struct artist_size *s, const struct artist_entry *e);
/* Updates the artist_size structure to contain the maximal lengths of either
* the original entry in s, or the entry e
* returns ERR_NONE on success (can't fail)
*/
int artist_size_destruct(struct artist_size *s);
/* destructs the artist_size structure
* returns ERR_NONE on success (can't fail)
*/
int artist_entry_add_album_mem(struct artist_entry *e, struct artist_size *s, const uint32_t album);
/* Adds the album to the array
* returns ERR_NONE on success
* ERR_MALLOC on malloc() failure
*/
int artist_entry_add_album_file(FILE *fd, struct artist_entry *e, struct artist_size *s, const uint32_t album);
/* Adds the album to the serialized entry in the file
* When this fails, the entry is invalidated and the function returns
* ERR_NO_INPLACE_UPDATE
* returns ERR_NONE on success
* ERR_NO_INPLACE_UPDATE (see above)
* ERR_FILE on fread()/fwrite() error
*/
#endif
|