]> git.draconx.ca Git - upkg.git/blob - src/engine/music-dummymod.c
c2e61b73c85dff2821d4c337f6eebb89d6904e0f
[upkg.git] / src / engine / music-dummymod.c
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include "music-module.h"
5 #include "upkg.h"
6
7 struct music_mod {
8         struct upkg_file *f;
9 };
10
11 int music_mod_init(void)
12 {
13         return 0;
14 }
15
16 void music_mod_exit(void)
17 {
18 }
19
20 struct music_mod *music_mod_open(struct upkg_file *f)
21 {
22         struct music_mod *m = malloc(sizeof *m);
23
24         if (m) {
25                 m->f = f;
26         }
27
28         return m;
29 }
30
31 void music_mod_close(struct music_mod *m)
32 {
33         free(m);
34 }
35
36 int music_mod_dump(struct music_mod *m, FILE *of)
37 {
38         unsigned char buf[1024];
39         size_t rc;
40
41         if (upkg_export_seek(m->f, 0, SEEK_SET) != 0) {
42                 return -1;
43         }
44
45         while (1) {
46                 rc = upkg_export_read(m->f, buf, sizeof buf);
47                 if (rc == 0) {
48                         if (!m->f->eof)
49                                 return -1;
50                         return 0;
51                 }
52
53                 if (fwrite(buf, rc, 1, of) != 1) {
54                         if (feof(of)) {
55                                 fprintf(stderr, "unexpected end-of-file.\n");
56                         } else {
57                                 perror("fwrite");
58                         }
59                         return -1;
60                 }
61
62                 if (rc < sizeof buf) {
63                         if (!m->f->eof)
64                                 return -1;
65                         return 0;
66                 }
67         }
68 }
69
70 const char *music_mod_type(struct music_mod *mod)
71 {
72         return "unknown";
73 }