comparison sidlib.c @ 128:2636185649c6

Add si_fread_str() helper function.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 27 Oct 2016 11:58:52 +0300
parents c1462b7880e8
children c2d2369feadc
comparison
equal deleted inserted replaced
127:1786b9d77782 128:2636185649c6
24 // } * nnodes; 24 // } * nnodes;
25 th_md5hash_t hash; 25 th_md5hash_t hash;
26 } PSIDLibHdr; 26 } PSIDLibHdr;
27 27
28 28
29 BOOL si_fread_str(th_ioctx *ctx, char **str, const size_t len)
30 {
31 char *tmp = th_malloc(len + 1);
32 if (tmp == NULL)
33 goto err;
34
35 if (!thfread_str(ctx, tmp, len))
36 goto err;
37
38 tmp[len] = 0;
39
40 *str = tmp;
41
42 return TRUE;
43
44 err:
45 th_free(tmp);
46 return FALSE;
47 }
48
49
29 int si_read_sid_file(th_ioctx *ctx, PSIDHeader **ppsid) 50 int si_read_sid_file(th_ioctx *ctx, PSIDHeader **ppsid)
30 { 51 {
31 PSIDHeader *psid = NULL; 52 PSIDHeader *psid = NULL;
32 th_md5state_t state; 53 th_md5state_t state;
33 uint8_t tmp8, *data = NULL; 54 uint8_t tmp8, *data = NULL;
78 goto error; 99 goto error;
79 } 100 }
80 101
81 psid->isRSID = psid->magic[0] == 'R'; 102 psid->isRSID = psid->magic[0] == 'R';
82 103
83 if (!thfread_str(ctx, (uint8_t *) psid->sidName, PSID_STR_LEN) || 104 if (!si_fread_str(ctx, &psid->sidName, PSID_STR_LEN) ||
84 !thfread_str(ctx, (uint8_t *) psid->sidAuthor, PSID_STR_LEN) || 105 !si_fread_str(ctx, &psid->sidAuthor, PSID_STR_LEN) ||
85 !thfread_str(ctx, (uint8_t *) psid->sidCopyright, PSID_STR_LEN)) 106 !si_fread_str(ctx, &psid->sidCopyright, PSID_STR_LEN))
86 { 107 {
87 th_io_error(ctx, ctx->status, 108 th_io_error(ctx, ctx->status,
88 "Error reading SID file header: %s.\n", 109 "Error reading SID file header: %s.\n",
89 th_error_str(ctx->status)); 110 th_error_str(ctx->status));
90 goto error; 111 goto error;
91 } 112 }
92
93 psid->sidName[PSID_STR_LEN] = 0;
94 psid->sidAuthor[PSID_STR_LEN] = 0;
95 psid->sidCopyright[PSID_STR_LEN] = 0;
96 113
97 // Check if we need to load PSIDv2NG header ... 114 // Check if we need to load PSIDv2NG header ...
98 if (psid->version >= 2) 115 if (psid->version >= 2)
99 { 116 {
100 // Yes, we need to 117 // Yes, we need to