2 Commits

Author SHA1 Message Date
4bfb72d8ff [rtext] Fix TextSplit() losing the last substring when the text has MAX_TEXTSPLIT_COUNT parts (#6341) 2026-11-05 20:04:57 +07:00
4670834827 [rcore] Fix IsPathDirectory() returning true for paths that don't exist (#6368)
`IsPathDirectory()` was implemented as `!IsPathFile()`, so any path that
is not a regular file, including a missing path or an empty string, was
reported as a directory. Check the path with `stat()` and `S_ISDIR()`
instead, with the same fallback macro already used for `S_ISREG()`.
2026-11-05 19:51:10 +07:00
2 changed files with 8 additions and 4 deletions

View File

@ -182,11 +182,14 @@
#endif
#define _CRT_INTERNAL_NONSTDC_NAMES 1
#include <sys/stat.h> // Required for: stat(), S_ISREG [Used in GetFileModTime(), IsFilePath()]
#include <sys/stat.h> // Required for: stat(), S_ISREG, S_ISDIR [Used in GetFileModTime(), IsPathFile(), IsPathDirectory()]
#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif
#if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
#if defined(_WIN32) && (defined(_MSC_VER) || defined(__TINYC__))
#define DIRENT_MALLOC RL_MALLOC
@ -2880,7 +2883,8 @@ bool IsPathDirectory(const char *path)
{
bool result = false;
if (!IsPathFile(path)) result = true;
struct stat info = { 0 };
if ((stat(path, &info) == 0) && S_ISDIR(info.st_mode)) result = true;
return result;
}

View File

@ -2100,10 +2100,10 @@ char **TextSplit(const char *text, char delimiter, int *count)
else if (buffer[i] == delimiter)
{
buffer[i] = '\0'; // Set an end of string at this point
if (counter == MAX_TEXTSPLIT_COUNT) break; // No room for more substrings, keep the last one complete
buffers[counter] = buffer + i + 1;
counter++;
if (counter == MAX_TEXTSPLIT_COUNT) break;
}
}
}