diff options
Diffstat (limited to 'lisiblepng-bin/src/main.c')
| -rw-r--r-- | lisiblepng-bin/src/main.c | 24 | 
1 files changed, 10 insertions, 14 deletions
diff --git a/lisiblepng-bin/src/main.c b/lisiblepng-bin/src/main.c index 116125a..47e1722 100644 --- a/lisiblepng-bin/src/main.c +++ b/lisiblepng-bin/src/main.c @@ -1,12 +1,8 @@  #include <errno.h> -#include <fcntl.h>  #include <lisiblepng.h>  #include <lisiblestd/log.h>  #include <stdio.h> -#include <stdlib.h>  #include <string.h> -#include <sys/mman.h> -#include <sys/stat.h>  #define LOG0(msg) fprintf(stderr, msg "\n")  #define LOGN(fmt, ...) fprintf(stderr, fmt "\n", __VA_ARGS__) @@ -19,19 +15,19 @@ int main(int argc, char **argv) {    }    const char *png_filepath = argv[1]; -  int fd = open(png_filepath, O_RDONLY); -  struct stat st; -  fstat(fd, &st); -  u8 *png_file_data = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); -  LOGN("File size: %ld bytes", st.st_size); +  FILE *png_file = fopen(png_filepath, "r"); +  fseek(png_file, 0, SEEK_END); +  long file_size = ftell(png_file); +  LOGN("File size: %ld bytes", file_size); +  fseek(png_file, 0, SEEK_SET); -  if (!png_file_data) { +  if (!png_file) {      const char *error_message = strerror(errno); -    LOGN("Couldn't map PNG file: %s", error_message); +    LOGN("Couldn't open PNG file: %s", error_message);      return 1;    } -  LisPng *png = LisPng_decode(png_file_data, st.st_size); +  LisPng *png = LisPng_decode(png_file);    if (!png) {      LOG0("Couldn't decode PNG");      return 1; @@ -40,9 +36,9 @@ int main(int argc, char **argv) {    LisPng_dump_ppm(png);    LisPng_destroy(png); -  if (munmap(png_file_data, st.st_size) != 0) { +  if (fclose(png_file) != 0) {      const char *error_message = strerror(errno); -    LOGN("Couldn't unmap PNG file: %s", error_message); +    LOGN("Couldn't close PNG file: %s", error_message);      return 1;    }  | 
