comparison sidlib.c @ 185:2dfe46fda09e

Improve error handling through ioctx.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 09 Jul 2018 08:05:49 +0300
parents d86ade7d0dfd
children b4a349f1c2f4
comparison
equal deleted inserted replaced
184:170e447e0984 185:2dfe46fda09e
131 !thfread_be16(ctx, &psid->nSongs) || 131 !thfread_be16(ctx, &psid->nSongs) ||
132 !thfread_be16(ctx, &psid->startSong) || 132 !thfread_be16(ctx, &psid->startSong) ||
133 !thfread_be32(ctx, &psid->speed)) 133 !thfread_be32(ctx, &psid->speed))
134 { 134 {
135 th_io_error(ctx, ctx->status, 135 th_io_error(ctx, ctx->status,
136 "Could not read PSID/RSID header: %s.\n", 136 "Could not read PSID/RSID header from '%s': %s.\n",
137 th_error_str(ctx->status)); 137 ctx->filename, th_error_str(ctx->status));
138 goto error; 138 goto error;
139 } 139 }
140 140
141 psid->magic[PSID_MAGIC_LEN] = 0; 141 psid->magic[PSID_MAGIC_LEN] = 0;
142 142
143 if ((psid->magic[0] != 'R' && psid->magic[0] != 'P') || 143 if ((psid->magic[0] != 'R' && psid->magic[0] != 'P') ||
144 psid->magic[1] != 'S' || psid->magic[2] != 'I' || psid->magic[3] != 'D' || 144 psid->magic[1] != 'S' || psid->magic[2] != 'I' || psid->magic[3] != 'D' ||
145 psid->version < 1 || psid->version > 4) 145 psid->version < 1 || psid->version > 4)
146 { 146 {
147 th_io_error(ctx, THERR_NOT_SUPPORTED, 147 th_io_error(ctx, THERR_NOT_SUPPORTED,
148 "Not a supported PSID or RSID file.\n"); 148 "Not a supported PSID or RSID file: %s\n",
149 ctx->filename);
149 goto error; 150 goto error;
150 } 151 }
151 152
152 psid->isRSID = psid->magic[0] == 'R'; 153 psid->isRSID = psid->magic[0] == 'R';
153 154
154 if (!si_fread_str(ctx, &psid->sidName, PSID_STR_LEN) || 155 if (!si_fread_str(ctx, &psid->sidName, PSID_STR_LEN) ||
155 !si_fread_str(ctx, &psid->sidAuthor, PSID_STR_LEN) || 156 !si_fread_str(ctx, &psid->sidAuthor, PSID_STR_LEN) ||
156 !si_fread_str(ctx, &psid->sidCopyright, PSID_STR_LEN)) 157 !si_fread_str(ctx, &psid->sidCopyright, PSID_STR_LEN))
157 { 158 {
158 th_io_error(ctx, ctx->status, 159 th_io_error(ctx, ctx->status,
159 "Error reading SID file header: %s.\n", 160 "Error reading SID file header from '%s': %s.\n",
160 th_error_str(ctx->status)); 161 ctx->filename, th_error_str(ctx->status));
161 goto error; 162 goto error;
162 } 163 }
163 164
164 // Check if we need to load PSIDv2NG header ... 165 // Check if we need to load PSIDv2NG header ...
165 if (psid->version >= 2) 166 if (psid->version >= 2)
170 !thfread_u8(ctx, &psid->pageLength) || 171 !thfread_u8(ctx, &psid->pageLength) ||
171 !thfread_u8(ctx, &psid->sid2Addr) || 172 !thfread_u8(ctx, &psid->sid2Addr) ||
172 !thfread_u8(ctx, &psid->sid3Addr)) 173 !thfread_u8(ctx, &psid->sid3Addr))
173 { 174 {
174 th_io_error(ctx, ctx->status, 175 th_io_error(ctx, ctx->status,
175 "Error reading PSID/RSID v2+ extra header data: %s.\n", 176 "Error reading PSID/RSID v2+ extra header data from '%s': %s.\n",
176 th_error_str(ctx->status)); 177 ctx->filename, th_error_str(ctx->status));
177 goto error; 178 goto error;
178 } 179 }
179 } 180 }
180 181
181 hdrEnd = thftell(ctx); 182 hdrEnd = thftell(ctx);