diff options
| author | Clement Sibille <clements+github@lisible.xyz> | 2024-06-10 12:52:15 +0900 |
|---|---|---|
| committer | Clement Sibille <clements+github@lisible.xyz> | 2024-06-10 12:52:15 +0900 |
| commit | 8552afa1a13e7eef4a0ead8736a3e732731aac6d (patch) | |
| tree | af097e52226085e0d5b17e16ce505e3d0a146f7c /lisiblepng-bin | |
| parent | ff11942fb7abfc68e2f04350f7d0a2dde51b1d9e (diff) | |
Revert "Make LisPng_decode use a u8* instead of a FILE*"
This reverts commit ff11942fb7abfc68e2f04350f7d0a2dde51b1d9e.
Diffstat (limited to 'lisiblepng-bin')
| -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; } |
