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:
parent
019cc889fc
commit
c4ba2a2b6f
1 changed files with 21 additions and 10 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue