diff options
| author | ChrisDill <chrisdude134@gmail.com> | 2018-10-12 13:53:36 +0100 |
|---|---|---|
| committer | ChrisDill <chrisdude134@gmail.com> | 2018-10-12 13:53:36 +0100 |
| commit | c2b36af60f1b2823cdeb6c8ae73a4957026d46ce (patch) | |
| tree | b0dbeabc15bf2ebe8da3883130996c7b3982c65a /src | |
| parent | 5945805b1567c20546ae294705454733f8c071f8 (diff) | |
| download | raylib-c2b36af60f1b2823cdeb6c8ae73a4957026d46ce.tar.gz raylib-c2b36af60f1b2823cdeb6c8ae73a4957026d46ce.zip | |
Added GetLastWriteTime to allow for file reloading
- Added a function to get the last write time of a file. I used this so I can reload files or resources if the time since they were last loaded changes.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core.c | 13 | ||||
| -rw-r--r-- | src/raylib.h | 1 |
2 files changed, 14 insertions, 0 deletions
@@ -123,6 +123,7 @@ #include <string.h> // Required for: strrchr(), strcmp() //#include <errno.h> // Macros for reporting and retrieving error conditions through error codes #include <ctype.h> // Required for: tolower() [Used in IsFileExtension()] +#include <sys/stat.h> // Required for stat() [Used in GetLastWriteTime()] #if defined(_MSC_VER) #include "external/dirent.h" // Required for: DIR, opendir(), closedir() [Used in GetDirectoryFiles()] @@ -1681,6 +1682,18 @@ void ClearDroppedFiles(void) #endif } +// Get the last write time of a file +long GetLastWriteTime(const char *fileName) +{ + struct stat result = {0}; + if (stat(fileName, &result) == 0) + { + time_t mod = result.st_mtime; + return mod; + } + return 0; +} + // Save integer value to storage file (to defined position) // NOTE: Storage positions is directly related to file memory layout (4 bytes each integer) void StorageSaveValue(int position, int value) diff --git a/src/raylib.h b/src/raylib.h index 9d870255..1765b40b 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -880,6 +880,7 @@ RLAPI bool ChangeDirectory(const char *dir); // Change work RLAPI bool IsFileDropped(void); // Check if a file has been dropped into window RLAPI char **GetDroppedFiles(int *count); // Get dropped files names (memory should be freed) RLAPI void ClearDroppedFiles(void); // Clear dropped files paths buffer (free memory) +RLAPI long GetLastWriteTime(const char *fileName); // Get last write time of a file // Persistent storage management RLAPI void StorageSaveValue(int position, int value); // Save integer value to storage file (to defined position) |
