From 1866be047578fbe38e3e857ae047ce84d92870ee Mon Sep 17 00:00:00 2001 From: Gil Barbosa Reis Date: Sat, 16 Jan 2021 06:33:13 -0300 Subject: Fix absolute path handling in GetFileName and GetDirectoryPath (#1534) (#1535) --- src/core.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/core.c b/src/core.c index 15aab363..3cac4796 100644 --- a/src/core.c +++ b/src/core.c @@ -2353,7 +2353,7 @@ const char *GetFileName(const char *filePath) const char *fileName = NULL; if (filePath != NULL) fileName = strprbrk(filePath, "\\/"); - if (!fileName || (fileName == filePath)) return filePath; + if (!fileName) return filePath; return fileName + 1; } @@ -2399,9 +2399,9 @@ const char *GetDirectoryPath(const char *filePath) static char dirPath[MAX_FILEPATH_LENGTH]; memset(dirPath, 0, MAX_FILEPATH_LENGTH); - // In case provided path does not contains a root drive letter (C:\, D:\), + // In case provided path does not contain a root drive letter (C:\, D:\) nor leading path separator (\, /), // we add the current directory path to dirPath - if (filePath[1] != ':') + if (filePath[1] != ':' && filePath[0] != '\\' && filePath[0] != '/') { // For security, we set starting path to current directory, // obtained path will be concated to this @@ -2412,9 +2412,18 @@ const char *GetDirectoryPath(const char *filePath) lastSlash = strprbrk(filePath, "\\/"); if (lastSlash) { - // NOTE: Be careful, strncpy() is not safe, it does not care about '\0' - memcpy(dirPath + ((filePath[1] != ':')? 2 : 0), filePath, strlen(filePath) - (strlen(lastSlash) - 1)); - dirPath[strlen(filePath) - strlen(lastSlash) + ((filePath[1] != ':')? 2 : 0)] = '\0'; // Add '\0' manually + if (lastSlash == filePath) + { + // The last and only slash is the leading one: path is in a root directory + dirPath[0] = filePath[0]; + dirPath[1] = '\0'; + } + else + { + // NOTE: Be careful, strncpy() is not safe, it does not care about '\0' + memcpy(dirPath + (filePath[1] != ':' && filePath[0] != '\\' && filePath[0] != '/' ? 2 : 0), filePath, strlen(filePath) - (strlen(lastSlash) - 1)); + dirPath[strlen(filePath) - strlen(lastSlash) + (filePath[1] != ':' && filePath[0] != '\\' && filePath[0] != '/' ? 2 : 0)] = '\0'; // Add '\0' manually + } } return dirPath; -- cgit v1.2.3 From 6cc27e979769affcc9d094143c03efd5872e70b9 Mon Sep 17 00:00:00 2001 From: hristo Date: Sat, 16 Jan 2021 15:04:01 +0200 Subject: Fix cmake build error dirent (#1536) * Better ignore support for idea projects. Added a wildcard at the end because different configurations would have a diffeerent build directory. * Removed external from being a relative include directory for target raylib. Fixes #1533 --- .gitignore | 2 +- src/CMakeLists.txt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/.gitignore b/.gitignore index 2a23619e..d51b5bcd 100644 --- a/.gitignore +++ b/.gitignore @@ -82,7 +82,7 @@ DerivedData/ # Jetbrains project .idea/ -cmake-build-debug/ +cmake-build-*/ # CMake stuff CMakeCache.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b94ac149..3319ef03 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -105,7 +105,6 @@ target_include_directories(raylib $ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/external ${CMAKE_BINARY_DIR} # For cmake/config.h ${OPENGL_INCLUDE_DIR} ${OPENAL_INCLUDE_DIR} -- cgit v1.2.3