comparison mac/dw.m @ 1098:9e1d6fa397be

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.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 19 Jul 2011 05:10:56 +0000
parents 25707e9f5ad1
children d1cea9be1436
comparison
equal deleted inserted replaced
1097:8e9db23a8c31 1098:9e1d6fa397be
8911 * newthread: True if this is the only thread. 8911 * newthread: True if this is the only thread.
8912 * False if there is already a message loop running. 8912 * False if there is already a message loop running.
8913 */ 8913 */
8914 int API dw_init(int newthread, int argc, char *argv[]) 8914 int API dw_init(int newthread, int argc, char *argv[])
8915 { 8915 {
8916 /* Correct the startup path if run from a bundle */
8917 if(argc > 0 && argv[0])
8918 {
8919 char *pathcopy = strdup(argv[0]);
8920 char *app = strstr(pathcopy, ".app/");
8921
8922 if(app)
8923 {
8924 char pathbuf[PATH_MAX];
8925
8926 *app = 0;
8927
8928 getcwd(pathbuf, PATH_MAX);
8929
8930 /* If run from a bundle the path seems to be / */
8931 if(strcmp(pathbuf, "/") == 0)
8932 {
8933 size_t len;
8934
8935 strncpy(pathbuf, pathcopy, PATH_MAX);
8936
8937 len = strlen(pathbuf);
8938
8939 while(len > 0 && pathbuf[len] != '/')
8940 {
8941 len--;
8942 }
8943 pathbuf[len] = '\0';
8944 chdir(pathbuf);
8945 }
8946 }
8947 free(pathcopy);
8948 }
8916 /* Get the operating system version */ 8949 /* Get the operating system version */
8917 Gestalt(gestaltSystemVersionMajor, &DWOSMajor); 8950 Gestalt(gestaltSystemVersionMajor, &DWOSMajor);
8918 Gestalt(gestaltSystemVersionMinor, &DWOSMinor); 8951 Gestalt(gestaltSystemVersionMinor, &DWOSMinor);
8919 Gestalt(gestaltSystemVersionBugFix, &DWOSBuild); 8952 Gestalt(gestaltSystemVersionBugFix, &DWOSBuild);
8920 /* Create the application object */ 8953 /* Create the application object */