diff options
| author | raysan5 <[email protected]> | 2022-01-27 14:07:05 +0100 |
|---|---|---|
| committer | raysan5 <[email protected]> | 2022-01-27 14:07:05 +0100 |
| commit | 0f00c41aad3a60f64481172bd11f8b4120963dc3 (patch) | |
| tree | 69b5f2699e5b946e30a3f9e0b8b8f9affb3fd0dd /src | |
| parent | 524bf57b74f443052a90d7a61534dab86a99cda7 (diff) | |
| download | raylib-0f00c41aad3a60f64481172bd11f8b4120963dc3.tar.gz raylib-0f00c41aad3a60f64481172bd11f8b4120963dc3.zip | |
ADDED: `GetFileSize()`
Diffstat (limited to 'src')
| -rw-r--r-- | src/raylib.h | 1 | ||||
| -rw-r--r-- | src/rcore.c | 17 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/raylib.h b/src/raylib.h index 228983d5..ab8892cc 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1041,6 +1041,7 @@ RLAPI bool SaveFileText(const char *fileName, char *text); // Save text d RLAPI bool FileExists(const char *fileName); // Check if file exists RLAPI bool DirectoryExists(const char *dirPath); // Check if a directory path exists RLAPI bool IsFileExtension(const char *fileName, const char *ext); // Check file extension (including point: .png, .wav) +RLAPI int GetFileSize(const char *fileName); // Get file size in bytes RLAPI const char *GetFileExtension(const char *fileName); // Get pointer to extension for a filename string (includes dot: '.png') RLAPI const char *GetFileName(const char *filePath); // Get pointer to filename for a path string RLAPI const char *GetFileNameWithoutExt(const char *filePath); // Get filename string without extension (uses static string) diff --git a/src/rcore.c b/src/rcore.c index 70cc350b..83b6a884 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -2851,6 +2851,23 @@ bool DirectoryExists(const char *dirPath) return result; } +// Get file size in bytes +int GetFileSize(const char *fileName) +{ + int size = 0; + + FILE *file = fopen(fileName, "rb"); + + if (file != NULL) + { + fseek(file, 0L, SEEK_END); + size = (int)ftell(file); + fclose(file); + } + + return size; +} + // Get pointer to extension for a filename string (includes the dot: .png) const char *GetFileExtension(const char *fileName) { |
