libansilove

Library for converting ANSI, ASCII, and other formats to PNG
Log | Files | Refs | README | LICENSE

commit f26fc46dbd1b5f5b31977f37baf7f624a693cab4
parent 70b6a4dcc6e6693ef61630a14e3cc256a95da7a0
Author: Frederic Cambus <fred@statdns.com>
Date:   Thu, 25 Oct 2018 22:17:29 +0200

Add ANSILOVE_FILE_READ_ERROR and ANSILOVE_FILE_WRITE_ERROR to return more granular errors

Diffstat:
Minclude/ansilove.h | 5+++--
Msrc/error.c | 9++++++---
Msrc/loadfile.c | 4++--
Msrc/savefile.c | 2+-
4 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/include/ansilove.h b/include/ansilove.h @@ -21,8 +21,9 @@ #define ANSILOVE_INVALID_PARAM 1 #define ANSILOVE_FORMAT_ERROR 2 #define ANSILOVE_MEMORY_ERROR 3 -#define ANSILOVE_FILE_ERROR 4 -#define ANSILOVE_GD_ERROR 5 +#define ANSILOVE_FILE_READ_ERROR 4 +#define ANSILOVE_FILE_WRITE_ERROR 5 +#define ANSILOVE_GD_ERROR 6 /* PC Fonts */ #define ANSILOVE_FONT_CP437 1 /* IBM PC 80x25 */ diff --git a/src/error.c b/src/error.c @@ -30,11 +30,14 @@ ansilove_error(struct ansilove_ctx *ctx) { case ANSILOVE_MEMORY_ERROR: return "Memory allocation error."; break; - case ANSILOVE_FILE_ERROR: - return "File error."; + case ANSILOVE_FILE_READ_ERROR: + return "Error reading file."; + break; + case ANSILOVE_FILE_WRITE_ERROR: + return "Error writing file."; break; case ANSILOVE_GD_ERROR: - return "GD error."; + return "GD library error."; break; default: return NULL; diff --git a/src/loadfile.c b/src/loadfile.c @@ -29,14 +29,14 @@ ansilove_loadfile(struct ansilove_ctx *ctx, char *input) { // load input file if ((fd = open(input, O_RDONLY)) == -1) { - ctx->error = ANSILOVE_FILE_ERROR; + ctx->error = ANSILOVE_FILE_READ_ERROR; close(fd); return -1; } // get the file size (bytes) if (fstat(fd, &st) == -1) { - ctx->error = ANSILOVE_FILE_ERROR; + ctx->error = ANSILOVE_FILE_READ_ERROR; close(fd); return -1; } diff --git a/src/savefile.c b/src/savefile.c @@ -30,7 +30,7 @@ ansilove_savefile(struct ansilove_ctx *ctx, char *output) { fwrite(ctx->png.buffer, ctx->png.length, 1, file); fclose(file); } else { - ctx->error = ANSILOVE_FILE_ERROR; + ctx->error = ANSILOVE_FILE_WRITE_ERROR; return -1; }