VOID prcReport16(PQPROCESS16 pProcess, PPRCPROCESS pprcp) { if (pProcess) { PQTHREAD16 pThread; int i; DosQueryModuleName(pProcess->usHModule, sizeof(pprcp->szModuleName), pprcp->szModuleName); // DosGetPrty(PRTYS_PROCESS, &(pprcp->usPriority), pProcess->usPID); // sum up CPU time for process for (pprcp->ulCPU = 0, i = 0, pThread = (PQTHREAD16)PTR(pProcess->ulThreadList, 0); i < pProcess->usThreads; i++, pThread++ ) { pprcp->ulCPU += (pThread->ulSysTime + pThread->ulUserTime); } pprcp->usPID = pProcess->usPID; pprcp->usParentPID = pProcess->usParentPID; pprcp->usThreads = pProcess->usThreads; pprcp->ulSID = pProcess->ulSID; pprcp->ulSessionType = pProcess->ulSessionType; pprcp->ulStatus = pProcess->ulStatus; } }
static void spawn_child(int slot) { PPIB ppib; PTIB ptib; char fail_module[100]; char progname[CCHMAXPATH]; RESULTCODES proc_rc; ULONG rc; ap_scoreboard_image->parent[slot].generation = ap_my_generation; DosGetInfoBlocks(&ptib, &ppib); DosQueryModuleName(ppib->pib_hmte, sizeof(progname), progname); rc = DosExecPgm(fail_module, sizeof(fail_module), EXEC_ASYNCRESULT, ppib->pib_pchcmd, NULL, &proc_rc, progname); if (rc) { ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(rc), ap_server_conf, "error spawning child, slot %d", slot); } if (ap_max_daemons_limit < slot) { ap_max_daemons_limit = slot; } ap_scoreboard_image->parent[slot].pid = proc_rc.codeTerminate; }
wstring GetHandlerPath(void * pHandler) { HMODULE *handler = (HMODULE *)pHandler HMODULE hmod = *handler; char module_name[CCHMAXPATH]; char *result; int rc; module_name[0] = '\0'; /* return values 0 NO_ERROR 6 ERROR_INVALID_HANDLE 24 ERROR_BAD_LENGTH */ rc = DosQueryModuleName(*hmod2, sizeof module_name, module_name); if (rc ) { std::cerr << "DosQueryModuleName of " << handler << " failed: (ret: " << rc << ")"<< std::endl; } else { #if defined(_OS2_LIBDEBUG) std::cerr << "DosQueryModuleName of " << handler << " succeeded. " << std::endl; #endif } return WidenString(module_name); }
static void GetObjectInfo( ULONG mte ) { HFILE hdl; ULONG new_head; USHORT type; unsigned_32 objoff; unsigned_32 numobjs; char buff[CCHMAXPATH]; if( mte == LastMTE ) { return; } memset( ObjInfo, 0, sizeof( ObjInfo ) ); DosQueryModuleName( mte, sizeof( buff ), buff ); NumObjects = 0; if( !FindNewHeader( buff, &hdl, &new_head, &type ) ) { return; } if( type != EXE_LE && type != EXE_LX ) { DosClose( hdl ); return; } SeekRead( hdl, new_head + 0x40, &objoff, sizeof( objoff ) ); SeekRead( hdl, new_head + 0x44, &numobjs, sizeof( numobjs ) ); if( numobjs <= MAX_OBJECTS ) { SeekRead( hdl, new_head + objoff, ObjInfo, numobjs * sizeof( ObjInfo[0] ) ); NumObjects = numobjs; } LastMTE = mte; DosClose( hdl ); }
int __PHYSFS_platformInit(void) { char buf[CCHMAXPATH]; APIRET rc; PTIB ptib; PPIB ppib; PHYSFS_sint32 len; assert(baseDir == NULL); BAIL_IF_MACRO(os2err(DosGetInfoBlocks(&ptib, &ppib)) != NO_ERROR, NULL, 0); rc = DosQueryModuleName(ppib->pib_hmte, sizeof (buf), (PCHAR) buf); BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0); /* chop off filename, leave path. */ for (len = strlen(buf) - 1; len >= 0; len--) { if (buf[len] == '\\') { buf[len] = '\0'; break; } /* if */ } /* for */ assert(len > 0); /* should have been a "x:\\" on the front on string. */ /* The string is capitalized! Figure out the REAL case... */ cvt_path_to_correct_case(buf); baseDir = (char *) malloc(len + 1); BAIL_IF_MACRO(baseDir == NULL, ERR_OUT_OF_MEMORY, 0); strcpy(baseDir, buf); return(1); /* success. */ } /* __PHYSFS_platformInit */
unsigned long _System _DLL_InitTerm (unsigned long hModule, unsigned long ulFlag) { static char location[CCHMAXPATH]; switch (ulFlag) { case 0: if (_CRT_init () == -1) return 0; __ctordtorInit(); /* See http://cyberkinetica.homeunix.net/os2tk45/cp1/1247_L2H_DosQueryModuleNameSy.html for specification of DosQueryModuleName(). */ if (DosQueryModuleName (hModule, sizeof (location), location)) return 0; _fnslashify (location); shared_library_fullname = strdup (location); break; case 1: __ctordtorTerm(); _CRT_term (); break; } return 1; }
/** * Lazily initialize the two application directory paths. */ static void kldrDyldFindLazyInitAppDir(void) { if (!kLdrDyldAppDir[0]) { #if K_OS == K_OS_DARWIN /** @todo implement this! */ kLdrDyldWindowsAppDir[0] = kLdrDyldAppDir[0] = '.'; kLdrDyldWindowsAppDir[1] = kLdrDyldAppDir[1] = '\0'; #elif K_OS == K_OS_LINUX KSSIZE cch = kHlpSys_readlink("/proc/self/exe", kLdrDyldAppDir, sizeof(kLdrDyldAppDir) - 1); if (cch > 0) { kLdrDyldAppDir[cch] = '\0'; *kHlpGetFilename(kLdrDyldAppDir) = '\0'; kHlpMemCopy(kLdrDyldWindowsAppDir, kLdrDyldAppDir, sizeof(kLdrDyldAppDir)); } else { kLdrDyldWindowsAppDir[0] = kLdrDyldAppDir[0] = '.'; kLdrDyldWindowsAppDir[1] = kLdrDyldAppDir[1] = '\0'; } #elif K_OS == K_OS_OS2 PPIB pPib; PTIB pTib; APIRET rc; DosGetInfoBlocks(&pTib, &pPib); rc = DosQueryModuleName(pPib->pib_hmte, sizeof(kLdrDyldAppDir), kLdrDyldAppDir); if (!rc) { *kHlpGetFilename(kLdrDyldAppDir) = '\0'; kHlpMemCopy(kLdrDyldWindowsAppDir, kLdrDyldAppDir, sizeof(kLdrDyldAppDir)); } else { kLdrDyldWindowsAppDir[0] = kLdrDyldAppDir[0] = '.'; kLdrDyldWindowsAppDir[1] = kLdrDyldAppDir[1] = '\0'; } #elif K_OS == K_OS_WINDOWS DWORD dwSize = GetModuleFileName(NULL /* the executable */, kLdrDyldAppDir, sizeof(kLdrDyldAppDir)); if (dwSize > 0) { *kHlpGetFilename(kLdrDyldAppDir) = '\0'; kHlpMemCopy(kLdrDyldWindowsAppDir, kLdrDyldAppDir, sizeof(kLdrDyldAppDir)); } else { kLdrDyldWindowsAppDir[0] = kLdrDyldAppDir[0] = '.'; kLdrDyldWindowsAppDir[1] = kLdrDyldAppDir[1] = '\0'; } #else # error "Port me" #endif } }
static void get_progpath(void) { extern char *Py_GetProgramName(void); char *path = getenv("PATH"); char *prog = Py_GetProgramName(); PPIB pib; if ((DosGetInfoBlocks(NULL, &pib) == 0) && (DosQueryModuleName(pib->pib_hmte, sizeof(progpath), progpath) == 0)) return; if (prog == NULL || *prog == '\0') prog = "python"; /* If there is no slash in the argv0 path, then we have to * assume python is on the user's $PATH, since there's no * other way to find a directory to start the search from. If * $PATH isn't exported, you lose. */ #ifdef ALTSEP if (strchr(prog, SEP) || strchr(prog, ALTSEP)) #else if (strchr(prog, SEP)) #endif strncpy(progpath, prog, MAXPATHLEN); else if (path) { while (1) { char *delim = strchr(path, DELIM); if (delim) { size_t len = delim - path; /* ensure we can't overwrite buffer */ #if !defined(PYCC_GCC) len = min(MAXPATHLEN,len); #else len = MAXPATHLEN < len ? MAXPATHLEN : len; #endif strncpy(progpath, path, len); *(progpath + len) = '\0'; } else strncpy(progpath, path, MAXPATHLEN); /* join() is safe for MAXPATHLEN+1 size buffer */ join(progpath, prog); if (exists(progpath)) break; if (!delim) { progpath[0] = '\0'; break; } path = delim + 1; } } else progpath[0] = '\0'; }
MRESULT khs_umIsExceptWindow( HWND hwnd, MPARAM mp1, MPARAM mp2 ) { PKHSCD pkhscd = WinQueryWindowPtr( hwnd, 0 ); HWND hwndTarget = HWNDFROMMP( mp1 ); PID pid; PCHAR modulePath; PCHAR moduleName; ULONG maxPathLen; APIRET rc; BOOL result; WinQueryWindowProcess( hwndTarget, &pid, NULL ); #ifdef DEBUG fprintf( pkhscd->fp, "PID = %x\n", pid ); #endif memset( pkhscd->pQTopLevel, 0, DOSQSS_BUFSIZE ); rc = DosQuerySysState( 0x01, 0, pid, 1, pkhscd->pQTopLevel, DOSQSS_BUFSIZE ); if( rc != 0 ) return FALSE; DosQuerySysInfo( QSV_MAX_PATH_LENGTH, QSV_MAX_PATH_LENGTH, &maxPathLen, sizeof( ULONG )); modulePath = malloc( maxPathLen ); DosQueryModuleName( pkhscd->pQTopLevel->procdata->hndmod, maxPathLen, modulePath ); #ifdef DEBUG fprintf( pkhscd->fp, "Module path = %s\n", modulePath ); #endif moduleName = strrchr( modulePath, '\\' ); if( moduleName == NULL ) moduleName = modulePath; else moduleName++; #ifdef DEBUG fprintf( pkhscd->fp, "Module name = %s\n", moduleName ); #endif result = exceptFindName( pkhscd->exceptListBuf, moduleName ); free( modulePath ); #ifdef DEBUG fprintf( pkhscd->fp, "exceptFindName() = %ld\n", result ); fflush( pkhscd->fp ); #endif return MRFROMLONG( result ); }
void GetApplicationFilename( char* Buffer, ULONG BufferLength ) { PTIB pThreadInfo; PPIB pProcessInfo; DosGetInfoBlocks( & pThreadInfo, & pProcessInfo ); DosQueryModuleName( pProcessInfo -> pib_hmte, BufferLength, Buffer ); }
bool EnumConfigPaths(char *Path,int Number) { #ifdef _EMX static char RARFileName[NM]; if (Number==-1) strcpy(RARFileName,Path); if (Number!=0) return(false); #ifndef _DJGPP if (_osmode==OS2_MODE) { PTIB ptib; PPIB ppib; DosGetInfoBlocks(&ptib, &ppib); DosQueryModuleName(ppib->pib_hmte,NM,Path); } else #endif strcpy(Path,RARFileName); RemoveNameFromPath(Path); return(true); #elif defined(_UNIX) static const char *AltPath[]={ "/etc","/etc/rar","/usr/lib","/usr/local/lib","/usr/local/etc" }; if (Number==0) { char *EnvStr=getenv("HOME"); strncpy(Path, (EnvStr==NULL) ? AltPath[0] : EnvStr, NM-1); Path[NM-1]=0; return(true); } Number--; if (Number<0 || Number>=sizeof(AltPath)/sizeof(AltPath[0])) return(false); strcpy(Path,AltPath[Number]); return(true); #elif defined(_WIN_32) if (Number<0 || Number>1) return(false); if (Number==0) GetRarDataPath(Path); else { GetModuleFileName(NULL,Path,NM); RemoveNameFromPath(Path); } return(true); #else return(false); #endif }
/** Load functions from a DLL. */ static HMODULE load_functions(PSZ moduleName, FUNCTION_TABLE_DEF * table, const int tableLength, char * foundModuleName, const int foundModuleNameLength) { int i; HMODULE moduleHandle = NULLHANDLE; UCHAR loadError[GBMVER_FILENAME_MAX+1] = { 0 }; APIRET rc = 0; /* load the module */ rc = DosLoadModule(loadError, sizeof(loadError)-1, moduleName, &moduleHandle); if (rc) { return NULLHANDLE; } /* get the full path name */ rc = DosQueryModuleName(moduleHandle, foundModuleNameLength, foundModuleName); if (rc) { DosFreeModule(moduleHandle); return NULLHANDLE; } /* get all function addresses */ for (i = 0; i < tableLength; i++) { rc = DosQueryProcAddr(moduleHandle, 0L, table[i].functionName, &table[i].functionAddress); if (rc) { table[i].functionAddress = NULL; } } return moduleHandle; }
int main() { HMQ hmq; HAB hab; CHAR szPMWIN[CCHMAXPATH]; HMODULE hmodPMWIN; PSZ psz; HWND hwndDlg; SWP swp; hab = WinInitialize(0); hmq = WinCreateMsgQueue(hab, 0); if (!DosLoadModule(NULL, 0, "PMWIN", &hmodPMWIN)) { DosQueryModuleName(hmodPMWIN, sizeof(szPMWIN), szPMWIN); psz = strrchr(szPMWIN, '\\'); *psz = '\0'; strcpy(vszSysDLLPath, szPMWIN); } hwndDlg = WinLoadDlg(HWND_DESKTOP, NULLHANDLE, ShrInstallDlgProc, NULLHANDLE, IDD_INSTALL, vszSysDLLPath); WinQueryWindowPos(hwndDlg, &swp); swp.x = (WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN) - swp.cx) / 2; swp.y = (WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN) - swp.cy) / 2; swp.fl |= SWP_ACTIVATE | SWP_MOVE | SWP_ZORDER; swp.hwndInsertBehind = HWND_TOP; WinSetMultWindowPos(NULLHANDLE, &swp, 1); WinProcessDlg(hwndDlg); WinDestroyMsgQueue(hmq); WinTerminate(hab); return 0; }
char *get_module_name(char *buf, size_t len) { HMODULE hmod; ULONG obj, offset; APIRET arc; arc = DosQueryModFromEIP(&hmod, &obj, len, buf, &offset, (ULONG)get_module_name); TRACE_IF(arc, "DosQueryModFromEIP %ld\n", arc); ASSERT_MSG(!arc || arc == ERROR_BAD_LENGTH, "%ld %d", arc, len); if (arc) return NULL; arc = DosQueryModuleName(hmod, len, buf); TRACE_IF(arc, "DosQueryModuleName %ld\n", arc); ASSERT_MSG(!arc || arc == ERROR_BAD_LENGTH, "%ld %d", arc, len); if (arc) return NULL; return buf; }
int archdep_init(int *argc, char **argv) { /* This is right way to do this in OS/2 (not via argv[0]) */ TIB *pTib; PIB *pPib; DosGetInfoBlocks(&pTib, &pPib); DosQueryModuleName(pPib->pib_hmte, CCHMAXPATH, argv0); orig_workdir = (char *)getcwd(NULL, CCHMAXPATH); atexit(restore_workdir); PM_open(); #if !defined __X1541__ && !defined __PETCAT__ archdep_create_mutex_sem(&hmtxSpawn, "Spawn", FALSE); #endif return 0; }
/* from Eberhard to check for the right EMX version */ static void check_emx (void) { ULONG rc; HMODULE hmod; char name[CCHMAXPATH]; char fail[9]; if (_emx_rev < 50) { ErrorF("xf86-OS/2: This program requires emx.dll revision 50 (0.9c fix 2) " "or later.\n"); rc = DosLoadModule (fail, sizeof (fail), "emx", &hmod); if (rc == 0) { rc = DosQueryModuleName (hmod, sizeof (name), name); if (rc == 0) ErrorF("Please delete or update `%s'.\n", name); DosFreeModule (hmod); } exit (2); } }
void (* pthread_dlsym(int handle, char * fnname))(void) { APIRET rc; char pszmodule[80]; pthread_t self = pthread_self(); void (* func )(void); if (rc = DosQueryProcAddr((HMODULE) handle, 0, fnname,(PFN *) &func)) { if (rc == 6) { sprintf(self->dlerror,"invalid module handle %d",handle); errno = EINVAL; } else { DosQueryModuleName((HMODULE) handle, 79, pszmodule); sprintf(self->dlerror,"no function \"%s\" in module \"%s\"",pszmodule,fnname); errno = ENOSYS; } return NULL; } return func; }
/*--------------------------------------------------------------------------------------*\ * UApm : intialize() * \*--------------------------------------------------------------------------------------*/ UApm &UApm::initialize(void) { TIB *ptib; /* Thread information block */ PIB *ppib; /* Process information block */ char *pcTemp; /* Query the fully qualified path APM/2 was loaded from. Once we know the language to use we replace ".exe" by e.g. "xx.msg" where xx is the NLS message file, but for now we assume English as this one is shipped with APM/2 for sure */ DosGetInfoBlocks(&ptib, &ppib); DosQueryModuleName(ppib->pib_hmte, sizeof(acMessageFileUs), (PCHAR)acMessageFileUs); pcCommandline=strdup(strchr(ppib->pib_pchcmd, '\0')+1); pcTemp=strrchr(acMessageFileUs, '.'); if(pcTemp!=0) strcpy(pcTemp, "Us.msg"); strcpy(acMessageFileNls, acMessageFileUs); /* Query the version we're running */ DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR, ulVersion, sizeof(ulVersion)); return(*this); }
VOID fill_proc_rec( PAPPRECORD parAppRec, PQPROCESS pqProcess ) { static char buf[ MAXCOMMANDLEN ]; pqProcess->_reserved2_ = ( ULONG ) parAppRec; parAppRec->pqProcess = pqProcess; parAppRec->core.cb = sizeof( APPRECORD ); /* * bitmap * **/ parAppRec->core.hptrIcon = hPlusIcon; /* * command name * **/ parAppRec->pszCommand = parAppRec->szCommand; DosQueryModuleName( pqProcess->hndmod, MAXCOMMANDLEN, parAppRec->szCommand ); /* * pid ppid * **/ parAppRec->pszPid = parAppRec->szPid; _itoa( pqProcess->pid, buf, 10 ); strncpy( parAppRec->pszPid, buf, sizeof( parAppRec->szPid ) ); parAppRec->pszPpid = parAppRec->szPpid; _itoa( pqProcess->ppid, buf, 10 ); strncpy( parAppRec->pszPpid, buf, sizeof( parAppRec->szPpid ) ); parAppRec->core.pszIcon = pszEmptyStr; // tid parAppRec->pszClass = pszEmptyStr; // class };
PQPROCESS16 prc16FindProcessFromName(PQPROCSTAT16 pInfo, // in: from prc16GetInfo const char *pcszName) // in: e.g. "pmshell.exe" { PQPROCESS16 pProcess, pReturn = NULL; if (pInfo) { for ( pProcess = (PQPROCESS16)PTR(pInfo->ulProcesses, 0); pProcess->ulType != 3; pProcess = (PQPROCESS16)PTR(pProcess->ulThreadList, pProcess->usThreads * sizeof(QTHREAD16)) ) { CHAR szModuleName[CCHMAXPATH]; if (DosQueryModuleName(pProcess->usHModule, sizeof(szModuleName), szModuleName) == NO_ERROR) { // the module name is fully qualified, so find the // file name (after the last backslash) PSZ pLastBackslash = strrchr(szModuleName, '\\'); if (pLastBackslash) // found: if (stricmp(pLastBackslash + 1, pcszName) == 0) { // matches: pReturn = pProcess; break; } } } } return pReturn; }
//---------------------------------------------------------------------------------------- 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()
//---------------------------------------------------------------------------------------- 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()
void FillMenu( HWND hwndMenu ) { char szPidPath[1024]; char szBuffer[1024]; char* pBuf; QSPTRREC* pRecHead; QSPREC* pApp; int numItems, iCounter; PVOID pBuffer; PSWBLOCK pSB; TASKDATA* data; SHORT id = ID_ITEM_FIRST; // Delete all current items numItems = LONGFROMMR( WinSendMsg( hwndMenu, MM_QUERYITEMCOUNT, 0, 0 )); while( numItems-- ) { MENUITEM mi; SHORT id = LONGFROMMR( WinSendMsg( hwndMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT(0), 0 )); if( WinSendMsg( hwndMenu, MM_QUERYITEM, MPFROM2SHORT( id, FALSE ), MPFROMP( &mi ))) { if( mi.hItem ) { data = (TASKDATA*)mi.hItem; free( data->szTitle ); free( data ); } } WinSendMsg( hwndMenu, MM_DELETEITEM, MPFROM2SHORT( id, FALSE ), 0 ); } if( bType ) { // Ctrl is pressed, get the processes in the system. pBuf = (char*)malloc( 0x8000 ); // Get processes DosQuerySysState( QS_PROCESS, 0, 0, 0, (char*)pBuf, 0x8000 ); // Point to first process pRecHead = (QSPTRREC*)pBuf; pApp = pRecHead->pProcRec; // While its a process record while( pApp->RecType == 1 ) { // Get module name for process memset( szPidPath, 0, _MAX_PATH ); DosQueryModuleName( pApp->hMte, 512, szPidPath ); if( strlen( szPidPath ) == 0 ) { // If no hit is the kernel if( pApp->type == 1 ) { sprintf( szPidPath, "VDM (%d)", pApp->pid ); } else { strcpy ( szPidPath, "*SYSINIT" ); } } else { // Else trim the path strcpy ( szBuffer, FileGetFileExt( szPidPath )); sprintf( szPidPath, "%s (%d)", szBuffer, pApp->pid ); } // add to menu data = (TASKDATA*)malloc( sizeof( TASKDATA )); data->szTitle = strdup( szPidPath ); data->hWindow = NULLHANDLE; data->pid = pApp->pid; switch( pApp->type ) { case 0: data->hIcon = ico_os2fs; break; case 1: data->hIcon = ico_dos; break; case 2: data->hIcon = ico_os2vio; break; case 3: data->hIcon = ico_pm; break; case 4: data->hIcon = ico_detach; break; default: data->hIcon = NULLHANDLE; break; } winhInsertMenuItem( hwndMenu, MIT_END, id++, szPidPath, MIS_OWNERDRAW, 0, data ); // get next record pApp=(QSPREC *)((pApp->pThrdRec) + pApp->cTCB); } free(pBuf); } else { // Get number of items in switchlist numItems = WinQuerySwitchList( WinQueryAnchorBlock( hwndMenu ), NULL, 0 ); // Get all items into buffer pBuffer = malloc(( numItems * sizeof(SWENTRY)) + sizeof(HSWITCH)); WinQuerySwitchList( WinQueryAnchorBlock(hwndMenu), (SWBLOCK*)pBuffer, (numItems * sizeof(SWENTRY)) + sizeof(HSWITCH)); pSB = (PSWBLOCK)(pBuffer); for( iCounter = 0; iCounter < numItems; iCounter++ ) { // Should be JUMPABLE and VISIBLE to show in list if( pSB->aswentry[iCounter].swctl.uchVisibility == SWL_VISIBLE ) { // Put in menu data = (TASKDATA*)malloc( sizeof( TASKDATA )); data->szTitle = strdup( pSB->aswentry[iCounter].swctl.szSwtitle ); data->hWindow = pSB->aswentry[iCounter].swctl.hwnd; data->pid = pSB->aswentry[iCounter].swctl.idProcess; CleanString( data->szTitle ); if( pSB->aswentry[iCounter].swctl.hwndIcon != NULLHANDLE ) { data->hIcon = pSB->aswentry[iCounter].swctl.hwndIcon; } else { data->hIcon = (HPOINTER)WinSendMsg( data->hWindow, WM_QUERYICON, 0, 0 ); } winhInsertMenuItem( hwndMenu, MIT_END, id++, pSB->aswentry[iCounter].swctl.szSwtitle, MIS_OWNERDRAW, 0, data ); } } free(pBuffer); } }
nsresult GetSpecialSystemDirectory(SystemDirectories aSystemSystemDirectory, nsIFile** aFile) { #if defined(XP_WIN) WCHAR path[MAX_PATH]; #else char path[MAXPATHLEN]; #endif switch (aSystemSystemDirectory) { case OS_CurrentWorkingDirectory: #if defined(XP_WIN) if (!_wgetcwd(path, MAX_PATH)) return NS_ERROR_FAILURE; return NS_NewLocalFile(nsDependentString(path), true, aFile); #elif defined(XP_OS2) if (DosQueryPathInfo( ".", FIL_QUERYFULLNAME, path, MAXPATHLEN)) return NS_ERROR_FAILURE; #else if(!getcwd(path, MAXPATHLEN)) return NS_ERROR_FAILURE; #endif #if !defined(XP_WIN) return NS_NewNativeLocalFile(nsDependentCString(path), true, aFile); #endif case OS_DriveDirectory: #if defined (XP_WIN) { PRInt32 len = ::GetWindowsDirectoryW(path, MAX_PATH); if (len == 0) break; if (path[1] == PRUnichar(':') && path[2] == PRUnichar('\\')) path[3] = 0; return NS_NewLocalFile(nsDependentString(path), true, aFile); } #elif defined(XP_OS2) { ULONG ulBootDrive = 0; char buffer[] = " :\\OS2\\"; DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, sizeof ulBootDrive); buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index... return NS_NewNativeLocalFile(nsDependentCString(buffer), true, aFile); } #else return NS_NewNativeLocalFile(nsDependentCString("/"), true, aFile); #endif case OS_TemporaryDirectory: #if defined (XP_WIN) { DWORD len = ::GetTempPathW(MAX_PATH, path); if (len == 0) break; return NS_NewLocalFile(nsDependentString(path, len), true, aFile); } #elif defined(XP_OS2) { char *tPath = PR_GetEnv("TMP"); if (!tPath || !*tPath) { tPath = PR_GetEnv("TEMP"); if (!tPath || !*tPath) { // if an OS/2 system has neither TMP nor TEMP defined // then it is severely broken, so this will never happen. return NS_ERROR_UNEXPECTED; } } nsCString tString = nsDependentCString(tPath); if (tString.Find("/", false, 0, -1)) { tString.ReplaceChar('/','\\'); } return NS_NewNativeLocalFile(tString, true, aFile); } #elif defined(MOZ_WIDGET_COCOA) { return GetOSXFolderType(kUserDomain, kTemporaryFolderType, aFile); } #elif defined(XP_UNIX) { static const char *tPath = nullptr; if (!tPath) { tPath = PR_GetEnv("TMPDIR"); if (!tPath || !*tPath) { tPath = PR_GetEnv("TMP"); if (!tPath || !*tPath) { tPath = PR_GetEnv("TEMP"); if (!tPath || !*tPath) { tPath = "/tmp/"; } } } } return NS_NewNativeLocalFile(nsDependentCString(tPath), true, aFile); } #else break; #endif #if defined (XP_WIN) case Win_SystemDirectory: { PRInt32 len = ::GetSystemDirectoryW(path, MAX_PATH); // Need enough space to add the trailing backslash if (!len || len > MAX_PATH - 2) break; path[len] = L'\\'; path[++len] = L'\0'; return NS_NewLocalFile(nsDependentString(path, len), true, aFile); } case Win_WindowsDirectory: { PRInt32 len = ::GetWindowsDirectoryW(path, MAX_PATH); // Need enough space to add the trailing backslash if (!len || len > MAX_PATH - 2) break; path[len] = L'\\'; path[++len] = L'\0'; return NS_NewLocalFile(nsDependentString(path, len), true, aFile); } case Win_ProgramFiles: { return GetWindowsFolder(CSIDL_PROGRAM_FILES, aFile); } case Win_HomeDirectory: { nsresult rv = GetWindowsFolder(CSIDL_PROFILE, aFile); if (NS_SUCCEEDED(rv)) return rv; PRInt32 len; if ((len = ::GetEnvironmentVariableW(L"HOME", path, MAX_PATH)) > 0) { // Need enough space to add the trailing backslash if (len > MAX_PATH - 2) break; path[len] = L'\\'; path[++len] = L'\0'; rv = NS_NewLocalFile(nsDependentString(path, len), true, aFile); if (NS_SUCCEEDED(rv)) return rv; } len = ::GetEnvironmentVariableW(L"HOMEDRIVE", path, MAX_PATH); if (0 < len && len < MAX_PATH) { WCHAR temp[MAX_PATH]; DWORD len2 = ::GetEnvironmentVariableW(L"HOMEPATH", temp, MAX_PATH); if (0 < len2 && len + len2 < MAX_PATH) wcsncat(path, temp, len2); len = wcslen(path); // Need enough space to add the trailing backslash if (len > MAX_PATH - 2) break; path[len] = L'\\'; path[++len] = L'\0'; return NS_NewLocalFile(nsDependentString(path, len), true, aFile); } } case Win_Desktop: { return GetWindowsFolder(CSIDL_DESKTOP, aFile); } case Win_Programs: { return GetWindowsFolder(CSIDL_PROGRAMS, aFile); } case Win_Downloads: { // Defined in KnownFolders.h. GUID folderid_downloads = {0x374de290, 0x123f, 0x4565, {0x91, 0x64, 0x39, 0xc4, 0x92, 0x5e, 0x46, 0x7b}}; nsresult rv = GetKnownFolder(&folderid_downloads, aFile); // On WinXP, there is no downloads folder, default // to 'Desktop'. if(NS_ERROR_FAILURE == rv) { rv = GetWindowsFolder(CSIDL_DESKTOP, aFile); } return rv; } case Win_Controls: { return GetWindowsFolder(CSIDL_CONTROLS, aFile); } case Win_Printers: { return GetWindowsFolder(CSIDL_PRINTERS, aFile); } case Win_Personal: { return GetWindowsFolder(CSIDL_PERSONAL, aFile); } case Win_Favorites: { return GetWindowsFolder(CSIDL_FAVORITES, aFile); } case Win_Startup: { return GetWindowsFolder(CSIDL_STARTUP, aFile); } case Win_Recent: { return GetWindowsFolder(CSIDL_RECENT, aFile); } case Win_Sendto: { return GetWindowsFolder(CSIDL_SENDTO, aFile); } case Win_Bitbucket: { return GetWindowsFolder(CSIDL_BITBUCKET, aFile); } case Win_Startmenu: { return GetWindowsFolder(CSIDL_STARTMENU, aFile); } case Win_Desktopdirectory: { return GetWindowsFolder(CSIDL_DESKTOPDIRECTORY, aFile); } case Win_Drives: { return GetWindowsFolder(CSIDL_DRIVES, aFile); } case Win_Network: { return GetWindowsFolder(CSIDL_NETWORK, aFile); } case Win_Nethood: { return GetWindowsFolder(CSIDL_NETHOOD, aFile); } case Win_Fonts: { return GetWindowsFolder(CSIDL_FONTS, aFile); } case Win_Templates: { return GetWindowsFolder(CSIDL_TEMPLATES, aFile); } case Win_Common_Startmenu: { return GetWindowsFolder(CSIDL_COMMON_STARTMENU, aFile); } case Win_Common_Programs: { return GetWindowsFolder(CSIDL_COMMON_PROGRAMS, aFile); } case Win_Common_Startup: { return GetWindowsFolder(CSIDL_COMMON_STARTUP, aFile); } case Win_Common_Desktopdirectory: { return GetWindowsFolder(CSIDL_COMMON_DESKTOPDIRECTORY, aFile); } case Win_Common_AppData: { return GetWindowsFolder(CSIDL_COMMON_APPDATA, aFile); } case Win_Printhood: { return GetWindowsFolder(CSIDL_PRINTHOOD, aFile); } case Win_Cookies: { return GetWindowsFolder(CSIDL_COOKIES, aFile); } case Win_Appdata: { nsresult rv = GetWindowsFolder(CSIDL_APPDATA, aFile); if (NS_FAILED(rv)) rv = GetRegWindowsAppDataFolder(false, aFile); return rv; } case Win_LocalAppdata: { nsresult rv = GetWindowsFolder(CSIDL_LOCAL_APPDATA, aFile); if (NS_FAILED(rv)) rv = GetRegWindowsAppDataFolder(true, aFile); return rv; } #endif // XP_WIN #if defined(XP_UNIX) case Unix_LocalDirectory: return NS_NewNativeLocalFile(nsDependentCString("/usr/local/netscape/"), true, aFile); case Unix_LibDirectory: return NS_NewNativeLocalFile(nsDependentCString("/usr/local/lib/netscape/"), true, aFile); case Unix_HomeDirectory: return GetUnixHomeDir(aFile); case Unix_XDG_Desktop: case Unix_XDG_Documents: case Unix_XDG_Download: case Unix_XDG_Music: case Unix_XDG_Pictures: case Unix_XDG_PublicShare: case Unix_XDG_Templates: case Unix_XDG_Videos: return GetUnixXDGUserDirectory(aSystemSystemDirectory, aFile); #endif #ifdef XP_OS2 case OS2_SystemDirectory: { ULONG ulBootDrive = 0; char buffer[] = " :\\OS2\\System\\"; DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, sizeof ulBootDrive); buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index... return NS_NewNativeLocalFile(nsDependentCString(buffer), true, aFile); } case OS2_OS2Directory: { ULONG ulBootDrive = 0; char buffer[] = " :\\OS2\\"; DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, sizeof ulBootDrive); buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index... return NS_NewNativeLocalFile(nsDependentCString(buffer), true, aFile); } case OS2_HomeDirectory: { nsresult rv; char *tPath = PR_GetEnv("MOZILLA_HOME"); char buffer[CCHMAXPATH]; /* If MOZILLA_HOME is not set, use GetCurrentProcessDirectory */ /* To ensure we get a long filename system */ if (!tPath || !*tPath) { PPIB ppib; PTIB ptib; DosGetInfoBlocks( &ptib, &ppib); DosQueryModuleName( ppib->pib_hmte, CCHMAXPATH, buffer); *strrchr( buffer, '\\') = '\0'; // XXX DBCS misery tPath = buffer; } rv = NS_NewNativeLocalFile(nsDependentCString(tPath), true, aFile); PrfWriteProfileString(HINI_USERPROFILE, "Mozilla", "Home", tPath); return rv; } case OS2_DesktopDirectory: { char szPath[CCHMAXPATH + 1]; BOOL fSuccess; fSuccess = WinQueryActiveDesktopPathname (szPath, sizeof(szPath)); if (!fSuccess) { // this could happen if we are running without the WPS, return // the Home directory instead return GetSpecialSystemDirectory(OS2_HomeDirectory, aFile); } int len = strlen (szPath); if (len > CCHMAXPATH -1) break; szPath[len] = '\\'; szPath[len + 1] = '\0'; return NS_NewNativeLocalFile(nsDependentCString(szPath), true, aFile); } #endif default: break; } return NS_ERROR_NOT_AVAILABLE; }
unsigned _LibMain( unsigned hmod, unsigned termination ) /******************************************************/ { static int processes; unsigned rc; if( termination != 0 ) { // If we're running with single DGROUP and tried to load // twice, do not run any termination code! Also reset the // process counter so that the already loaded DLL can // terminate properly if( processes > 1 ) { --processes; return( 0 ); } rc = LibMain( hmod, termination ); --processes; #ifdef __SW_BR __FiniRtns( 0, 255 ); #else if( _LpwCmdLine ) { lib_free( _LpwCmdLine ); _LpwCmdLine = NULL; } if( _LpwPgmName ) { lib_free( _LpwPgmName ); _LpwPgmName = NULL; } __FiniRtns( FINI_PRIORITY_EXIT, 255 ); // calls to free memory have to be done before semaphores closed __FreeInitThreadData( __FirstThreadData ); __OS2Fini(); // must be done before following finalizers get called __FiniRtns( 0, FINI_PRIORITY_EXIT - 1 ); __shutdown_stack_checking(); #endif return( rc ); } ++processes; if( processes > 1 ) { if( __disallow_single_dgroup(hmod) ) { return( 0 ); } } __hmodule = hmod; #ifdef __SW_BR { static char fname[_MAX_PATH]; static wchar_t wfname[_MAX_PATH]; __Is_DLL = 1; __InitRtns( 255 ); DosQueryModuleName( hmod, sizeof( fname ), fname ); _LpDllName = fname; _LpwDllName = wfname; _atouni( _LpwDllName, _LpDllName ); } #else { PTIB pptib; PPIB pppib; unsigned i; DosGetInfoBlocks( &pptib, &pppib ); _RWD_Envptr = pppib->pib_pchenv; _LpCmdLine = pppib->pib_pchcmd; while( *_LpCmdLine ) { // skip over program name _LpCmdLine++; } _LpCmdLine++; _LpwCmdLine = lib_malloc( (strlen( _LpCmdLine ) + 1) * sizeof( wchar_t ) ); _atouni( _LpwCmdLine, _LpCmdLine ); { // ugly stuff to deal with two copies of .exe name in the // environment space. apparently the OS fullpath name is // just before this one in the environment space char *cmd_path; cmd_path = pppib->pib_pchcmd; for( cmd_path -= 2; *cmd_path != '\0'; --cmd_path ); ++cmd_path; _LpPgmName = cmd_path; _LpwPgmName = lib_malloc( (strlen( _LpPgmName ) + 1) * sizeof( wchar_t ) ); _atouni( _LpwPgmName, _LpPgmName ); } __InitRtns( INIT_PRIORITY_THREAD ); if( __InitThreadProcessing() == NULL ) return( 0 ); __OS2Init( TRUE, __AllocInitThreadData( NULL ) ); for( i = 2; i <= __MaxThreads; i++ ) { if( !__OS2AddThread( i, NULL ) ) { return( 0 ); } } __InitRtns( INIT_PRIORITY_EXIT - 1 ); __InitMultipleThread(); { static char fname[_MAX_PATH]; static wchar_t wfname[_MAX_PATH]; DosQueryModuleName( hmod, sizeof( fname ), fname ); _LpDllName = fname; _LpwDllName = wfname; _atouni( _LpwDllName, _LpDllName ); } __InitRtns( 255 ); } #endif __CommonInit(); #ifndef __SW_BR /* allocate alternate stack for F77 */ __ASTACKPTR = (char *)_STACKLOW + __ASTACKSIZ; #endif return( LibMain( hmod, termination ) ); }
char *get_path(const char *filename){ char *homedir; char *buff; #ifdef __MINGW32__ static char *config_dir = "/mplayer"; #else static char *config_dir = "/.mplayer"; #endif int len; #ifdef CONFIG_MACOSX_BUNDLE struct stat dummy; CFIndex maxlen=256; CFURLRef res_url_ref=NULL; CFURLRef bdl_url_ref=NULL; char *res_url_path = NULL; char *bdl_url_path = NULL; #endif if ((homedir = getenv("MPLAYER_HOME")) != NULL) config_dir = ""; else if ((homedir = getenv("HOME")) == NULL) #if defined(__MINGW32__) || defined(__CYGWIN__) /* Hack to get fonts etc. loaded outside of Cygwin environment. */ { int i,imax=0; char exedir[260]; GetModuleFileNameA(NULL, exedir, 260); for (i=0; i< strlen(exedir); i++) if (exedir[i] =='\\') {exedir[i]='/'; imax=i;} exedir[imax]='\0'; homedir = exedir; } #elif defined(__OS2__) { PPIB ppib; char path[260]; // Get process info blocks DosGetInfoBlocks(NULL, &ppib); // Get full path of the executable DosQueryModuleName(ppib->pib_hmte, sizeof( path ), path); // Truncate name part including last backslash *strrchr(path, '\\') = 0; // Convert backslash to slash _fnslashify(path); homedir = path; } #else return NULL; #endif len = strlen(homedir) + strlen(config_dir) + 1; if (filename == NULL) { if ((buff = malloc(len)) == NULL) return NULL; sprintf(buff, "%s%s", homedir, config_dir); } else { len += strlen(filename) + 1; if ((buff = malloc(len)) == NULL) return NULL; sprintf(buff, "%s%s/%s", homedir, config_dir, filename); } #ifdef CONFIG_MACOSX_BUNDLE if (stat(buff, &dummy)) { res_url_ref=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); bdl_url_ref=CFBundleCopyBundleURL(CFBundleGetMainBundle()); if (res_url_ref&&bdl_url_ref) { res_url_path=malloc(maxlen); bdl_url_path=malloc(maxlen); while (!CFURLGetFileSystemRepresentation(res_url_ref, true, res_url_path, maxlen)) { maxlen*=2; res_url_path=realloc(res_url_path, maxlen); } CFRelease(res_url_ref); while (!CFURLGetFileSystemRepresentation(bdl_url_ref, true, bdl_url_path, maxlen)) { maxlen*=2; bdl_url_path=realloc(bdl_url_path, maxlen); } CFRelease(bdl_url_ref); if (strcmp(res_url_path, bdl_url_path) == 0) res_url_path = NULL; } if (res_url_path&&filename) { if ((strlen(filename)+strlen(res_url_path)+2)>maxlen) { maxlen=strlen(filename)+strlen(res_url_path)+2; } free(buff); buff = malloc(maxlen); strcpy(buff, res_url_path); strcat(buff,"/"); strcat(buff, filename); } } #endif mp_msg(MSGT_GLOBAL,MSGL_V,"get_path('%s') -> '%s'\n",filename,buff); return buff; }
//---------------------------------------------------------------------------------------- nsresult nsDirectoryService::GetCurrentProcessDirectory(nsILocalFile** aFile) //---------------------------------------------------------------------------------------- { NS_ENSURE_ARG_POINTER(aFile); *aFile = nsnull; // Set the component registry location: if (!gService) 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 PRUnichar buf[MAX_PATH]; if ( ::GetModuleFileNameW(0, buf, sizeof(buf)) ) { // chop off the executable name by finding the rightmost backslash PRUnichar* lastSlash = wcsrchr(buf, L'\\'); if (lastSlash) *(lastSlash + 1) = L'\0'; localFile->InitWithPath(nsDependentString(buf)); *aFile = localFile; return NS_OK; } #elif defined(MOZ_WIDGET_COCOA) // 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); } } 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 MOZILLA_FIVE_HOME is defined, that is it // - else give the current directory char buf[MAXPATHLEN]; // The MOZ_DEFAULT_MOZILLA_FIVE_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 MOZILLA_FIVE_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 by putenv()ing the default value into the environment. Note that // we only do this if it is not already set. #ifdef MOZ_DEFAULT_MOZILLA_FIVE_HOME const char *home = PR_GetEnv("MOZILLA_FIVE_HOME"); if (!home || !*home) { putenv("MOZILLA_FIVE_HOME=" MOZ_DEFAULT_MOZILLA_FIVE_HOME); } #endif char *moz5 = PR_GetEnv("MOZILLA_FIVE_HOME"); if (moz5 && *moz5) { if (realpath(moz5, buf)) { localFile->InitWithNativePath(nsDependentCString(buf)); *aFile = localFile; return NS_OK; } } #if defined(DEBUG) static bool firstWarning = true; if((!moz5 || !*moz5) && 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))) { 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; #endif NS_RELEASE(localFile); NS_ERROR("unable to get current process directory"); return NS_ERROR_FAILURE; } // GetCurrentProcessDirectory()
nsresult nsXREDirProvider::GetUserDataDirectoryHome(nsIFile** aFile, bool aLocal) { // Copied from nsAppFileLocationProvider (more or less) nsresult rv; nsCOMPtr<nsIFile> localDir; #if defined(XP_MACOSX) FSRef fsRef; OSType folderType; if (aLocal) { folderType = kCachedDataFolderType; } else { #ifdef MOZ_THUNDERBIRD folderType = kDomainLibraryFolderType; #else folderType = kApplicationSupportFolderType; #endif } OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef); NS_ENSURE_FALSE(err, NS_ERROR_FAILURE); rv = NS_NewNativeLocalFile(EmptyCString(), true, getter_AddRefs(localDir)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsILocalFileMac> dirFileMac = do_QueryInterface(localDir); NS_ENSURE_TRUE(dirFileMac, NS_ERROR_UNEXPECTED); rv = dirFileMac->InitWithFSRef(&fsRef); NS_ENSURE_SUCCESS(rv, rv); localDir = do_QueryInterface(dirFileMac, &rv); #elif defined(XP_WIN) nsString path; if (aLocal) { rv = GetShellFolderPath(CSIDL_LOCAL_APPDATA, path); if (NS_FAILED(rv)) rv = GetRegWindowsAppDataFolder(aLocal, path); } if (!aLocal || NS_FAILED(rv)) { rv = GetShellFolderPath(CSIDL_APPDATA, path); if (NS_FAILED(rv)) { if (!aLocal) rv = GetRegWindowsAppDataFolder(aLocal, path); } } NS_ENSURE_SUCCESS(rv, rv); rv = NS_NewLocalFile(path, true, getter_AddRefs(localDir)); #elif defined(XP_OS2) #if 0 /* For OS/2 we want to always use MOZILLA_HOME */ // we want an environment variable of the form // FIREFOX_HOME, etc if (!gAppData) return NS_ERROR_FAILURE; nsDependentCString envVar(nsDependentCString(gAppData->name)); envVar.Append("_HOME"); char *pHome = getenv(envVar.get()); #endif char *pHome = getenv("MOZILLA_HOME"); if (pHome && *pHome) { rv = NS_NewNativeLocalFile(nsDependentCString(pHome), true, getter_AddRefs(localDir)); } else { PPIB ppib; PTIB ptib; char appDir[CCHMAXPATH]; DosGetInfoBlocks(&ptib, &ppib); DosQueryModuleName(ppib->pib_hmte, CCHMAXPATH, appDir); *strrchr(appDir, '\\') = '\0'; rv = NS_NewNativeLocalFile(nsDependentCString(appDir), true, getter_AddRefs(localDir)); } #elif defined(MOZ_WIDGET_GONK) rv = NS_NewNativeLocalFile(NS_LITERAL_CSTRING("/data/b2g"), true, getter_AddRefs(localDir)); #elif defined(XP_UNIX) const char* homeDir = getenv("HOME"); if (!homeDir || !*homeDir) return NS_ERROR_FAILURE; #ifdef ANDROID /* We want (ProfD == ProfLD) on Android. */ aLocal = false; #endif if (aLocal) { // If $XDG_CACHE_HOME is defined use it, otherwise use $HOME/.cache. const char* cacheHome = getenv("XDG_CACHE_HOME"); if (cacheHome && *cacheHome) { rv = NS_NewNativeLocalFile(nsDependentCString(cacheHome), true, getter_AddRefs(localDir)); } else { rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true, getter_AddRefs(localDir)); if (NS_SUCCEEDED(rv)) rv = localDir->AppendNative(NS_LITERAL_CSTRING(".cache")); } } else { rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true, getter_AddRefs(localDir)); } #else #error "Don't know how to get product dir on your platform" #endif NS_IF_ADDREF(*aFile = localDir); return rv; }
/** * Daemonize the process for running in the background. * * This is supposed to do the same job as the BSD daemon() call. * * @returns 0 on success * * @param fNoChDir Pass false to change working directory to root. * @param fNoClose Pass false to redirect standard file streams to /dev/null. * @param fRespawn Restart the daemonised process after five seconds if it * terminates abnormally. * @param pcRespawn Where to store a count of how often we have respawned, * intended for avoiding error spamming. Optional. * * @todo Use RTProcDaemonize instead of this. * @todo Implement fRespawn on OS/2. * @todo Make the respawn interval configurable. But not until someone * actually needs that. */ VBGLR3DECL(int) VbglR3Daemonize(bool fNoChDir, bool fNoClose, bool fRespawn, unsigned *pcRespawn) { #if defined(RT_OS_OS2) PPIB pPib; PTIB pTib; DosGetInfoBlocks(&pTib, &pPib); AssertRelease(!fRespawn); /* Get the full path to the executable. */ char szExe[CCHMAXPATH]; APIRET rc = DosQueryModuleName(pPib->pib_hmte, sizeof(szExe), szExe); if (rc) return RTErrConvertFromOS2(rc); /* calc the length of the command line. */ char *pch = pPib->pib_pchcmd; size_t cch0 = strlen(pch); pch += cch0 + 1; size_t cch1 = strlen(pch); pch += cch1 + 1; char *pchArgs; if (cch1 && *pch) { do pch = strchr(pch, '\0') + 1; while (*pch); size_t cchTotal = pch - pPib->pib_pchcmd; pchArgs = (char *)alloca(cchTotal + sizeof("--daemonized\0\0")); memcpy(pchArgs, pPib->pib_pchcmd, cchTotal - 1); memcpy(pchArgs + cchTotal - 1, "--daemonized\0\0", sizeof("--daemonized\0\0")); } else { size_t cchTotal = pch - pPib->pib_pchcmd + 1; pchArgs = (char *)alloca(cchTotal + sizeof(" --daemonized ")); memcpy(pchArgs, pPib->pib_pchcmd, cch0 + 1); pch = pchArgs + cch0 + 1; memcpy(pch, " --daemonized ", sizeof(" --daemonized ") - 1); pch += sizeof(" --daemonized ") - 1; if (cch1) memcpy(pch, pPib->pib_pchcmd + cch0 + 1, cch1 + 2); else pch[0] = pch[1] = '\0'; } /* spawn a detach process */ char szObj[128]; RESULTCODES ResCodes = { 0, 0 }; szObj[0] = '\0'; rc = DosExecPgm(szObj, sizeof(szObj), EXEC_BACKGROUND, (PCSZ)pchArgs, NULL, &ResCodes, (PCSZ)szExe); if (rc) { /** @todo Change this to some standard log/print error?? */ /* VBoxServiceError("DosExecPgm failed with rc=%d and szObj='%s'\n", rc, szObj); */ return RTErrConvertFromOS2(rc); } DosExit(EXIT_PROCESS, 0); return VERR_GENERAL_FAILURE; #elif defined(RT_OS_WINDOWS) # error "PORTME" #else /* the unices */ /* * Fork the child process in a new session and quit the parent. * * - fork once and create a new session (setsid). This will detach us * from the controlling tty meaning that we won't receive the SIGHUP * (or any other signal) sent to that session. * - The SIGHUP signal is ignored because the session/parent may throw * us one before we get to the setsid. * - When the parent exit(0) we will become an orphan and re-parented to * the init process. * - Because of the Linux / System V semantics of assigning the controlling * tty automagically when a session leader first opens a tty, we will * fork() once more on Linux to get rid of the session leadership role. */ struct sigaction OldSigAct; struct sigaction SigAct; RT_ZERO(SigAct); SigAct.sa_handler = SIG_IGN; int rcSigAct = sigaction(SIGHUP, &SigAct, &OldSigAct); pid_t pid = fork(); if (pid == -1) return RTErrConvertFromErrno(errno); if (pid != 0) exit(0); /* * The orphaned child becomes is reparented to the init process. * We create a new session for it (setsid), point the standard * file descriptors to /dev/null, and change to the root directory. */ pid_t newpgid = setsid(); int SavedErrno = errno; if (rcSigAct != -1) sigaction(SIGHUP, &OldSigAct, NULL); if (newpgid == -1) return RTErrConvertFromErrno(SavedErrno); if (!fNoClose) { /* Open stdin(0), stdout(1) and stderr(2) as /dev/null. */ int fd = open("/dev/null", O_RDWR); if (fd == -1) /* paranoia */ { close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); fd = open("/dev/null", O_RDWR); } if (fd != -1) { dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); if (fd > 2) close(fd); } } if (!fNoChDir) chdir("/"); /* * Change the umask - this is non-standard daemon() behavior. */ umask(027); # ifdef RT_OS_LINUX /* * And fork again to lose session leader status (non-standard daemon() * behaviour). */ pid = fork(); if (pid == -1) return RTErrConvertFromErrno(errno); if (pid != 0) exit(0); # endif /* RT_OS_LINUX */ if (fRespawn) { /* We implement re-spawning as a third fork(), with the parent process * monitoring the child and re-starting it after a delay if it exits * abnormally. */ unsigned cRespawn = 0; for (;;) { int iStatus, rcWait; if (pcRespawn != NULL) *pcRespawn = cRespawn; pid = fork(); if (pid == -1) return RTErrConvertFromErrno(errno); if (pid == 0) return VINF_SUCCESS; do rcWait = waitpid(pid, &iStatus, 0); while (rcWait == -1 && errno == EINTR); if (rcWait == -1) exit(1); if (WIFEXITED(iStatus) && WEXITSTATUS(iStatus) == 0) exit(0); sleep(5); ++cRespawn; } } return VINF_SUCCESS; #endif }
int main(int argc, char *argv[]) { int do_load,do_unload,do_help,do_path; do_load=do_unload=do_help=do_path=0; char basepath[CCHMAXPATH]; if (argc == 1) do_help = 1; else { for (int i=1; i < argc; i++) { if (strnicmp(argv[i],"-l", 2) == 0) do_load = 1; else if (strnicmp(argv[i],"-u", 2) == 0) do_unload = 1; else if (strnicmp(argv[i],"-h", 2) == 0) do_help = 1; else if (strnicmp(argv[i],"-?", 2) == 0) do_help = 1; else if (strnicmp(argv[i],"-p", 2) == 0) { if (argc > i+1) { strcpy(basepath, argv[i+1]); if (basepath[strlen(basepath)] !='\\') { strcat(basepath, "\\"); } do_path = 1; } else { do_help = 1; } } } } if (do_help) { printf("%s for OS/2 preloader\n"\ "\n"\ "Usage: %s [-h] [-l | -u] [-p path]\n"\ " -h display this help\n"\ " -l load modules\n"\ " -u unload modules\n"\ " -p specify fully qualified path to directory where EXE is located\n", MOZ_APP_DISPLAYNAME, argv[0]); return(1); } if (do_unload) { HEV hev = NULLHANDLE; if (DosOpenEventSem(SEMNAME, &hev) == NO_ERROR) { if (DosPostEventSem(hev) == NO_ERROR) { if (DosCloseEventSem(hev) == NO_ERROR) { return(0); } } } printf("%s for OS/2 preloader is not running\n", MOZ_APP_DISPLAYNAME); return(1); } if (do_path == 0) { /* Get the name of this EXE and use its location as the path */ HMODULE hmodule; DosQueryModFromEIP(&hmodule, NULL, 0, NULL, NULL, (ULONG)ForceModuleLoad); DosQueryModuleName(hmodule, CCHMAXPATH, basepath); char *pchar = strrchr(basepath, '\\'); pchar++; *pchar = '\0'; } if (do_load) { ULONG ulCurMaxFH; LONG ulReqFH = 40; DosSetRelMaxFH(&ulReqFH, &ulCurMaxFH); HEV hev; if (DosCreateEventSem(SEMNAME, &hev, DC_SEM_SHARED, FALSE) != NO_ERROR) { printf("%s for OS/2 preloader is already running\n", MOZ_APP_DISPLAYNAME); return(1); } /* Add directory where EXE is located to LIBPATH */ DosSetExtLIBPATH(basepath, BEGIN_LIBPATH); /* loop through list loading named modules */ char filepath[CCHMAXPATH]; HMODULE hmod; int i = 0, nummodules = 0; while (bindir[i]) { strcpy(filepath,basepath); strcat(filepath,bindir[i]); if (DosLoadModule(NULL, 0, filepath, &hmod) == NO_ERROR) { ForceModuleLoad(hmod); nummodules++; } i++; } i = 0; while (compdir[i]) { strcpy(filepath, basepath); strcat(filepath, "COMPONENTS\\"); strcat(filepath, compdir[i]); if (DosLoadModule(NULL, 0, filepath, &hmod) == NO_ERROR) { ForceModuleLoad(hmod); nummodules++; } i++; } if (nummodules > 0) { if (DosWaitEventSem(hev, SEM_INDEFINITE_WAIT) != NO_ERROR) { printf("DosWaitEventSem failed\n"); return(1); } if (DosCloseEventSem(hev) != NO_ERROR) { printf("DosCloseEventSem failed\n"); return(1); } } else { printf("No modules available to load\n"); } } return(0); }