summaryrefslogtreecommitdiffhomepage
path: root/src/core.c
diff options
context:
space:
mode:
authorRay <[email protected]>2020-01-26 13:01:35 +0100
committerRay <[email protected]>2020-01-26 13:01:35 +0100
commit46774a8167b061c5f438ed4ddf607669d9e9f322 (patch)
tree65804beaa642d7a40c8f89b2bd857605c0a37a89 /src/core.c
parentf28c1ef6759c587c205cdf239a06ac8b2ccac963 (diff)
downloadraylib-46774a8167b061c5f438ed4ddf607669d9e9f322.tar.gz
raylib-46774a8167b061c5f438ed4ddf607669d9e9f322.zip
REVIEWED: GetDirectoryPath()
Diffstat (limited to 'src/core.c')
-rw-r--r--src/core.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/core.c b/src/core.c
index f1016c36..e865a520 100644
--- a/src/core.c
+++ b/src/core.c
@@ -1941,16 +1941,31 @@ const char *GetFileNameWithoutExt(const char *filePath)
// Get directory for a given filePath
const char *GetDirectoryPath(const char *filePath)
{
+/*
+ // NOTE: Directory separator is different in Windows and other platforms,
+ // fortunately, Windows also support the '/' separator, that's the one should be used
+ #if defined(_WIN32)
+ char separator = '\\';
+ #else
+ char separator = '/';
+ #endif
+*/
const char *lastSlash = NULL;
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] = '/';
lastSlash = strprbrk(filePath, "\\/");
- if (!lastSlash) return NULL;
-
- // 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
+ if (lastSlash)
+ {
+ // NOTE: Be careful, strncpy() is not safe, it does not care about '\0'
+ strncpy(dirPath + 2, filePath, strlen(filePath) - (strlen(lastSlash) - 1));
+ dirPath[2 + strlen(filePath) - strlen(lastSlash)] = '\0'; // Add '\0' manually
+ }
return dirPath;
}