diff --git a/src/rcore.c b/src/rcore.c index e21c3f254..154df982a 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -1946,23 +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 + + static char fileName[MAX_FILENAMEWITHOUTEXT_LENGTH] = { 0 }; + memset(fileName, 0, MAX_FILENAMEWITHOUTEXT_LENGTH); + if (filePath != NULL) { - const char *fileName = GetFileName(filePath); // Get filename.ext without path - for (int i = (int)strlen(fileName); i>0; i--) // Reverse search '.' + 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 '.' { if (fileName[i] == '.') { - char rfileName[i]; - strncpy(rfileName, fileName,i); - rfileName[i] = '\0'; - const char* rrfileName = rfileName; - return rrfileName; + fileName[i] = '\0'; + break; } } - return fileName; // Extension not found } - return "\0"; + return fileName; } // Get directory for a given filePath