Skip to content

Commit d91e910

Browse files
authored
[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
1 parent a96b224 commit d91e910

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/rcore.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -1946,25 +1946,25 @@ const char *GetFileName(const char *filePath)
19461946
// Get filename string without extension (uses static string)
19471947
const char *GetFileNameWithoutExt(const char *filePath)
19481948
{
1949-
#define MAX_FILENAMEWITHOUTEXT_LENGTH 256
1950-
1949+
#define MAX_FILENAMEWITHOUTEXT_LENGTH 256
1950+
19511951
static char fileName[MAX_FILENAMEWITHOUTEXT_LENGTH] = { 0 };
19521952
memset(fileName, 0, MAX_FILENAMEWITHOUTEXT_LENGTH);
19531953

1954-
if (filePath != NULL) strcpy(fileName, GetFileName(filePath)); // Get filename with extension
1955-
1956-
int size = (int)strlen(fileName); // Get size in bytes
1957-
1958-
for (int i = 0; (i < size) && (i < MAX_FILENAMEWITHOUTEXT_LENGTH); i++)
1954+
if (filePath != NULL)
19591955
{
1960-
if (fileName[i] == '.')
1956+
strcpy(fileName, GetFileName(filePath)); // Get filename.ext without path
1957+
int size = (int)strlen(fileName); // Get size in bytes
1958+
for (int i = size; i>0; i--) // Reverse search '.'
19611959
{
1962-
// NOTE: We break on first '.' found
1963-
fileName[i] = '\0';
1964-
break;
1960+
if (fileName[i] == '.')
1961+
{
1962+
// NOTE: We break on first '.' found
1963+
fileName[i] = '\0';
1964+
break;
1965+
}
19651966
}
19661967
}
1967-
19681968
return fileName;
19691969
}
19701970

0 commit comments

Comments
 (0)