Browse Source

[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
pull/3780/head
oblerion 10 months ago
committed by GitHub
parent
commit
d91e9104aa
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 12 deletions
  1. +12
    -12
      src/rcore.c

+ 12
- 12
src/rcore.c View File

@ -1946,25 +1946,25 @@ const char *GetFileName(const char *filePath)
// Get filename string without extension (uses static string) // Get filename string without extension (uses static string)
const char *GetFileNameWithoutExt(const char *filePath) const char *GetFileNameWithoutExt(const char *filePath)
{ {
#define MAX_FILENAMEWITHOUTEXT_LENGTH 256
#define MAX_FILENAMEWITHOUTEXT_LENGTH 256
static char fileName[MAX_FILENAMEWITHOUTEXT_LENGTH] = { 0 }; static char fileName[MAX_FILENAMEWITHOUTEXT_LENGTH] = { 0 };
memset(fileName, 0, MAX_FILENAMEWITHOUTEXT_LENGTH); 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; return fileName;
} }

Loading…
Cancel
Save