commit b1d85f619641f884401f9dcb40bea4007fdb5fe7
parent e7e789746f59971821c11794de9ff04a27332c7c
Author: Frederic Cambus <fred@statdns.com>
Date: Mon, 16 Jul 2018 20:14:38 +0200
Use ansilove_loadfile() to load input file
Diffstat:
1 file changed, 1 insertion(+), 25 deletions(-)
diff --git a/src/main.c b/src/main.c
@@ -129,9 +129,6 @@ int main(int argc, char *argv[]) {
char *input = NULL, *output = NULL;
- int fd;
- struct stat st;
-
static struct ansilove_ctx ctx;
static struct ansilove_options options;
@@ -272,26 +269,7 @@ int main(int argc, char *argv[]) {
if (!strcmp(fext, ".diz"))
options.diz = true;
- // load input file
- if ((fd = open(input, O_RDONLY)) == -1) {
- perror("File error");
- return 1;
- }
-
- // get the file size (bytes)
- if (fstat(fd, &st) == -1) {
- perror("Can't stat file");
- return 1;
- }
-
- ctx.length = st.st_size;
-
- // 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");
- return 2;
- }
+ ansilove_loadfile(&ctx, input);
// adjust the file size if file contains a SAUCE record
if (fileHasSAUCE) {
@@ -339,9 +317,7 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "Columns: %d\n", options.columns);
}
- // close input file, we don't need it anymore
// TODO: munmap, with original ctxSize
- close(fd);
}
// either display SAUCE or tell us if there is no record