mirror of
https://gitlab.com/xCrystal/pokecrystal-board.git
synced 2024-11-16 11:27:33 -08:00
fix unused fread return value warnings
This commit is contained in:
parent
bad9e33530
commit
40305f205e
@ -21,7 +21,10 @@ uint8_t *read_u8(char *filename, int *size) {
|
|||||||
*size = ftell(f);
|
*size = ftell(f);
|
||||||
rewind(f);
|
rewind(f);
|
||||||
uint8_t *data = malloc(*size);
|
uint8_t *data = malloc(*size);
|
||||||
fread(data, 1, *size, f);
|
if (*size != (int)fread(data, 1, *size, f)) {
|
||||||
|
fprintf(stderr, "Could not read file: \"%s\"\n", filename);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -230,8 +230,13 @@ int png_get_width(char *filename) {
|
|||||||
const int OFFSET_WIDTH = 16;
|
const int OFFSET_WIDTH = 16;
|
||||||
uint8_t bytes[4];
|
uint8_t bytes[4];
|
||||||
fseek(f, OFFSET_WIDTH, SEEK_SET);
|
fseek(f, OFFSET_WIDTH, SEEK_SET);
|
||||||
fread(bytes, 1, 4, f);
|
size_t size = 4;
|
||||||
|
size_t result = fread(bytes, 1, size, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
if (result != size) {
|
||||||
|
fprintf(stderr, "Could not read file at offset 0x%x: \"%s\"\n", OFFSET_WIDTH, filename);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
int width = 0;
|
int width = 0;
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
|
@ -29,7 +29,11 @@ void print_pokemon_palette(char* palette_filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fseek(f, 2, SEEK_SET);
|
fseek(f, 2, SEEK_SET);
|
||||||
fread(bytes, 1, 4, f);
|
size_t size = 4;
|
||||||
|
if (size != fread(bytes, 1, size, f)) {
|
||||||
|
fprintf(stderr, "failed to read file %s\n", palette_filename);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
print_rgb((bytes[1] << 8) | bytes[0]);
|
print_rgb((bytes[1] << 8) | bytes[0]);
|
||||||
@ -39,7 +43,7 @@ void print_pokemon_palette(char* palette_filename) {
|
|||||||
void print_palette(char* palette_filename) {
|
void print_palette(char* palette_filename) {
|
||||||
FILE* f;
|
FILE* f;
|
||||||
uint8_t* bytes;
|
uint8_t* bytes;
|
||||||
long size;
|
size_t size;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
f = fopen(palette_filename, "rb");
|
f = fopen(palette_filename, "rb");
|
||||||
@ -63,10 +67,13 @@ void print_palette(char* palette_filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
fread(bytes, 1, size, f);
|
if (size != fread(bytes, 1, size, f)) {
|
||||||
|
fprintf(stderr, "failed to read file %s\n", palette_filename);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
for (i = 0; i + 1 < size; i += 2) {
|
for (i = 0; i + 1 < (int)size; i += 2) {
|
||||||
print_rgb((bytes[i + 1] << 8) | bytes[i]);
|
print_rgb((bytes[i + 1] << 8) | bytes[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,12 @@ void output_dimensions(char* png_filename, char* out_filename) {
|
|||||||
|
|
||||||
// width
|
// width
|
||||||
fseek(f, 16, SEEK_SET);
|
fseek(f, 16, SEEK_SET);
|
||||||
fread(bytes, 1, 4, f);
|
int size = fread(bytes, 1, 4, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
if (size != 4) {
|
||||||
|
fprintf(stderr, "failed to read at offset 0x10 in file %s\n", png_filename);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
width = 0;
|
width = 0;
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
|
@ -38,7 +38,7 @@ void make_frames(struct Frames* frames, struct Bitmasks* bitmasks, char* tilemap
|
|||||||
uint8_t* tilemap;
|
uint8_t* tilemap;
|
||||||
uint8_t* this_frame;
|
uint8_t* this_frame;
|
||||||
FILE* f;
|
FILE* f;
|
||||||
long size;
|
size_t size;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
@ -48,7 +48,7 @@ void make_frames(struct Frames* frames, struct Bitmasks* bitmasks, char* tilemap
|
|||||||
|
|
||||||
f = fopen(tilemap_filename, "rb");
|
f = fopen(tilemap_filename, "rb");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
fprintf(stderr, "could not open file %s", tilemap_filename);
|
fprintf(stderr, "could not open file %s\n", tilemap_filename);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,15 +65,21 @@ void make_frames(struct Frames* frames, struct Bitmasks* bitmasks, char* tilemap
|
|||||||
fprintf(stderr, "malloc failure\n");
|
fprintf(stderr, "malloc failure\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
fread(tilemap, 1, size, f);
|
if (size != fread(tilemap, 1, size, f)) {
|
||||||
|
fprintf(stderr, "failed to read file %s\n", tilemap_filename);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
f = fopen(dimensions_filename, "rb");
|
f = fopen(dimensions_filename, "rb");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
fprintf(stderr, "could not open file %s", dimensions_filename);
|
fprintf(stderr, "could not open file %s\n", dimensions_filename);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (1 != fread(&byte, 1, 1, f)) {
|
||||||
|
fprintf(stderr, "failed to read file %s\n", dimensions_filename);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
fread(&byte, 1, 1, f);
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
width = byte & 0xf;
|
width = byte & 0xf;
|
||||||
@ -137,7 +143,7 @@ void make_frames(struct Frames* frames, struct Bitmasks* bitmasks, char* tilemap
|
|||||||
//}
|
//}
|
||||||
//free(frames->frames);
|
//free(frames->frames);
|
||||||
|
|
||||||
//fprintf(stderr, "num bitmasks: %d", bitmasks->num_bitmasks);
|
//fprintf(stderr, "num bitmasks: %d\n", bitmasks->num_bitmasks);
|
||||||
//for (i = 0; i < bitmasks->num_bitmasks; i++) {
|
//for (i = 0; i < bitmasks->num_bitmasks; i++) {
|
||||||
// free(bitmasks->bitmasks[i].data);
|
// free(bitmasks->bitmasks[i].data);
|
||||||
// fprintf(stderr, "freed bitmask %d\n", i);
|
// fprintf(stderr, "freed bitmask %d\n", i);
|
||||||
@ -263,7 +269,7 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
//ext = strrchr(argv[3], '.');
|
//ext = strrchr(argv[3], '.');
|
||||||
//if (!ext || ext == argv[3]) {
|
//if (!ext || ext == argv[3]) {
|
||||||
// fprintf(stderr, "need a file extension to determine what to write to %s", argv[3]);
|
// fprintf(stderr, "need a file extension to determine what to write to %s\n", argv[3]);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
make_frames(&frames, &bitmasks, tilemap_filename, dimensions_filename);
|
make_frames(&frames, &bitmasks, tilemap_filename, dimensions_filename);
|
||||||
|
@ -100,7 +100,10 @@ void create_tilemap(struct Tilemap* tilemap, struct Graphic* graphic, char* grap
|
|||||||
fprintf(stderr, "malloc failure\n");
|
fprintf(stderr, "malloc failure\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
fread(graphics, 1, graphics_size, f);
|
if (graphics_size != (long)fread(graphics, 1, graphics_size, f)) {
|
||||||
|
fprintf(stderr, "failed to read file %s\n", graphics_filename);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
int num_tiles_per_frame = width * height;
|
int num_tiles_per_frame = width * height;
|
||||||
@ -213,7 +216,10 @@ int main(int argc, char* argv[]) {
|
|||||||
if (!f) {
|
if (!f) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
fread(bytes, 1, 1, f);
|
if (1 != fread(bytes, 1, 1, f)) {
|
||||||
|
fprintf(stderr, "failed to read file %s\n", dimensions_filename);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
width = bytes[0] & 0xf;
|
width = bytes[0] & 0xf;
|
||||||
height = bytes[0] >> 4;
|
height = bytes[0] >> 4;
|
||||||
|
Loading…
Reference in New Issue
Block a user