# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1311052256 0 # Node ID 9e1d6fa397be62a1db39ef9f2dfe4a3430b96768 # Parent 8e9db23a8c311bb4eea0bc632ed74fe0d86ff619 Experimental change to set the current working directory to the bundle path on Mac. This will only occur when the current working directory is initially / so it shouldn't affect command line tools or when run without an application bundle. diff -r 8e9db23a8c31 -r 9e1d6fa397be mac/dw.m --- a/mac/dw.m Fri Jul 01 02:48:20 2011 +0000 +++ b/mac/dw.m Tue Jul 19 05:10:56 2011 +0000 @@ -8913,6 +8913,39 @@ */ int API dw_init(int newthread, int argc, char *argv[]) { + /* Correct the startup path if run from a bundle */ + if(argc > 0 && argv[0]) + { + char *pathcopy = strdup(argv[0]); + char *app = strstr(pathcopy, ".app/"); + + if(app) + { + char pathbuf[PATH_MAX]; + + *app = 0; + + getcwd(pathbuf, PATH_MAX); + + /* If run from a bundle the path seems to be / */ + if(strcmp(pathbuf, "/") == 0) + { + size_t len; + + strncpy(pathbuf, pathcopy, PATH_MAX); + + len = strlen(pathbuf); + + while(len > 0 && pathbuf[len] != '/') + { + len--; + } + pathbuf[len] = '\0'; + chdir(pathbuf); + } + } + free(pathcopy); + } /* Get the operating system version */ Gestalt(gestaltSystemVersionMajor, &DWOSMajor); Gestalt(gestaltSystemVersionMinor, &DWOSMinor);