From 96fe104e6b1c1452a8408bb46baa73d2b93bcf0e Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Wed, 2 Sep 2020 17:29:51 +0200 Subject: bitmap_strerror: More verbose bitmap failures --- src/bitmap.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/bitmap.c') diff --git a/src/bitmap.c b/src/bitmap.c index 6d72cb0..31256e8 100644 --- a/src/bitmap.c +++ b/src/bitmap.c @@ -6,6 +6,15 @@ #include "bitmap.h" +static const int bitmap_errors_cnt = 5; +static const char* bitmap_errors[] = { + "OK.", + "Error opening file.", // Use errno instead + "Invalid or corrupted file.", + "Unsupported bit depth.", + "Compression not supported." +}; + static struct bitmap_file_header bitmap_read_file_header(FILE *_file); static struct bitmap_image bitmap_read_pixel_data(FILE *_file, struct bitmap_file_header _header); @@ -265,3 +274,10 @@ static uint8_t bitmap_rgb_luminance(uint8_t R, uint8_t G, uint8_t B) { return ret; } + +char* bitmap_strerror( int _error ) { + if ( _error >= bitmap_errors_cnt || _error < 0) + return "Unknown Error."; + + return (char*) bitmap_errors[_error]; +} -- cgit v1.2.3