commit bf29b39fd42bfc6d4b55a182b7a6548e0d2da7b5
parent 6c7bbcb14d400ac6d93ecff9e206688511fe67c4
Author: Frederic Cambus <fred@statdns.com>
Date: Fri, 19 Oct 2018 12:13:30 +0200
Return error codes in ansilove_loadfile() and ansilove_savefile()
Diffstat:
2 files changed, 4 insertions(+), 4 deletions(-)
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) {
- // perror("File error");
+ ctx->error = ANSILOVE_FILE_ERROR;
close(fd);
return -1;
}
// get the file size (bytes)
if (fstat(fd, &st) == -1) {
- // perror("Can't stat file");
+ ctx->error = ANSILOVE_FILE_ERROR;
close(fd);
return -1;
}
@@ -46,7 +46,7 @@ ansilove_loadfile(struct ansilove_ctx *ctx, char *input) {
// mmap input file into memory
ctx->buffer = mmap(NULL, ctx->length, PROT_READ, MAP_PRIVATE, fd, 0);
if (ctx->buffer == MAP_FAILED) {
- // perror("Memory error");
+ ctx->error = ANSILOVE_MEMORY_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 {
- // XXX Set error code
+ ctx->error = ANSILOVE_FILE_ERROR;
return -1;
}