diff options
Diffstat (limited to 'apps/tagdb/header.c')
-rw-r--r-- | apps/tagdb/header.c | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/apps/tagdb/header.c b/apps/tagdb/header.c new file mode 100644 index 0000000000..01f973824b --- /dev/null +++ b/apps/tagdb/header.c | |||
@@ -0,0 +1,121 @@ | |||
1 | |||
2 | #include <stdio.h> | ||
3 | |||
4 | #include "header.h" | ||
5 | |||
6 | int header_write(FILE *fd, const struct header *h) { | ||
7 | // Write the header to file | ||
8 | uint32_t be; | ||
9 | |||
10 | if( fwrite(h->magic, 3, 1, fd) != 1 ) { | ||
11 | DEBUGF("header_write: failed to write magic[3]\n"); | ||
12 | return ERR_FILE; | ||
13 | } | ||
14 | if( fwrite(&h->version, 1, 1, fd) != 1 ) { | ||
15 | DEBUGF("header_write: failed to write version\n"); | ||
16 | return ERR_FILE; | ||
17 | } | ||
18 | |||
19 | be = BE32(h->artist_start); | ||
20 | if( fwrite(&be, 4, 1, fd) != 1 ) { | ||
21 | DEBUGF("header_write: failed to write artist_start\n"); | ||
22 | return ERR_FILE; | ||
23 | } | ||
24 | |||
25 | be = BE32(h->album_start); | ||
26 | if( fwrite(&be, 4, 1, fd) != 1 ) { | ||
27 | DEBUGF("header_write: failed to write album_start\n"); | ||
28 | return ERR_FILE; | ||
29 | } | ||
30 | |||
31 | be = BE32(h->song_start); | ||
32 | if( fwrite(&be, 4, 1, fd) != 1 ) { | ||
33 | DEBUGF("header_write: failed to write song_start\n"); | ||
34 | return ERR_FILE; | ||
35 | } | ||
36 | |||
37 | be = BE32(h->file_start); | ||
38 | if( fwrite(&be, 4, 1, fd) != 1 ) { | ||
39 | DEBUGF("header_write: failed to write file_start\n"); | ||
40 | return ERR_FILE; | ||
41 | } | ||
42 | |||
43 | |||
44 | be = BE32(h->artist_count); | ||
45 | if( fwrite(&be, 4, 1, fd) != 1 ) { | ||
46 | DEBUGF("header_write: failed to write artist_count\n"); | ||
47 | return ERR_FILE; | ||
48 | } | ||
49 | |||
50 | be = BE32(h->album_count); | ||
51 | if( fwrite(&be, 4, 1, fd) != 1 ) { | ||
52 | DEBUGF("header_write: failed to write album_count\n"); | ||
53 | return ERR_FILE; | ||
54 | } | ||
55 | |||
56 | be = BE32(h->song_count); | ||
57 | if( fwrite(&be, 4, 1, fd) != 1 ) { | ||
58 | DEBUGF("header_write: failed to write song_count\n"); | ||
59 | return ERR_FILE; | ||
60 | } | ||
61 | |||
62 | be = BE32(h->file_count); | ||
63 | if( fwrite(&be, 4, 1, fd) != 1 ) { | ||
64 | DEBUGF("header_write: failed to write file_count\n"); | ||
65 | return ERR_FILE; | ||
66 | } | ||
67 | |||
68 | |||
69 | be = BE32(h->artist_len); | ||
70 | if( fwrite(&be, 4, 1, fd) != 1 ) { | ||
71 | DEBUGF("header_write: failed to write artist_len\n"); | ||
72 | return ERR_FILE; | ||
73 | } | ||
74 | |||
75 | be = BE32(h->album_len); | ||
76 | if( fwrite(&be, 4, 1, fd) != 1 ) { | ||
77 | DEBUGF("header_write: failed to write album_len\n"); | ||
78 | return ERR_FILE; | ||
79 | } | ||
80 | |||
81 | be = BE32(h->song_len); | ||
82 | if( fwrite(&be, 4, 1, fd) != 1 ) { | ||
83 | DEBUGF("header_write: failed to write song_len\n"); | ||
84 | return ERR_FILE; | ||
85 | } | ||
86 | |||
87 | be = BE32(h->genre_len); | ||
88 | if( fwrite(&be, 4, 1, fd) != 1 ) { | ||
89 | DEBUGF("header_write: failed to write genre_len\n"); | ||
90 | return ERR_FILE; | ||
91 | } | ||
92 | |||
93 | be = BE32(h->file_len); | ||
94 | if( fwrite(&be, 4, 1, fd) != 1 ) { | ||
95 | DEBUGF("header_write: failed to write file_len\n"); | ||
96 | return ERR_FILE; | ||
97 | } | ||
98 | |||
99 | |||
100 | be = BE32(h->song_array_count); | ||
101 | if( fwrite(&be, 4, 1, fd) != 1 ) { | ||
102 | DEBUGF("header_write: failed to write song_array_count\n"); | ||
103 | return ERR_FILE; | ||
104 | } | ||
105 | |||
106 | be = BE32(h->album_array_count); | ||
107 | if( fwrite(&be, 4, 1, fd) != 1 ) { | ||
108 | DEBUGF("header_write: failed to write album_array_count\n"); | ||
109 | return ERR_FILE; | ||
110 | } | ||
111 | |||
112 | |||
113 | be = BE32( (h->flags.reserved << 1) | (h->flags.rundb_dirty) ); | ||
114 | if( fwrite(&be, 4, 1, fd) != 1 ) { | ||
115 | DEBUGF("header_write: failed to write flags\n"); | ||
116 | return ERR_FILE; | ||
117 | } | ||
118 | |||
119 | |||
120 | return ERR_NONE; | ||
121 | } | ||