diff options
| author | Ray <[email protected]> | 2020-02-11 19:12:49 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2020-02-11 19:12:49 +0100 |
| commit | 87d5b51256118cdf00c8d6c02133b0f65c52fcca (patch) | |
| tree | b1d6c7d4b5f46953b2f3f41274026d20f1ae8bea /src | |
| parent | aa3b4133909ad0b8a384fdf1795cf3ead5a35e12 (diff) | |
| download | raylib-87d5b51256118cdf00c8d6c02133b0f65c52fcca.tar.gz raylib-87d5b51256118cdf00c8d6c02133b0f65c52fcca.zip | |
REVIEWED: GetDirectoryPath()
Check if provided path is a full path containing system root letter: C:\
Diffstat (limited to 'src')
| -rw-r--r-- | src/core.c | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -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; |
