diff options
| author | Michael Vetter <jubalh@iodoru.org> | 2018-10-14 14:14:04 +0200 |
|---|---|---|
| committer | Michael Vetter <jubalh@iodoru.org> | 2018-10-14 14:21:02 +0200 |
| commit | d8331bde3a6c9781278106497be023b349b0a3fa (patch) | |
| tree | a387e09767b48a4de90e0357fdca24f3f563da62 | |
| parent | e371609a1204edf7a019e909e97b146db8517c3d (diff) | |
| download | raylib-d8331bde3a6c9781278106497be023b349b0a3fa.tar.gz raylib-d8331bde3a6c9781278106497be023b349b0a3fa.zip | |
Add FileExists() function
| -rw-r--r-- | src/core.c | 18 | ||||
| -rw-r--r-- | src/raylib.h | 1 |
2 files changed, 18 insertions, 1 deletions
@@ -135,8 +135,9 @@ #include <direct.h> // Required for: _getch(), _chdir() #define GETCWD _getcwd // NOTE: MSDN recommends not to use getcwd(), chdir() #define CHDIR _chdir + #include <io.h> // Required for _access() [Used in FileExists()] #else - #include "unistd.h" // Required for: getch(), chdir() (POSIX) + #include "unistd.h" // Required for: getch(), chdir() (POSIX), access() #define GETCWD getcwd #define CHDIR chdir #endif @@ -1514,6 +1515,21 @@ static const char *strprbrk(const char *s, const char *charset) return latestMatch; } +// Return true if the file exists +bool FileExists(const char *fileName) +{ + bool result = false; + +#if defined(_WIN32) + if (_access(fileName, 0) != -1) +#else + if (access(fileName, F_OK) != -1) +#endif + result = true; + + return result; +} + // Get pointer to filename for a path string const char *GetFileName(const char *filePath) { diff --git a/src/raylib.h b/src/raylib.h index 963df077..8aa5e7be 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -870,6 +870,7 @@ RLAPI int GetRandomValue(int min, int max); // Returns a r // Files management functions RLAPI bool IsFileExtension(const char *fileName, const char *ext);// Check file extension RLAPI const char *GetExtension(const char *fileName); // Get pointer to extension for a filename string +RLAPI bool FileExists(const char *fileName); // Return true if file exists 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 (memory should be freed) RLAPI const char *GetDirectoryPath(const char *fileName); // Get full path for a given fileName (uses static string) |
