From 730375faf738790b32e31f668813443ecdfd8150 Mon Sep 17 00:00:00 2001
From: ivn <i@ivn.cx>
Date: Thu, 14 May 2020 18:30:32 +0300
Subject: [PATCH] fix bug in GetPrevDirectoryPath on Unix-like systems (#1246)

---
 src/core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/core.c b/src/core.c
index 33caac51..ac77138c 100644
--- a/src/core.c
+++ b/src/core.c
@@ -2087,11 +2087,12 @@ const char *GetPrevDirectoryPath(const char *dirPath)
 
     if (pathLen <= 3) strcpy(prevDirPath, dirPath);
 
-    for (int i = (pathLen - 1); (i > 0) && (pathLen > 3); i--)
+    for (int i = (pathLen - 1); (i >= 0) && (pathLen > 3); i--)
     {
         if ((dirPath[i] == '\\') || (dirPath[i] == '/'))
         {
-            if (i == 2) i++;    // Check for root: "C:\"
+            if ((i == 2) && (dirPath[1] ==':') // Check for root: "C:\"
+                || i == 0) i++;                // Check for root: "/"
             strncpy(prevDirPath, dirPath, i);
             break;
         }