//------------------------------------------------------------------------- // // Create a new thread and run the message pump in there // //------------------------------------------------------------------------- void nsToolkit::CreateUIThread() { PRMonitor *monitor = ::PR_NewMonitor(); PR_EnterMonitor(monitor); ThreadInitInfo *ti = new ThreadInitInfo(); if (ti) { ti->monitor = monitor; ti->toolkit = this; // create a gui thread mGuiThread = PR_CreateThread(PR_SYSTEM_THREAD, RunPump, (void*)ti, PR_PRIORITY_HIGH, PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0); // wait for the gui thread to start while(gThreadState == PR_FALSE) { PR_Wait(monitor, PR_INTERVAL_NO_TIMEOUT); } } image_info iinfo; int32 cookie = 0; char *leaf = NULL; do { if (get_next_image_info(0, &cookie, &iinfo) == B_OK && strlen(iinfo.name) > 0 && (leaf = strrchr(iinfo.name, '/')) != NULL) { leaf++; mGUIThreadID = find_thread(leaf); } else { mGUIThreadID = find_thread(0); } } while(iinfo.type != B_APP_IMAGE); // at this point the thread is running PR_ExitMonitor(monitor); PR_DestroyMonitor(monitor); }
void process_refs(entry_ref dir_ref, BMessage* msg, void* reserved) { PRINT(("process_refs()\n")); msg->AddRef("dir_ref", & dir_ref); // get the path of the Tracker add-on image_info image; int32 cookie = 0; status_t status = B_OK; status = get_next_image_info(0, &cookie, &image); while (status == B_OK) { if (((char*)process_refs >= (char*)image.text && (char*)process_refs <= (char*)image.text + image.text_size) || ((char*)process_refs >= (char*)image.data && (char*)process_refs <= (char*)image.data + image.data_size)) { PRINT(("****** found our image: %s\n", image.name)); break; } status = get_next_image_info(0, &cookie, &image); } entry_ref addon_ref; if (get_ref_for_path(image.name, & addon_ref) == B_OK) { // it's better to launch Tracker add-ons by entry_ref // in the event of multiple instances with the same // applicatins signature PRINT(("Launching Tracker add-on by entry_ref.\n")); be_roster->Launch (& addon_ref, msg); } else { // if get_ref_for_path() fails we can launch by app sig PRINT(("Launching Tracker add-on by signature.\n")); BString signature = ZK_APP_SIG; app_sig_for_pathname(image.name, & signature); PRINT(("application signature: %s\n", signature.String())); be_roster->Launch (signature.String(), msg); } fflush(stdout); }
char *__PHYSFS_platformCalcBaseDir(const char *argv0) { image_info info; int32 cookie = 0; while (get_next_image_info(0, &cookie, &info) == B_OK) { if (info.type == B_APP_IMAGE) break; } /* while */ BEntry entry(info.name, true); BPath path; status_t rc = entry.GetPath(&path); /* (path) now has binary's path. */ assert(rc == B_OK); rc = path.GetParent(&path); /* chop filename, keep directory. */ assert(rc == B_OK); const char *str = path.Path(); assert(str != NULL); const size_t len = strlen(str); char *retval = (char *) allocator.Malloc(len + 2); BAIL_IF(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL); strcpy(retval, str); retval[len] = '/'; retval[len+1] = '\0'; return retval; } /* __PHYSFS_platformCalcBaseDir */
/* A function called through the vtable to open a module with this loader. Returns an opaque representation of the newly opened module for processing with this loader's other vtable functions. */ static lt_module vm_open (lt_user_data LT__UNUSED loader_data, const char *filename, lt_dladvise LT__UNUSED advise) { image_id image = 0; if (filename) { image = load_add_on (filename); } else { image_info info; int32 cookie = 0; if (get_next_image_info (0, &cookie, &info) == B_OK) image = load_add_on (info.name); } if (image <= 0) { LT__SETERROR (CANNOT_OPEN); image = 0; } return (lt_module) image; }
static void haiku_init_image_list(team_debug_info *teamDebugInfo) { int32 cookie = 0; image_info info; while (get_next_image_info(teamDebugInfo->team, &cookie, &info) == B_OK) haiku_add_image(teamDebugInfo, &info); }
void fill_pathname_application_path(char *buf, size_t size) { size_t i; (void)i; if (!size) return; #ifdef _WIN32 DWORD ret = GetModuleFileName(GetModuleHandle(NULL), buf, size - 1); buf[ret] = '\0'; #elif defined(__APPLE__) CFBundleRef bundle = CFBundleGetMainBundle(); if (bundle) { CFURLRef bundle_url = CFBundleCopyBundleURL(bundle); CFStringRef bundle_path = CFURLCopyPath(bundle_url); CFStringGetCString(bundle_path, buf, size, kCFStringEncodingUTF8); CFRelease(bundle_path); CFRelease(bundle_url); rarch_assert(strlcat(buf, "nobin", size) < size); return; } #elif defined(__HAIKU__) image_info info; int32 cookie = 0; while (get_next_image_info(0, &cookie, &info) == B_OK) { if (info.type == B_APP_IMAGE) { strlcpy(buf, info.name, size); return; } } #else *buf = '\0'; pid_t pid = getpid(); char link_path[PATH_MAX]; /* Linux, BSD and Solaris paths. Not standardized. */ static const char *exts[] = { "exe", "file", "path/a.out" }; for (i = 0; i < ARRAY_SIZE(exts); i++) { snprintf(link_path, sizeof(link_path), "/proc/%u/%s", (unsigned)pid, exts[i]); ssize_t ret = readlink(link_path, buf, size - 1); if (ret >= 0) { buf[ret] = '\0'; return; } } RARCH_ERR("Cannot resolve application path! This should not happen.\n"); #endif }
int dladdr(void *addr, Dl_info *info) { // TODO: This can be implemented more efficiently in the runtime loader. // get_library_symbol() already has the code doing that. char curSymName[NAME_MAX]; static char symName[NAME_MAX]; static char imageName[MAXPATHLEN]; void *symLocation; int32 cookie; int32 symType, symNameLength; uint32 symIndex; image_info imageInfo; if (info == NULL) return 0; imageName[0] = '\0'; symName[0] = '\0'; info->dli_fname = imageName; info->dli_saddr = NULL; info->dli_sname = symName; cookie = 0; while (get_next_image_info(0, &cookie, &imageInfo) == B_OK) { // check if the image holds the symbol if ((addr_t)addr >= (addr_t)imageInfo.text && (addr_t)addr < (addr_t)imageInfo.text + imageInfo.text_size) { strlcpy(imageName, imageInfo.name, MAXPATHLEN); info->dli_fbase = imageInfo.text; symIndex = 0; symNameLength = NAME_MAX; while (get_nth_image_symbol(imageInfo.id, symIndex, curSymName, &symNameLength, &symType, &symLocation) == B_OK) { // check if symbol is the nearest until now if (symLocation <= addr && symLocation >= info->dli_saddr) { strlcpy(symName, curSymName, NAME_MAX); info->dli_saddr = symLocation; // stop here if exact match if (info->dli_saddr == addr) return 1; } symIndex++; symNameLength = NAME_MAX; } break; } } if (info->dli_saddr != NULL) return 1; return 0; }
status_t our_image(image_info& image) { int32 cookie = 0; while (get_next_image_info(B_CURRENT_TEAM, &cookie, &image) == B_OK) { if ((char *)our_image >= (char *)image.text && (char *)our_image <= (char *)image.text + image.text_size) return B_OK; } return B_ERROR; }
status_t our_image(image_info* image) { int32 cookie = 0; status_t ret; while ((ret = get_next_image_info(0,&cookie,image)) == B_OK) { if ((char*)our_image >= (char*)image->text_part && (char*)our_image <= (char*)image->text_part + image->text_part_size) break; } return ret; }
static status_t find_own_image(image_info *info) { int32 cookie = 0; while (get_next_image_info(B_CURRENT_TEAM, &cookie, info) == B_OK) { if (((addr_t)info->text <= (addr_t)find_own_image && (addr_t)info->text + info->text_size > (addr_t)find_own_image)) { return B_OK; } } return B_NAME_NOT_FOUND; }
static status_t our_image(image_info& image) { /** @todo r=ramshankar: find a way to do this without annoying the compiler, probably uintptr_t? */ int32 cookie = 0; while (get_next_image_info(B_CURRENT_TEAM, &cookie, &image) == B_OK) { if ((char *)our_image >= (char *)image.text && (char *)our_image <= (char *)image.text + image.text_size) return B_OK; } return B_ERROR; }
status_t DebuggerInterface::GetImageInfos(BObjectList<ImageInfo>& infos) { // get the team's images image_info imageInfo; int32 cookie = 0; while (get_next_image_info(fTeamID, &cookie, &imageInfo) == B_OK) { ImageInfo* info = new(std::nothrow) ImageInfo(fTeamID, imageInfo.id, imageInfo.name, imageInfo.type, (addr_t)imageInfo.text, imageInfo.text_size, (addr_t)imageInfo.data, imageInfo.data_size); if (info == NULL || !infos.AddItem(info)) { delete info; return B_NO_MEMORY; } } // Also add the "commpage" image, which belongs to the kernel, but is used // by userland teams. cookie = 0; while (get_next_image_info(B_SYSTEM_TEAM, &cookie, &imageInfo) == B_OK) { if ((addr_t)imageInfo.text >= USER_COMMPAGE_ADDR && (addr_t)imageInfo.text < USER_COMMPAGE_ADDR + COMMPAGE_SIZE) { ImageInfo* info = new(std::nothrow) ImageInfo(B_SYSTEM_TEAM, imageInfo.id, imageInfo.name, imageInfo.type, (addr_t)imageInfo.text, imageInfo.text_size, (addr_t)imageInfo.data, imageInfo.data_size); if (info == NULL || !infos.AddItem(info)) { delete info; return B_NO_MEMORY; } break; } } return B_OK; }
static status_t find_image(const void* codePointer, image_info& _info) { int32 cookie = 0; while (get_next_image_info(B_CURRENT_TEAM, &cookie, &_info) == B_OK) { if (codePointer == NULL ? _info.type == B_APP_IMAGE : (is_in_range(codePointer, _info.text, _info.text_size) || is_in_range(codePointer, _info.data, _info.data_size))) { return B_OK; } } return B_ENTRY_NOT_FOUND; }
/* _be_sys_get_executable_name: */ extern "C" void _be_sys_get_executable_name(char *output, int size) { image_info info; int32 cookie; cookie = 0; if (get_next_image_info(0, &cookie, &info) == B_NO_ERROR) { _al_sane_strncpy(output, info.name, size); } else { _al_sane_strncpy(output, EXE_NAME_UNKNOWN, size); } output[size-1] = '\0'; }
static status_t find_own_image(image_info* _info) { int32 cookie = 0; image_info info; while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) { if (((uint32)info.text <= (uint32)find_own_image && (uint32)info.text + (uint32)info.text_size > (uint32)find_own_image)) { // found us *_info = info; return B_OK; } } return B_ENTRY_NOT_FOUND; }
image_id BImageResources::find_image(void* memAddr) const { image_info info; int32 cookie = 0; while (get_next_image_info(0, &cookie, &info) == B_OK) { if ((info.text <= memAddr && (((uint8*)info.text)+info.text_size) > memAddr) || (info.data <= memAddr && (((uint8*)info.data)+info.data_size) > memAddr)) { // Found the image. return info.id; } } return -1; }
/* finds the NetSurf binary image ID and path * */ image_id nsbeos_find_app_path(char *path) { image_info info; int32 cookie = 0; while (get_next_image_info(0, &cookie, &info) == B_OK) { //fprintf(stderr, "%p <> %p, %p\n", (char *)&find_app_resources, (char *)info.text, (char *)info.text + info.text_size); if (((char *)&nsbeos_find_app_path >= (char *)info.text) && ((char *)&nsbeos_find_app_path < (char *)info.text + info.text_size)) { //fprintf(stderr, "match\n"); if (path) { memset(path, 0, B_PATH_NAME_LENGTH); strncpy(path, info.name, B_PATH_NAME_LENGTH-1); } return info.id; } } return B_ERROR; }
status_t LocalDebuggerInterface::GetImageInfos(BObjectList<ImageInfo>& infos) { // get the team's images image_info imageInfo; int32 cookie = 0; while (get_next_image_info(fTeamID, &cookie, &imageInfo) == B_OK) { ImageInfo* info = new(std::nothrow) ImageInfo(fTeamID, imageInfo.id, imageInfo.name, imageInfo.type, (addr_t)imageInfo.text, imageInfo.text_size, (addr_t)imageInfo.data, imageInfo.data_size); if (info == NULL || !infos.AddItem(info)) { delete info; return B_NO_MEMORY; } } return B_OK; }
/** * BeOS entropy poll */ void BeOS_EntropySource::poll(Entropy_Accumulator& accum) { system_info info_sys; get_system_info(&info_sys); accum.add(info_sys, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA); key_info info_key; // current state of the keyboard get_key_info(&info_key); accum.add(info_key, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA); team_info info_team; int32 cookie_team = 0; while(get_next_team_info(&cookie_team, &info_team) == B_OK) { accum.add(info_team, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA); team_id id = info_team.team; int32 cookie = 0; thread_info info_thr; while(get_next_thread_info(id, &cookie, &info_thr) == B_OK) accum.add(info_thr, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA); cookie = 0; image_info info_img; while(get_next_image_info(id, &cookie, &info_img) == B_OK) accum.add(info_img, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA); cookie = 0; sem_info info_sem; while(get_next_sem_info(id, &cookie, &info_sem) == B_OK) accum.add(info_sem, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA); cookie = 0; area_info info_area; while(get_next_area_info(id, &cookie, &info_area) == B_OK) accum.add(info_area, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA); if(accum.polling_finished()) break; } }
// get_app_path status_t get_app_path(char *buffer) { status_t error = (buffer ? B_OK : B_BAD_VALUE); image_info info; int32 cookie = 0; bool found = false; if (error == B_OK) { while (!found && get_next_image_info(0, &cookie, &info) == B_OK) { if (info.type == B_APP_IMAGE) { strncpy(buffer, info.name, B_PATH_NAME_LENGTH); buffer[B_PATH_NAME_LENGTH] = 0; found = true; } } } if (error == B_OK && !found) error = B_ENTRY_NOT_FOUND; return error; }
void find_self(entry_ref& ref) { int32 cookie = 0; image_info info; while (get_next_image_info (0, &cookie, &info) == B_OK) { if (((addr_t)info.text <= (addr_t)move_to_deskbar && (addr_t)info.text + (size_t)info.text_size > (addr_t)move_to_deskbar) || ((addr_t)info.data <= (addr_t)move_to_deskbar && (addr_t)info.data + (size_t)info.data_size > (addr_t)move_to_deskbar)) { if (get_ref_for_path (info.name, &ref) == B_OK) return; } } // This works, but not always... :( app_info appInfo; be_roster->GetAppInfo(kSignature, &appInfo); ref = appInfo.ref; }
void VisionApp::LoadInitialSettings(void) { image_info info; int32 cookie = 0; while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) { if (info.type == B_APP_IMAGE) { BPath path(info.name); if (path.InitCheck() != B_OK) return; path.GetParent(&path); path.Append("InitialSettings"); BFile file(path.Path(), B_READ_ONLY); if (file.InitCheck() != B_OK) return; BMessage message; if (message.Unflatten(&file) != B_OK) return; fVisionSettings->Append(message); break; } } }
static gpointer _g_module_self (void) { image_info info; int32 cookie = 0; status_t status; /* Is it always the first one? I'm guessing yes. */ status = get_next_image_info (0, &cookie, &info); if (status == B_OK) return (gpointer) info.id; else { gchar *msg = g_strdup_printf ("failed to get_next_image_info(self): %s", strerror (status)); g_module_set_error (msg); g_free (msg); return NULL; } }
/*! \brief Returns the path to an application's executable. \param team The application's team ID. \param buffer A pointer to a pre-allocated character array of at least size B_PATH_NAME_LENGTH to be filled in by this function. \return - \c B_OK: Everything went fine. - \c B_BAD_VALUE: \c NULL \a buffer. - another error code */ status_t get_app_path(team_id team, char *buffer) { // The only way to get the path to the application's executable seems to // be to get an image_info of its image, which also contains a path. // Several images may belong to the team (libraries, add-ons), but only // the one in question should be typed B_APP_IMAGE. if (!buffer) return B_BAD_VALUE; image_info info; int32 cookie = 0; while (get_next_image_info(team, &cookie, &info) == B_OK) { if (info.type == B_APP_IMAGE) { strlcpy(buffer, info.name, B_PATH_NAME_LENGTH - 1); return B_OK; } } return B_ENTRY_NOT_FOUND; }
char * haiku_child_pid_to_exec_file (int pid) { static char buffer[B_PATH_NAME_LENGTH]; // The only way to get the path to the application's executable seems to // be to get an image_info of its image, which also contains a path. // Several images may belong to the team (libraries, add-ons), but only // the one in question should be typed B_APP_IMAGE. image_info info; int32 cookie = 0; while (get_next_image_info(0, &cookie, &info) == B_OK) { if (info.type == B_APP_IMAGE) { strncpy(buffer, info.name, B_PATH_NAME_LENGTH - 1); buffer[B_PATH_NAME_LENGTH - 1] = 0; return buffer; } } return NULL; }
//------------------------------------------------------------------------- // // //------------------------------------------------------------------------- NS_METHOD nsToolkit::Init(PRThread *aThread) { Kill(); // Store the thread ID of the thread containing the message pump. // If no thread is provided create one if (NULL != aThread) { mGuiThread = aThread; localthread = false; } else { localthread = true; // create a thread where the message pump will run CreateUIThread(); } cached = false; image_info iinfo; int32 cookie = 0; char *leaf = NULL; do { if (get_next_image_info(0, &cookie, &iinfo) == B_OK && strlen(iinfo.name) > 0 && (leaf = strrchr(iinfo.name, '/')) != NULL) { leaf++; mGUIThreadID = find_thread(leaf); } else { mGUIThreadID = find_thread(0); } } while(iinfo.type != B_APP_IMAGE); return NS_OK; }
TeamListItem::TeamListItem(team_info &teamInfo) : fTeamInfo(teamInfo), fAppInfo(), fMiniIcon(BRect(0, 0, 15, 15), B_RGBA32), fLargeIcon(BRect(0, 0, 31, 31), B_RGBA32), fFound(false), fRefusingToQuit(false) { int32 cookie = 0; image_info info; if (get_next_image_info(teamInfo.team, &cookie, &info) == B_OK) { fPath = BPath(info.name); BNode node(info.name); BNodeInfo nodeInfo(&node); nodeInfo.GetTrackerIcon(&fMiniIcon, B_MINI_ICON); nodeInfo.GetTrackerIcon(&fLargeIcon, B_LARGE_ICON); } if (be_roster->GetRunningAppInfo(fTeamInfo.team, &fAppInfo) != B_OK) fAppInfo.signature[0] = '\0'; CacheLocalizedName(); }
//---------------------------------------------------------------------------------------- nsresult nsDirectoryService::GetCurrentProcessDirectory(nsILocalFile** aFile) //---------------------------------------------------------------------------------------- { NS_ENSURE_ARG_POINTER(aFile); *aFile = nsnull; // Set the component registry location: if (!mService) return NS_ERROR_FAILURE; nsresult rv; nsCOMPtr<nsIProperties> dirService; rv = nsDirectoryService::Create(nsnull, NS_GET_IID(nsIProperties), getter_AddRefs(dirService)); // needs to be around for life of product if (dirService) { nsCOMPtr <nsILocalFile> aLocalFile; dirService->Get(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(aLocalFile)); if (aLocalFile) { *aFile = aLocalFile; NS_ADDREF(*aFile); return NS_OK; } } nsLocalFile* localFile = new nsLocalFile; if (localFile == nsnull) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(localFile); #ifdef 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'; localFile->InitWithNativePath(nsDependentCString(buf)); *aFile = localFile; return NS_OK; } #elif defined(XP_MAC) // get info for the the current process to determine the directory // its located in OSErr err; ProcessSerialNumber psn = {kNoProcess, kCurrentProcess}; ProcessInfoRec pInfo; FSSpec tempSpec; // initialize ProcessInfoRec before calling // GetProcessInformation() or die horribly. pInfo.processName = nil; pInfo.processAppSpec = &tempSpec; pInfo.processInfoLength = sizeof(ProcessInfoRec); err = GetProcessInformation(&psn, &pInfo); if (!err) { // create an FSSpec from the volume and dirid of the app. FSSpec appFSSpec; ::FSMakeFSSpec(pInfo.processAppSpec->vRefNum, pInfo.processAppSpec->parID, 0, &appFSSpec); nsCOMPtr<nsILocalFileMac> localFileMac = do_QueryInterface((nsIFile*)localFile); if (localFileMac) { localFileMac->InitWithFSSpec(&appFSSpec); *aFile = localFile; return NS_OK; } } #elif defined(XP_MACOSX) # ifdef MOZ_DEFAULT_VBOX_XPCOM_HOME rv = localFile->InitWithNativePath(nsDependentCString(MOZ_DEFAULT_VBOX_XPCOM_HOME)); if (NS_SUCCEEDED(rv)) *aFile = localFile; # else // Works even if we're not bundled. CFBundleRef appBundle = CFBundleGetMainBundle(); if (appBundle != nsnull) { CFURLRef bundleURL = CFBundleCopyExecutableURL(appBundle); if (bundleURL != nsnull) { CFURLRef parentURL = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, bundleURL); if (parentURL) { // Pass PR_TRUE for the "resolveAgainstBase" arg to CFURLGetFileSystemRepresentation. // This will resolve the relative portion of the CFURL against it base, giving a full // path, which CFURLCopyFileSystemPath doesn't do. char buffer[PATH_MAX]; if (CFURLGetFileSystemRepresentation(parentURL, PR_TRUE, (UInt8 *)buffer, sizeof(buffer))) { #ifdef DEBUG_conrad printf("nsDirectoryService - CurrentProcessDir is: %s\n", buffer); #endif rv = localFile->InitWithNativePath(nsDependentCString(buffer)); if (NS_SUCCEEDED(rv)) *aFile = localFile; } CFRelease(parentURL); } CFRelease(bundleURL); } } #endif NS_ASSERTION(*aFile, "nsDirectoryService - Could not determine CurrentProcessDir.\n"); if (*aFile) return NS_OK; #elif defined(XP_UNIX) // In the absence of a good way to get the executable directory let // us try this for unix: // - if VBOX_XPCOM_HOME is defined, that is it // - else give the current directory char buf[MAXPATHLEN]; #if 0 /* we need .so location. */ // Actually we have a way on linux. static volatile bool fPathSet = false; static char szPath[MAXPATHLEN]; if (!fPathSet) { char buf2[MAXPATHLEN + 3]; buf2[0] = '\0'; /* * Env.var. VBOX_XPCOM_HOME first. */ char *psz = PR_GetEnv("VBOX_XPCOM_HOME"); if (psz) { if (strlen(psz) < MAXPATHLEN) { if (!realpath(psz, buf2)) strcpy(buf2, psz); strcat(buf2, "/x"); /* for the filename stripping */ } } /* * The dynamic loader. */ if (!buf2[0]) { Dl_info DlInfo = {0}; if ( !dladdr((void *)nsDirectoryService::mService, &DlInfo) && DlInfo.dli_fname) { if (!realpath(DlInfo.dli_fname, buf2)) buf2[0] = '\0'; } } /* * Executable location. */ if (!buf2[0]) { char buf[MAXPATHLEN]; int cchLink = readlink("/proc/self/exe", buf, sizeof(buf) - 1); if (cchLink > 0 || cchLink != sizeof(buf) - 1) { buf[cchLink] = '\0'; if (!realpath(buf, buf2)) buf2[0] = '\0'; } } /* * Copy to static buffer on success. */ if (buf2[0]) { char *p = strrchr(buf2, '/'); if (p) { p[p == buf2] = '\0'; #ifdef DEBUG printf("debug: (1) VBOX_XPCOM_HOME=%s\n", buf2); #endif strcpy(szPath, buf2); fPathSet = true; } } } if (fPathSet) { localFile->InitWithNativePath(nsDependentCString(szPath)); *aFile = localFile; return NS_OK; } #endif // The MOZ_DEFAULT_VBOX_XPCOM_HOME variable can be set at configure time with // a --with-default-mozilla-five-home=foo autoconf flag. // // The idea here is to allow for builds that have a default VBOX_XPCOM_HOME // regardless of the environment. This makes it easier to write apps that // embed mozilla without having to worry about setting up the environment // // We do this py putenv()ing the default value into the environment. Note that // we only do this if it is not already set. #ifdef MOZ_DEFAULT_VBOX_XPCOM_HOME if (PR_GetEnv("VBOX_XPCOM_HOME") == nsnull) { putenv("VBOX_XPCOM_HOME=" MOZ_DEFAULT_VBOX_XPCOM_HOME); } #endif char *moz5 = PR_GetEnv("VBOX_XPCOM_HOME"); if (moz5) { if (realpath(moz5, buf)) { localFile->InitWithNativePath(nsDependentCString(buf)); *aFile = localFile; return NS_OK; } } #if defined(DEBUG) static PRBool firstWarning = PR_TRUE; if(!moz5 && firstWarning) { // Warn that VBOX_XPCOM_HOME not set, once. printf("Warning: VBOX_XPCOM_HOME not set.\n"); firstWarning = PR_FALSE; } #endif /* DEBUG */ // Fall back to current directory. if (getcwd(buf, sizeof(buf))) { localFile->InitWithNativePath(nsDependentCString(buf)); *aFile = localFile; return NS_OK; } #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 localFile->InitWithNativePath(nsDependentCString(buffer)); *aFile = localFile; return NS_OK; #elif defined(XP_BEOS) char *moz5 = getenv("VBOX_XPCOM_HOME"); if (moz5) { localFile->InitWithNativePath(nsDependentCString(moz5)); localFile->Normalize(); *aFile = localFile; return NS_OK; } 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; localFile->InitWithNativePath(nsDependentCString(buf)); *aFile = localFile; return NS_OK; } } } #endif NS_RELEASE(localFile); NS_ERROR("unable to get current process directory"); return NS_ERROR_FAILURE; } // GetCurrentProcessDirectory()
std::string GetProcessPath() { #if defined( PLATFORM_OSX ) char exe_file[PATH_MAX + 1]; CFBundleRef mainBundle = CFBundleGetMainBundle(); if (mainBundle) { CFURLRef mainURL = CFBundleCopyBundleURL(mainBundle); if (mainURL) { int ok = CFURLGetFileSystemRepresentation ( mainURL, (Boolean) true, (UInt8*)exe_file, PATH_MAX ); if (ok) { return std::string(exe_file) + "/"; } } } return "./"; #elif defined( PLATFORM_LINUX ) char exe_file[PATH_MAX + 1]; int size; size = readlink("/proc/self/exe", exe_file, PATH_MAX); if (size < 0) { return "./"; } else { exe_file[size] = '\0'; return std::string(dirname(exe_file)) + "/"; } #elif defined( PLATFORM_WIN32 ) // Get path to executable: TCHAR szDllName[_MAX_PATH]; TCHAR szDrive[_MAX_DRIVE]; TCHAR szDir[_MAX_DIR]; TCHAR szFilename[_MAX_DIR]; TCHAR szExt[_MAX_DIR]; GetModuleFileName(0, szDllName, _MAX_PATH); _splitpath(szDllName, szDrive, szDir, szFilename, szExt); return std::string(szDrive) + std::string(szDir); #elif defined( PLATFORM_BSD ) int mib[4]; mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_PATHNAME; mib[3] = -1; char buf[1024]; size_t cb = sizeof(buf); sysctl(mib, 4, buf, &cb, NULL, 0); return FileRemoveFileName( std::string( buf ) ); #elif defined( PLATFORM_SOLARIS ) return FileRemoveFileName( std::string( getexecname() ) ); #elif defined( PLATFORM_HAIKU ) image_info info; int32 cookie = 0; while ( B_OK == get_next_image_info( 0, &cookie, &info ) ) { if ( info.type == B_APP_IMAGE ) break; } return FileRemoveFileName( std::string( info.name ) ); #else #warning GetProcessPath() not implemented on this platform. ( will return "./" ) return "./"; #endif }
//---------------------------------------------------------------------------------------- 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_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 { #if defined(DEBUG) 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; } #endif /* DEBUG */ // 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()