From 5cef881ae672a408b6d47665f52398b1bb9fa573 Mon Sep 17 00:00:00 2001 From: oblerion <82583559+oblerion@users.noreply.github.com> Date: Thu, 1 Feb 2024 14:03:00 +0100 Subject: [PATCH] Update rcore.c fix [rcore] GetFileNameWithoutExt --- src/rcore.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/rcore.c b/src/rcore.c index f0af87f9d..0c7a88ce6 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -1946,26 +1946,17 @@ 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) 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++) + const char *filename = GetFileName(filePath); + int pos = TextLength(filename); + for(int i = pos; i>0; i--) { - if (fileName[i] == '.') + if(filename[i] == '.') { - // NOTE: We break on first '.' found - fileName[i] = '\0'; + pos = i; break; } } - - return fileName; + return TextSubtext(filename,0,pos); } // Get directory for a given filePath