diff options
| author | Ray <raysan5@gmail.com> | 2018-08-25 10:51:31 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-08-25 10:51:31 +0200 |
| commit | fe2f8d77a9b2d5ed459377dbdb79cd2c70196139 (patch) | |
| tree | 13bf50e0f9f7119a0346a613ffd9d8121766af5e | |
| parent | 4259ff78e1d8df8818de178d819cb42a85694595 (diff) | |
| parent | 85213795d162ff03e48523afb854d6d6d17f27d4 (diff) | |
| download | raylib-fe2f8d77a9b2d5ed459377dbdb79cd2c70196139.tar.gz raylib-fe2f8d77a9b2d5ed459377dbdb79cd2c70196139.zip | |
Merge pull request #635 from a3f/master
core: Support slashes as well in GetFileName & GetDirectoryPath
| -rw-r--r-- | src/core.c | 24 |
1 files changed, 18 insertions, 6 deletions
@@ -1346,11 +1346,20 @@ const char *GetExtension(const char *fileName) return (dot + 1); } +/* "string pointer reverse break": return right-most occurrence of charset in s */ +static const char *strprbrk(const char *s, const char *charset) +{ + const char *latest_match = NULL; + for(; s = strpbrk(s, charset), s != NULL; latest_match=s++) + ; + return latest_match; +} + // Get pointer to filename for a path string const char *GetFileName(const char *filePath) { - const char *fileName = strrchr(filePath, '\\'); - + const char *fileName = strprbrk(filePath, "\\/"); + if (!fileName || fileName == filePath) return filePath; return fileName + 1; @@ -1360,14 +1369,17 @@ const char *GetFileName(const char *filePath) // Get directory for a given fileName (with path) const char *GetDirectoryPath(const char *fileName) { - char *lastSlash = NULL; + const char *lastSlash = NULL; static char filePath[256]; // MAX_DIRECTORY_PATH_SIZE = 256 memset(filePath, 0, 256); - - lastSlash = strrchr(fileName, '\\'); + + lastSlash = strprbrk(fileName, "\\/"); + if (!lastSlash) + return NULL; + strncpy(filePath, fileName, strlen(fileName) - (strlen(lastSlash) - 1)); filePath[strlen(fileName) - strlen(lastSlash)] = '\0'; - + return filePath; } |
