ADDED: IsFileNameValid()
This commit is contained in:
parent
797de0f9ad
commit
c335c3c52c
@ -1124,6 +1124,7 @@ RLAPI const char *GetWorkingDirectory(void); // Get current
|
||||
RLAPI const char *GetApplicationDirectory(void); // Get the directory of the running application (uses static string)
|
||||
RLAPI bool ChangeDirectory(const char *dir); // Change working directory, return true on success
|
||||
RLAPI bool IsPathFile(const char *path); // Check if a given path is a file or a directory
|
||||
RLAPI bool IsFileNameValid(const char *fileName); // Check if fileName is valid for the platform/OS
|
||||
RLAPI FilePathList LoadDirectoryFiles(const char *dirPath); // Load directory filepaths
|
||||
RLAPI FilePathList LoadDirectoryFilesEx(const char *basePath, const char *filter, bool scanSubdirs); // Load directory filepaths with extension filtering and recursive directory scan
|
||||
RLAPI void UnloadDirectoryFiles(FilePathList files); // Unload filepaths
|
||||
|
58
src/rcore.c
58
src/rcore.c
@ -2244,6 +2244,64 @@ bool IsPathFile(const char *path)
|
||||
return S_ISREG(result.st_mode);
|
||||
}
|
||||
|
||||
// Check if fileName is valid for the platform/OS
|
||||
bool IsFileNameValid(const char *fileName)
|
||||
{
|
||||
bool valid = true;
|
||||
|
||||
if ((fileName != NULL) && (fileName[0] != '\0'))
|
||||
{
|
||||
int length = strlen(fileName);
|
||||
bool allPeriods = true;
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
// Check invalid characters
|
||||
if ((fileName[i] == '<') ||
|
||||
(fileName[i] == '>') ||
|
||||
(fileName[i] == ':') ||
|
||||
(fileName[i] == '\"') ||
|
||||
(fileName[i] == '/') ||
|
||||
(fileName[i] == '\\') ||
|
||||
(fileName[i] == '|') ||
|
||||
(fileName[i] == '?') ||
|
||||
(fileName[i] == '*')) { valid = false; break; }
|
||||
|
||||
// Check non-glyph characters
|
||||
if ((unsigned char)fileName[i] < 32) { valid = false; break; }
|
||||
|
||||
// TODO: Check trailing periods/spaces?
|
||||
|
||||
// Check if filename is not all periods
|
||||
if (fileName[i] != '.') allPeriods = false;
|
||||
}
|
||||
|
||||
if (allPeriods) valid = false;
|
||||
|
||||
/*
|
||||
if (valid)
|
||||
{
|
||||
// Check invalid DOS names
|
||||
if (length >= 3)
|
||||
{
|
||||
if (((fileName[0] == 'C') && (fileName[1] == 'O') && (fileName[2] == 'N')) || // CON
|
||||
((fileName[0] == 'P') && (fileName[1] == 'R') && (fileName[2] == 'N')) || // PRN
|
||||
((fileName[0] == 'A') && (fileName[1] == 'U') && (fileName[2] == 'X')) || // AUX
|
||||
((fileName[0] == 'N') && (fileName[1] == 'U') && (fileName[2] == 'L'))) valid = false; // NUL
|
||||
}
|
||||
|
||||
if (length >= 4)
|
||||
{
|
||||
if (((fileName[0] == 'C') && (fileName[1] == 'O') && (fileName[2] == 'M') && ((fileName[3] >= '0') && (fileName[3] <= '9'))) || // COM0-9
|
||||
((fileName[0] == 'L') && (fileName[1] == 'P') && (fileName[2] == 'T') && ((fileName[3] >= '0') && (fileName[3] <= '9')))) valid = false; // LPT0-9
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
// Check if a file has been dropped into window
|
||||
bool IsFileDropped(void)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user