diff options
| author | oblerion <[email protected]> | 2024-02-04 11:28:58 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-02-04 11:28:58 +0100 |
| commit | d91e9104aab9ef329ac946d37033578c6becec78 (patch) | |
| tree | 10fe6c99651e32aab68f8d4a7c0e814617e01bfd /src | |
| parent | a96b224b384c7be1f97dcd0dbdcf858d97660ffd (diff) | |
| download | raylib-d91e9104aab9ef329ac946d37033578c6becec78.tar.gz raylib-d91e9104aab9ef329ac946d37033578c6becec78.zip | |
[rcore] Fix `GetFileNameWithoutExt()` (#3771)
* Update rcore.c
fix [rcore] GetFileNameWithoutExt
* Update rcore.c
* Update rcore.c
* Update rcore.c
* Update rcore.c
* Update rcore.c
* Update rcore.c
* Update rcore.c
* Update rcore.c
* Update rcore.c
* Update rcore.c
* Update rcore.c
Diffstat (limited to 'src')
| -rw-r--r-- | src/rcore.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/rcore.c b/src/rcore.c index f0af87f9..8dc14c3b 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -1946,25 +1946,25 @@ const char *GetFileName(const char *filePath) // Get filename string without extension (uses static string) const char *GetFileNameWithoutExt(const char *filePath) { - #define MAX_FILENAMEWITHOUTEXT_LENGTH 256 - + #define MAX_FILENAMEWITHOUTEXT_LENGTH 256 + static char fileName[MAX_FILENAMEWITHOUTEXT_LENGTH] = { 0 }; memset(fileName, 0, MAX_FILENAMEWITHOUTEXT_LENGTH); - if (filePath != NULL) strcpy(fileName, GetFileName(filePath)); // Get filename with extension - - int size = (int)strlen(fileName); // Get size in bytes - - for (int i = 0; (i < size) && (i < MAX_FILENAMEWITHOUTEXT_LENGTH); i++) + if (filePath != NULL) { - if (fileName[i] == '.') + strcpy(fileName, GetFileName(filePath)); // Get filename.ext without path + int size = (int)strlen(fileName); // Get size in bytes + for (int i = size; i>0; i--) // Reverse search '.' { - // NOTE: We break on first '.' found - fileName[i] = '\0'; - break; + if (fileName[i] == '.') + { + // NOTE: We break on first '.' found + fileName[i] = '\0'; + break; + } } } - return fileName; } |
