Browse Source

REVIEWED: GetDirectoryPath()

Check if provided path is a full path containing system root letter: C:\
pull/1097/head
Ray 5 years ago
parent
commit
87d5b51256
1 changed files with 11 additions and 6 deletions
  1. +11
    -6
      src/core.c

+ 11
- 6
src/core.c View File

@ -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…
Cancel
Save