REVIEWED: GetDirectoryPath()
Check if provided path is a full path containing system root letter: C:\
This commit is contained in:
parent
aa3b413390
commit
87d5b51256
1 changed files with 11 additions and 6 deletions
17
src/core.c
17
src/core.c
|
@ -1964,17 +1964,22 @@ const char *GetDirectoryPath(const char *filePath)
|
||||||
static char dirPath[MAX_FILEPATH_LENGTH];
|
static char dirPath[MAX_FILEPATH_LENGTH];
|
||||||
memset(dirPath, 0, MAX_FILEPATH_LENGTH);
|
memset(dirPath, 0, MAX_FILEPATH_LENGTH);
|
||||||
|
|
||||||
// For security, we set starting path to current directory,
|
// In case provided path does not contains a root drive letter (C:\, D:\),
|
||||||
// obtained path will be concated to this
|
// we add the current directory path to dirPath
|
||||||
//dirPath[0] = '.';
|
if (filePath[1] != ':')
|
||||||
//dirPath[1] = '/';
|
{
|
||||||
|
// For security, we set starting path to current directory,
|
||||||
|
// obtained path will be concated to this
|
||||||
|
dirPath[0] = '.';
|
||||||
|
dirPath[1] = '/';
|
||||||
|
}
|
||||||
|
|
||||||
lastSlash = strprbrk(filePath, "\\/");
|
lastSlash = strprbrk(filePath, "\\/");
|
||||||
if (lastSlash)
|
if (lastSlash)
|
||||||
{
|
{
|
||||||
// NOTE: Be careful, strncpy() is not safe, it does not care about '\0'
|
// NOTE: Be careful, strncpy() is not safe, it does not care about '\0'
|
||||||
strncpy(dirPath, filePath, strlen(filePath) - (strlen(lastSlash) - 1));
|
strncpy(dirPath + ((filePath[1] != ':')? 2 : 0), filePath, strlen(filePath) - (strlen(lastSlash) - 1));
|
||||||
dirPath[strlen(filePath) - strlen(lastSlash)] = '\0'; // Add '\0' manually
|
dirPath[strlen(filePath) - strlen(lastSlash) + ((filePath[1] != ':')? 2 : 0)] = '\0'; // Add '\0' manually
|
||||||
}
|
}
|
||||||
|
|
||||||
return dirPath;
|
return dirPath;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue