summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRay <[email protected]>2020-02-11 19:12:49 +0100
committerRay <[email protected]>2020-02-11 19:12:49 +0100
commit87d5b51256118cdf00c8d6c02133b0f65c52fcca (patch)
treeb1d6c7d4b5f46953b2f3f41274026d20f1ae8bea
parentaa3b4133909ad0b8a384fdf1795cf3ead5a35e12 (diff)
downloadraylib-87d5b51256118cdf00c8d6c02133b0f65c52fcca.tar.gz
raylib-87d5b51256118cdf00c8d6c02133b0f65c52fcca.zip
REVIEWED: GetDirectoryPath()
Check if provided path is a full path containing system root letter: C:\
-rw-r--r--src/core.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/core.c b/src/core.c
index 44b5b98b..80ea9646 100644
--- a/src/core.c
+++ b/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;