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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#include <stdio.h>
#include "header.h"
int header_write(FILE *fd, const struct header *h) {
// Write the header to file
uint32_t be;
if( fwrite(h->magic, 3, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write magic[3]\n");
return ERR_FILE;
}
if( fwrite(&h->version, 1, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write version\n");
return ERR_FILE;
}
be = BE32(h->artist_start);
if( fwrite(&be, 4, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write artist_start\n");
return ERR_FILE;
}
be = BE32(h->album_start);
if( fwrite(&be, 4, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write album_start\n");
return ERR_FILE;
}
be = BE32(h->song_start);
if( fwrite(&be, 4, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write song_start\n");
return ERR_FILE;
}
be = BE32(h->file_start);
if( fwrite(&be, 4, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write file_start\n");
return ERR_FILE;
}
be = BE32(h->artist_count);
if( fwrite(&be, 4, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write artist_count\n");
return ERR_FILE;
}
be = BE32(h->album_count);
if( fwrite(&be, 4, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write album_count\n");
return ERR_FILE;
}
be = BE32(h->song_count);
if( fwrite(&be, 4, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write song_count\n");
return ERR_FILE;
}
be = BE32(h->file_count);
if( fwrite(&be, 4, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write file_count\n");
return ERR_FILE;
}
be = BE32(h->artist_len);
if( fwrite(&be, 4, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write artist_len\n");
return ERR_FILE;
}
be = BE32(h->album_len);
if( fwrite(&be, 4, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write album_len\n");
return ERR_FILE;
}
be = BE32(h->song_len);
if( fwrite(&be, 4, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write song_len\n");
return ERR_FILE;
}
be = BE32(h->genre_len);
if( fwrite(&be, 4, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write genre_len\n");
return ERR_FILE;
}
be = BE32(h->file_len);
if( fwrite(&be, 4, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write file_len\n");
return ERR_FILE;
}
be = BE32(h->song_array_count);
if( fwrite(&be, 4, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write song_array_count\n");
return ERR_FILE;
}
be = BE32(h->album_array_count);
if( fwrite(&be, 4, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write album_array_count\n");
return ERR_FILE;
}
be = BE32( (h->flags.reserved << 1) | (h->flags.rundb_dirty) );
if( fwrite(&be, 4, 1, fd) != 1 ) {
DEBUGF("header_write: failed to write flags\n");
return ERR_FILE;
}
return ERR_NONE;
}
|