Mercurial > hg > sidinfo
comparison sidlib.c @ 126:c1462b7880e8
Make si_read_sid_file() to allocate the PSIDHeader struct itself, adjust
API/ABI accordingly.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 27 Oct 2016 11:52:27 +0300 |
parents | 09ca9d9a8710 |
children | 2636185649c6 |
comparison
equal
deleted
inserted
replaced
125:ffccc712409a | 126:c1462b7880e8 |
---|---|
24 // } * nnodes; | 24 // } * nnodes; |
25 th_md5hash_t hash; | 25 th_md5hash_t hash; |
26 } PSIDLibHdr; | 26 } PSIDLibHdr; |
27 | 27 |
28 | 28 |
29 int si_read_sid_file(th_ioctx *ctx, PSIDHeader *psid) | 29 int si_read_sid_file(th_ioctx *ctx, PSIDHeader **ppsid) |
30 { | 30 { |
31 PSIDHeader *psid = NULL; | |
31 th_md5state_t state; | 32 th_md5state_t state; |
32 uint8_t tmp8, *data = NULL; | 33 uint8_t tmp8, *data = NULL; |
33 int index, ret = -1; | 34 int index, ret = -1; |
34 size_t read; | 35 size_t read; |
35 BOOL first; | 36 BOOL first; |
36 | 37 |
37 memset(psid, 0, sizeof(*psid)); | |
38 | |
39 if ((data = (uint8_t *) th_malloc(PSID_BUFFER_SIZE)) == NULL) | 38 if ((data = (uint8_t *) th_malloc(PSID_BUFFER_SIZE)) == NULL) |
40 { | 39 { |
41 th_io_error(ctx, THERR_MALLOC, | 40 th_io_error(ctx, THERR_MALLOC, |
42 "Error allocating temporary data buffer of %d bytes.\n", | 41 "Error allocating temporary data buffer of %d bytes.\n", |
43 PSID_BUFFER_SIZE); | 42 PSID_BUFFER_SIZE); |
43 goto error; | |
44 } | |
45 | |
46 if ((psid = *ppsid = th_malloc0(sizeof(PSIDHeader))) == NULL) | |
47 { | |
48 th_io_error(ctx, THERR_MALLOC, | |
49 "Error PSID context struct.\n"); | |
44 goto error; | 50 goto error; |
45 } | 51 } |
46 | 52 |
47 // Read PSID header in | 53 // Read PSID header in |
48 if (!thfread_str(ctx, (uint8_t *) psid->magic, PSID_MAGIC_LEN) || | 54 if (!thfread_str(ctx, (uint8_t *) psid->magic, PSID_MAGIC_LEN) || |
175 | 181 |
176 error: | 182 error: |
177 // Free buffer | 183 // Free buffer |
178 th_free(data); | 184 th_free(data); |
179 return ret; | 185 return ret; |
186 } | |
187 | |
188 | |
189 void si_free_sid_file(PSIDHeader *psid) | |
190 { | |
191 if (psid != NULL) | |
192 { | |
193 th_free(psid->sidName); | |
194 th_free(psid->sidAuthor); | |
195 th_free(psid->sidCopyright); | |
196 } | |
180 } | 197 } |
181 | 198 |
182 | 199 |
183 const char *si_get_sid_clock_str(const int flags) | 200 const char *si_get_sid_clock_str(const int flags) |
184 { | 201 { |