if (gBinaryPath) return NS_NewNativeLocalFile(nsDependentCString(gBinaryPath), PR_FALSE, aResult);
XRE_GetBinaryPath(const char* argv0, nsILocalFile* *aResult){  nsresult rv;  nsCOMPtr<nsILocalFile> lf;  // We need to use platform-specific hackery to find the  // path of this executable. This is copied, with some modifications, from  // nsGREDirServiceProvider.cpp#ifdef XP_WIN  char exePath[MAXPATHLEN];  if (!::GetModuleFileName(0, exePath, MAXPATHLEN))    return NS_ERROR_FAILURE;  rv = NS_NewNativeLocalFile(nsDependentCString(exePath), PR_TRUE,                             getter_AddRefs(lf));  if (NS_FAILED(rv))    return rv;#elif defined(XP_MACOSX)  NS_NewNativeLocalFile(EmptyCString(), PR_TRUE, getter_AddRefs(lf));  nsCOMPtr<nsILocalFileMac> lfm (do_QueryInterface(lf));  if (!lfm)    return NS_ERROR_FAILURE;  // Works even if we're not bundled.  CFBundleRef appBundle = CFBundleGetMainBundle();  if (!appBundle)    return NS_ERROR_FAILURE;  CFURLRef bundleURL = CFBundleCopyExecutableURL(appBundle);  if (!bundleURL)    return NS_ERROR_FAILURE;  FSRef fileRef;  if (!CFURLGetFSRef(bundleURL, &fileRef)) {    CFRelease(bundleURL);    return NS_ERROR_FAILURE;  }  rv = lfm->InitWithFSRef(&fileRef);  CFRelease(bundleURL);  if (NS_FAILED(rv))    return rv;#elif defined(XP_UNIX)  struct stat fileStat;  char exePath[MAXPATHLEN];  rv = NS_ERROR_FAILURE;  // on unix, there is no official way to get the path of the current binary.  // instead of using the MOZILLA_FIVE_HOME hack, which doesn't scale to  // multiple applications, we will try a series of techniques:  //  // 1) look for /proc/<pid>/exe which is a symlink to the executable on newer  //    Linux kernels  // 2) use realpath() on argv[0], which works unless we're loaded from the  //    PATH  // 3) manually walk through the PATH and look for ourself  // 4) give up// #ifdef __linux__#if 0  int r = readlink("/proc/self/exe", exePath, MAXPATHLEN);  // apparently, /proc/self/exe can sometimes return weird data... check it  if (r > 0 && r < MAXPATHLEN && stat(exePath, &fileStat) == 0) {    rv = NS_OK;  }#endif  if (NS_FAILED(rv) &&      realpath(argv0, exePath) && stat(exePath, &fileStat) == 0) {    rv = NS_OK;  }  if (NS_FAILED(rv)) {    const char *path = getenv("PATH");    if (!path)      return NS_ERROR_FAILURE;    char *pathdup = strdup(path);    if (!pathdup)      return NS_ERROR_OUT_OF_MEMORY;    PRBool found = PR_FALSE;    char *newStr = pathdup;    char *token;    while ( (token = nsCRT::strtok(newStr, ":", &newStr)) ) {      sprintf(exePath, "%s/%s", token, argv0);      if (stat(exePath, &fileStat) == 0) {        found = PR_TRUE;        break;      }    }    free(pathdup);    if (!found)      return NS_ERROR_FAILURE;  }  rv = NS_NewNativeLocalFile(nsDependentCString(exePath), PR_TRUE,                             getter_AddRefs(lf));  if (NS_FAILED(rv))    return rv;#elif defined(XP_OS2)  PPIB ppib;  PTIB ptib;  char exePath[MAXPATHLEN];  DosGetInfoBlocks( &ptib, &ppib);  DosQueryModuleName( ppib->pib_hmte, MAXPATHLEN, exePath);  rv = NS_NewNativeLocalFile(nsDependentCString(exePath), PR_TRUE,                             getter_AddRefs(lf));  if (NS_FAILED(rv))    return rv;#elif defined(XP_BEOS)  int32 cookie = 0;  image_info info;  if(get_next_image_info(0, &cookie, &info) != B_OK)    return NS_ERROR_FAILURE;  rv = NS_NewNativeLocalFile(nsDependentCString(info.name), PR_TRUE,                             getter_AddRefs(lf));  if (NS_FAILED(rv))    return rv;#elif#error Oops, you need platform-specific code here#endif  NS_ADDREF(*aResult = lf);  return NS_OK;}