pInfo.processName = nil; pInfo.processAppSpec = &tempSpec; pInfo.processInfoLength = sizeof(ProcessInfoRec);
Str255 name; CInfoPBRec catInfo; catInfo.dirInfo.ioCompletion = NULL; catInfo.dirInfo.ioNamePtr = (StringPtr)&name; catInfo.dirInfo.ioVRefNum = appFSSpec.vRefNum; catInfo.dirInfo.ioDrDirID = theDirID; catInfo.dirInfo.ioFDirIndex = -1;
static void GetCurrentProcessDirectory(nsFileSpec& aFileSpec)//----------------------------------------------------------------------------------------{#if defined (XP_WIN)    char buf[MAX_PATH];    if ( ::GetModuleFileName(0, buf, sizeof(buf)) ) {        // chop of the executable name by finding the rightmost backslash        char* lastSlash = PL_strrchr(buf, '\\');        if (lastSlash)            *(lastSlash + 1) = '\0';        aFileSpec = buf;        return;    }#elif defined(XP_OS2)    PPIB ppib;    PTIB ptib;    char buffer[CCHMAXPATH];    DosGetInfoBlocks( &ptib, &ppib);    DosQueryModuleName( ppib->pib_hmte, CCHMAXPATH, buffer);    *strrchr( buffer, '\\') = '\0'; // XXX DBCS misery    aFileSpec = buffer;    return;#elif defined(XP_MAC)    // get info for the the current process to determine the directory    // its located in    OSErr err;    ProcessSerialNumber psn;    if (!(err = GetCurrentProcess(&psn)))    {        ProcessInfoRec pInfo;        FSSpec         tempSpec;        // initialize ProcessInfoRec before calling        // GetProcessInformation() or die horribly.        pInfo.processName = nil;        pInfo.processAppSpec = &tempSpec;        pInfo.processInfoLength = sizeof(ProcessInfoRec);        if (!(err = GetProcessInformation(&psn, &pInfo)))        {            FSSpec appFSSpec = *(pInfo.processAppSpec);            long theDirID = appFSSpec.parID;            Str255 name;            CInfoPBRec catInfo;            catInfo.dirInfo.ioCompletion = NULL;            catInfo.dirInfo.ioNamePtr = (StringPtr)&name;            catInfo.dirInfo.ioVRefNum = appFSSpec.vRefNum;            catInfo.dirInfo.ioDrDirID = theDirID;            catInfo.dirInfo.ioFDirIndex = -1; // -1 = query dir in ioDrDirID            if (!(err = PBGetCatInfoSync(&catInfo)))            {                aFileSpec = nsFileSpec(appFSSpec.vRefNum,                                       catInfo.dirInfo.ioDrParID,                                       name,                                       PR_TRUE);                return;            }        }    }#elif defined(XP_UNIX)    // In the absence of a good way to get the executable directory let    // us try this for unix:    //	- if MOZILLA_FIVE_HOME is defined, that is it    //	- else give the current directory    char buf[MAXPATHLEN];    char *moz5 = PR_GetEnv("MOZILLA_FIVE_HOME");    if (moz5)    {        aFileSpec = moz5;        return;    }    else    {        static PRBool firstWarning = PR_TRUE;        if(firstWarning) {            // Warn that MOZILLA_FIVE_HOME not set, once.            printf("Warning: MOZILLA_FIVE_HOME not set.\n");            firstWarning = PR_FALSE;        }        // Fall back to current directory.        if (getcwd(buf, sizeof(buf)))        {            aFileSpec = buf;            return;        }    }#elif defined(XP_BEOS)    char *moz5 = getenv("MOZILLA_FIVE_HOME");    if (moz5)    {        aFileSpec = moz5;        return;    }    else    {      static char buf[MAXPATHLEN];      int32 cookie = 0;      image_info info;      char *p;      *buf = 0;      if(get_next_image_info(0, &cookie, &info) == B_OK)      {        strcpy(buf, info.name);        if((p = strrchr(buf, '/')) != 0)        {          *p = 0;          aFileSpec = buf;          return;        }      }    }#endif    NS_ERROR("unable to get current process directory");} // GetCurrentProcessDirectory()