diff --git a/src/fs/fs.c b/src/fs/fs.c index 3353774..2ddd6b0 100644 --- a/src/fs/fs.c +++ b/src/fs/fs.c @@ -14,21 +14,13 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I // Get file size. returns 18446744073709551615 (uint64_t maximum value) if something went wrong uint64_t file_size(char* path) { - FILE* file_stream; - uint64_t file_size; + struct stat file_stats; - file_stream = fopen(path, "rb"); - if (!file_stream) { + if (stat(path , &file_stats) != 0) { return UINT64_MAX; } - fseek(file_stream, 0, SEEK_END); - file_size = ftell(file_stream); - fseek(file_stream, 0, SEEK_SET); - - fclose(file_stream); - - return file_size; + return (uint64_t) file_stats.st_size; } // Copy file at path_src to path_dst. Does not create nonexistent directories. Returns -1 in case of an error and 0 if the operation was sucessfull diff --git a/src/fs/fs.h b/src/fs/fs.h index ca47a44..8befbc1 100644 --- a/src/fs/fs.h +++ b/src/fs/fs.h @@ -13,6 +13,11 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I #include #include #include +#include + +#if __WIN32__ +#define stat _stat64 +#endif // Get file size. returns 18446744073709551615 (uint64_t maximum value) if something went wrong uint64_t file_size(char* path); diff --git a/testing/test.c b/testing/test.c index 05bed1c..80605fe 100644 --- a/testing/test.c +++ b/testing/test.c @@ -121,7 +121,7 @@ int test_endian() { int test_fs() { if (file_size("test_img512x512.ppm") == UINT64_MAX) { - printf("[ERROR] Failed to determine file size of test ppm image"); + printf("[ERROR] Failed to determine file size of test ppm image\n"); return EXIT_FAILURE; }