//============================================================================ // FUNCTION: SPELLutils::showEnvironment //============================================================================ void SPELLutils::showEnvironment() { std::cerr << "==============================================================================" << std::endl; std::cerr << " SPELL environment configuration" << std::endl; std::cerr << "==============================================================================" << std::endl; envVar("SPELL_HOME"); envVar("SPELL_COTS"); envVar("SPELL_DATA"); envVar("SPELL_CONFIG"); envVar("SPELL_SYS_DATA"); envVar("SPELL_LOG"); envVar("SPELL_PROCS"); std::cerr << "==============================================================================" << std::endl; }
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; }
nsresult nsXREDirProvider::GetUserDataDirectoryHome(nsILocalFile** aFile, PRBool aLocal) { // Copied from nsAppFileLocationProvider (more or less) nsresult rv; nsCOMPtr<nsILocalFile> localDir; #if defined(MOZ_WIDGET_COCOA) 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(), PR_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); #ifndef WINCE if (NS_FAILED(rv)) rv = GetRegWindowsAppDataFolder(aLocal, path); #endif } if (!aLocal || NS_FAILED(rv)) { rv = GetShellFolderPath(CSIDL_APPDATA, path); #ifndef WINCE if (NS_FAILED(rv)) { if (!aLocal) rv = GetRegWindowsAppDataFolder(aLocal, path); } #endif } NS_ENSURE_SUCCESS(rv, rv); rv = NS_NewLocalFile(path, PR_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), PR_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), PR_TRUE, getter_AddRefs(localDir)); } #elif defined(XP_BEOS) char appDir[MAXPATHLEN]; if (find_directory(B_USER_SETTINGS_DIRECTORY, NULL, true, appDir, MAXPATHLEN)) return NS_ERROR_FAILURE; int len = strlen(appDir); appDir[len] = '/'; appDir[len+1] = '\0'; rv = NS_NewNativeLocalFile(nsDependentCString(appDir), PR_TRUE, getter_AddRefs(localDir)); #elif defined(ANDROID) // used for setting the patch to our profile // XXX: investigate putting the profile somewhere else const char* homeDir = "/data/data/org.mozilla." MOZ_APP_NAME; rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), PR_TRUE, getter_AddRefs(localDir)); #elif defined(XP_UNIX) const char* homeDir = getenv("HOME"); if (!homeDir || !*homeDir) return NS_ERROR_FAILURE; rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), PR_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; }
int main(int argc, char ** args) { struct dirent * current_entry; char * dirpath; if (argc < 2) { dirpath = strdup(DEFAULT_DIR); } else { dirpath = strdup(args[1]); } // copy environment, if needed /* if (argc > 2) { int n = 0; for (; environ[n]; ++n); new_environment = malloc(sizeof(char**)*(n+argc-1)); memcpy(new_environment, environ, sizeof(char**)*n); memcpy(new_environment + n, args + 2, sizeof(char**)*(argc-2)); new_environment[n+argc-2] = NULL; } else new_environment = NULL; */ char * homeDir = envVar("HOME"); if (*dirpath == '~' && homeDir) { char * oldpath = dirpath; int n1 = strlen(homeDir), n2 = strlen(oldpath)-1; dirpath = malloc(sizeof(char)*(n1+n2+1)); memset(dirpath, 0, n1+n2+1); strncat(dirpath, homeDir, n1); strncat(dirpath, oldpath + 1, n2); free(oldpath); } repair_path(&dirpath); dir = opendir(dirpath); if (!dir) die("could not open dir \"%s\"\n", args[1]); char filename[512]; while((current_entry = readdir(dir))) { if (is_desktop_file(current_entry)) { int pid; if ((pid = fork()) == 0) { strcpy(filename, dirpath); strcpy(filename + strlen(filename), current_entry->d_name); process_desktop_file(filename); break; } printf("cpid: %d\n", pid); } } free(dirpath); closedir(dir); }