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];
|
||||
memset(dirPath, 0, MAX_FILEPATH_LENGTH);
|
||||
|
||||
// For security, we set starting path to current directory,
|
||||
// obtained path will be concated to this
|
||||
//dirPath[0] = '.';
|
||||
//dirPath[1] = '/';
|
||||
// In case provided path does not contains a root drive letter (C:\, D:\),
|
||||
// we add the current directory path to dirPath
|
||||
if (filePath[1] != ':')
|
||||
{
|
||||
// For security, we set starting path to current directory,
|
||||
// obtained path will be concated to this
|
||||
dirPath[0] = '.';
|
||||
dirPath[1] = '/';
|
||||
}
|
||||
|
||||
lastSlash = strprbrk(filePath, "\\/");
|
||||
if (lastSlash)
|
||||
{
|
||||
// NOTE: Be careful, strncpy() is not safe, it does not care about '\0'
|
||||
strncpy(dirPath, filePath, strlen(filePath) - (strlen(lastSlash) - 1));
|
||||
dirPath[strlen(filePath) - strlen(lastSlash)] = '\0'; // Add '\0' manually
|
||||
strncpy(dirPath + ((filePath[1] != ':')? 2 : 0), filePath, strlen(filePath) - (strlen(lastSlash) - 1));
|
||||
dirPath[strlen(filePath) - strlen(lastSlash) + ((filePath[1] != ':')? 2 : 0)] = '\0'; // Add '\0' manually
|
||||
}
|
||||
|
||||
return dirPath;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue