rcore: fix GetFileNameWithoutExt returning wrong value on repeated calls

GetFileNameWithoutExt returns a pointer into a single static buffer,
so two consecutive calls return two pointers that alias the same
address. Any use of both results (snprintf, separate variables, etc.)
silently reads whichever path was written last.

Mirror the rotating-buffer idiom TextFormat uses in rtext.c (and the
rcore.c !SUPPORT_MODULE_RTEXT fallback): MAX_FILENAME_BUFFERS (default
4, overridable) slots with a rotating index. Same lifetime contract
as TextFormat. No API/ABI change.

Drive-by: fixes the pre-existing fileNameLenght -> fileNameLength
typo in the same function.
This commit is contained in:
shyraptor 2026-04-13 23:44:43 +02:00
commit c4ba2a2b6f

View file

@ -1152,7 +1152,7 @@ RLAPI int GetFileLength(const char *fileName); // Get file
RLAPI long GetFileModTime(const char *fileName); // Get file modification time (last write time)
RLAPI const char *GetFileExtension(const char *fileName); // Get pointer to extension for a filename string (includes dot: '.png')
RLAPI const char *GetFileName(const char *filePath); // Get pointer to filename for a path string
RLAPI const char *GetFileNameWithoutExt(const char *filePath); // Get filename string without extension (uses static string)
RLAPI const char *GetFileNameWithoutExt(const char *filePath); // Get filename string without extension (uses rotating static strings)
RLAPI const char *GetDirectoryPath(const char *filePath); // Get full path for a given fileName with path (uses static string)
RLAPI const char *GetPrevDirectoryPath(const char *dirPath); // Get previous directory path for a given path (uses static string)
RLAPI const char *GetWorkingDirectory(void); // Get current working directory (uses static string)