]> git.draconx.ca Git - upkg.git/blob - src/engine/music-dummymod.c
db18fa45482bd067eba7762727b183f7ba44e2f5
[upkg.git] / src / engine / music-dummymod.c
1 /*
2  *  upkg: tool for manipulating Unreal Tournament packages.
3  *  Copyright (C) 2009 Nick Bowler
4  *
5  *  This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21
22 #include "music-module.h"
23 #include "upkg.h"
24
25 struct music_mod {
26         struct upkg_file *f;
27 };
28
29 int music_mod_init(void)
30 {
31         return 0;
32 }
33
34 void music_mod_exit(void)
35 {
36 }
37
38 struct music_mod *music_mod_open(struct upkg_file *f)
39 {
40         struct music_mod *m = malloc(sizeof *m);
41
42         if (m) {
43                 m->f = f;
44         }
45
46         return m;
47 }
48
49 void music_mod_close(struct music_mod *m)
50 {
51         free(m);
52 }
53
54 int music_mod_dump(struct music_mod *m, FILE *of)
55 {
56         unsigned char buf[1024];
57         size_t rc;
58
59         if (upkg_export_seek(m->f, 0, SEEK_SET) != 0) {
60                 return -1;
61         }
62
63         while (1) {
64                 rc = upkg_export_read(m->f, buf, sizeof buf);
65                 if (rc == 0) {
66                         if (!m->f->eof)
67                                 return -1;
68                         return 0;
69                 }
70
71                 if (fwrite(buf, rc, 1, of) != 1) {
72                         if (feof(of)) {
73                                 fprintf(stderr, "unexpected end-of-file.\n");
74                         } else {
75                                 perror("fwrite");
76                         }
77                         return -1;
78                 }
79
80                 if (rc < sizeof buf) {
81                         if (!m->f->eof)
82                                 return -1;
83                         return 0;
84                 }
85         }
86 }
87
88 const char *music_mod_type(struct music_mod *mod)
89 {
90         return "unknown";
91 }