]> git.jsancho.org Git - lugaru.git/commitdiff
chdir to base of app bundle on the Mac.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 1 Nov 2009 21:41:49 +0000 (16:41 -0500)
committerRyan C. Gordon <icculus@icculus.org>
Sun, 1 Nov 2009 21:41:49 +0000 (16:41 -0500)
Source/OpenGL_Windows.cpp

index 59df351e4574ceea0416e978c3e18ddb1757ef52..a64f5e4408f3bda69737bacc04f7f2834fdfb4b9 100644 (file)
@@ -1442,6 +1442,19 @@ static inline void chdirToAppPath(const char *argv0)
     char *dir = calcBaseDir(argv0);
     if (dir)
     {
+        #if (defined(__APPLE__) && defined(__MACH__))
+        // Chop off /Contents/MacOS if it's at the end of the string, so we
+        //  land in the base of the app bundle.
+        const size_t len = strlen(dir);
+        const char *bundledirs = "/Contents/MacOS";
+        const size_t bundledirslen = strlen(bundledirs);
+        if (len > bundledirslen)
+        {
+            char *ptr = (dir + len) - bundledirslen;
+            if (strcasecmp(ptr, bundledirs) == 0)
+                *ptr = '\0';
+        }
+        #endif
         chdir(dir);
         free(dir);
     }