From 9a34028dd6a8526a18c1a23c21cbb86b325e1560 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 1 Nov 2009 16:41:49 -0500 Subject: [PATCH] chdir to base of app bundle on the Mac. --- Source/OpenGL_Windows.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Source/OpenGL_Windows.cpp b/Source/OpenGL_Windows.cpp index 59df351..a64f5e4 100644 --- a/Source/OpenGL_Windows.cpp +++ b/Source/OpenGL_Windows.cpp @@ -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); } -- 2.39.2