void Environment::unset(std::string var) { // POSIX implementation. #if defined(DUNE_OS_POSIX) unsetenv(var.c_str()); // Microsoft Windows implementation. #elif defined(DUNE_OS_WINDOWS) _putenv((var + '=').c_str()); #endif }
/* ============== Sys_GLimpInit Windows specific GL implementation initialisation ============== */ void Sys_GLimpInit(void) { #ifndef DEDICATED if (!SDL_VIDEODRIVER_externallySet) { // It's a little bit weird having in_mouse control the // video driver, but from ioq3's point of view they're // virtually the same except for the mouse input anyway if (Cvar_VariableIntegerValue("in_mouse") == -1) { // Use the windib SDL backend, which is closest to // the behaviour of idq3 with in_mouse set to -1 _putenv("SDL_VIDEODRIVER=windib"); } else { // Use the DirectX SDL backend _putenv("SDL_VIDEODRIVER=directx"); } } #endif }
void FdoCommonOSUtil::setenv(const char *varname, const char *varvalue) { #ifdef _WIN32 char* setstring = (char*)alloca(sizeof(char) * strlen(varname) + strlen(varvalue) + 2); sprintf(setstring, "%hs=%hs", varname, varvalue); _putenv(setstring); #else if ((varvalue==NULL) || (strlen(varvalue)==0)) ::unsetenv(varname); else ::setenv(varname, varvalue, 1); #endif }
/* ============== Sys_GLimpSafeInit Windows specific "safe" GL implementation initialisation ============== */ void Sys_GLimpSafeInit( void ) { #if !defined(DEDICATED) && !defined(BUILD_TTY_CLIENT) if ( !SDL_VIDEODRIVER_externallySet ) { // Here, we want to let SDL decide what do to unless // explicitly requested otherwise _putenv( "SDL_VIDEODRIVER=" ); } #endif }
void Environment::addToEnvironmentVariable(const std::string& variable, const std::string& value) { std::string new_path(variable + "="); const char* path_env = getenv(variable.c_str()); if (path_env) { new_path += path_env; } if (new_path.length() > 0) { if (!(new_path.back() == '=' || new_path.back() == ';')) { new_path += ";"; } } new_path += value; _putenv(new_path.c_str()); }
MasterSegmentTable::MasterSegmentTable() { #ifdef _MSC_VER const char* envp = getenv("SystemRoot"); string SystemRoot; if (envp && *envp) SystemRoot = envp; else SystemRoot = "C:\\WINDOWS"; string tmpEnv = "TMP=" + SystemRoot + "\\Temp"; _putenv(tmpEnv.c_str()); #endif int i; bool initializer = false; RWLockKeys[0] = fShmKeys.KEYRANGE_EXTENTMAP_BASE; RWLockKeys[1] = fShmKeys.KEYRANGE_EMFREELIST_BASE; RWLockKeys[2] = fShmKeys.KEYRANGE_VBBM_BASE; RWLockKeys[3] = fShmKeys.KEYRANGE_VSS_BASE; RWLockKeys[4] = fShmKeys.KEYRANGE_CL_BASE; try { // if initializer is returned false, then this is not the first time for this key. rwlock[0].reset(new RWLock(RWLockKeys[0], &initializer)); } catch (exception &e) { cerr << "ControllerSegmentTable: RWLock() threw: " << e.what() << endl; throw; } if (rwlock[0] == NULL) { cerr << "ControllerSegmentTable(): RWLock() failed..?" << endl; throw runtime_error("ControllerSegmentTable(): RWLock() failed..?"); } for (i = 1; i < nTables; i++) rwlock[i].reset(new RWLock(RWLockKeys[i])); makeMSTSegment(); if (initializer) { initMSTData(); rwlock[0]->write_unlock(); } else { rwlock[0]->read_lock_priority(); // this is to synch with the initializer rwlock[0]->read_unlock(); } }
//----------------------------------------------------------------------------- // Sets up the steam environment + gets back the gameinfo.txt path //----------------------------------------------------------------------------- FSReturnCode_t FileSystem_SetupSteamEnvironment( CFSSteamSetupInfo &fsInfo ) { // First, locate the directory with gameinfo.txt. FSReturnCode_t ret = LocateGameInfoFile( fsInfo, fsInfo.m_GameInfoPath, sizeof( fsInfo.m_GameInfoPath ) ); if ( ret != FS_OK ) return ret; // This is so that processes spawned by this application will have the same VPROJECT #ifdef WIN32 char pEnvBuf[MAX_PATH+32]; Q_snprintf( pEnvBuf, sizeof(pEnvBuf), "%s=%s", GAMEDIR_TOKEN, fsInfo.m_GameInfoPath ); _putenv( pEnvBuf ); #else setenv( GAMEDIR_TOKEN, fsInfo.m_GameInfoPath, 1 ); #endif CSteamEnvVars steamEnvVars; if ( fsInfo.m_bSteam ) { if ( fsInfo.m_bToolsMode ) { // Now, load gameinfo.txt (to make sure it's there) KeyValues *pMainFile, *pFileSystemInfo, *pSearchPaths; ret = LoadGameInfoFile( fsInfo.m_GameInfoPath, pMainFile, pFileSystemInfo, pSearchPaths ); if ( ret != FS_OK ) return ret; // Setup all the environment variables related to Steam so filesystem_steam.dll knows how to initialize Steam. ret = SetupSteamStartupEnvironment( pFileSystemInfo, fsInfo.m_GameInfoPath, steamEnvVars ); if ( ret != FS_OK ) return ret; steamEnvVars.m_SteamAppId.SetRestoreOriginalValue( false ); // We want to keep the change to the path going forward. // We're done with main file pMainFile->deleteThis(); } else if ( fsInfo.m_bSetSteamDLLPath ) { // This is used by the engine to automatically set the path to their steam.dll when running the engine, // so they can debug it without having to copy steam.dll up into their hl2.exe folder. char steamInstallPath[MAX_PATH]; ret = SetSteamInstallPath( steamInstallPath, sizeof( steamInstallPath ), steamEnvVars, true ); steamEnvVars.m_Path.SetRestoreOriginalValue( false ); // We want to keep the change to the path going forward. } } return FS_OK; }
void InitializeEnvironment() { char *pValue; size_t len; errno_t err = _dupenv_s( &pValue, &len, "JAVA_HOME" ); gJavaHome = pValue; char *path_env = (char*)malloc(sizeof(char)*2048); _snprintf(path_env, 2048, "PATH=%s\\bin;%s", gJavaHome.c_str(), getenv("PATH")); _putenv ( path_env ); err = _dupenv_s( &pValue, &len, "GEMFIRE" ); gGemfireHome = pValue; }
int setenv_portable(const char *name, const char *value) { char *var; int ret; size_t len; len = strlen(name) + strlen(value) + 2; /* 1 for '\0', 1 for =. */ var = (char *) safe_malloc(len); Snprintf(var, len, "%s=%s", name, value); /* _putenv was chosen over SetEnvironmentVariable because variables set with the latter seem to be invisible to getenv() calls and Lua uses these in the 'os' module. */ ret = _putenv(var) == 0; free(var); return ret; }
void SetValue( const char *pValue, ... ) { char valueString[4096]; va_list marker; va_start( marker, pValue ); Q_vsnprintf( valueString, sizeof( valueString ), pValue, marker ); va_end( marker ); #ifdef WIN32 char str[4096]; Q_snprintf( str, sizeof( str ), "%s=%s", m_pVarName, valueString ); _putenv( str ); #else setenv( m_pVarName, valueString, 1 ); #endif }
/* * Find path to JRE based on .exe's location or registry settings. */ jboolean GetJREPath(char *path, jint pathsize) { char javadll[MAXPATHLEN]; struct stat s; // // if (GetApplicationHome(path, pathsize)) { // /* Is JRE co-located with the application? */ // sprintf(javadll, "%s\\bin\\" JAVA_DLL, path); // if (stat(javadll, &s) == 0) { // goto found; // } // /* Does this app ship a private JRE in <apphome>\jre directory? */ // sprintf(javadll, "%s\\jre\\bin\\" JAVA_DLL, path); // if (stat(javadll, &s) == 0) { // strcat(path, "\\jre"); // goto found; // } // } /* Look for a public JRE on this machine. */ if (GetPublicJREHome(path, pathsize)) goto found; fprintf(stderr, "Error: could not find " JAVA_DLL "\n"); return JNI_FALSE; found: { // trick into thinking that the jre/bin path is in the PATH char *oldPath = getenv("PATH"); char *newPath; if(oldPath != NULL) { newPath = MemAlloc(strlen(oldPath) + strlen(path) + 6 + 6 + 1); // PATH=<new>\bin;<old> sprintf(newPath, "PATH=%s\\bin;%s", path, oldPath); } else { newPath = MemAlloc(strlen(path) + 6 + 1); sprintf(newPath, "PATH=%s\\bin", path); } _putenv(newPath); free(newPath); } return JNI_TRUE; }
static void init_i18n() { if (fs_config_get_boolean("localization") == 0) { fs_log("localization was forced off\n"); return; } char *locale = setlocale(LC_MESSAGES, ""); if (locale) { fs_log("locale is set to %s\n", locale); } else { fs_log("failed to set current locale\n"); } const char *language = fs_config_get_const_string("language"); if (language) { fs_log("setting LANGUAGE=%s\n", language); char *env_str = g_strdup_printf("LANGUAGE=%s", language); #ifdef WINDOWS _putenv(env_str); #else putenv(env_str); #endif // don't free env_str, it's put directly in the environment } #ifndef ANDROID textdomain("fs-uae"); char *path = fs_get_data_file("fs-uae/share-dir"); if (path) { fs_log("using data dir \"%s\"\n", path); // remove "fs-uae/share-dir" from the returned path int len = strlen(path); if (len > 16) { path[len - 16] = '\0'; } char *locale_base = g_build_filename(path, "locale", NULL); fs_log("using locale dir \"%s\"\n", locale_base); bindtextdomain("fs-uae", locale_base); free(locale_base); free(path); } bind_textdomain_codeset("fs-uae", "UTF-8"); #endif }
template <typename T> void ImagesClass<T>::setImplementation(int i) { char str[100]; clMath::BlasBase *base = clMath::BlasBase::getInstance(); if (i != I_IMAGES) { if (base->useImages()) { base->removeScratchImages(); } base->setUseImages(false); } #if WIN32 if (i == I_DEFAULT) { sprintf (str, "%s=", metod.env); } else { sprintf (str, "%s=%i",metod.env, i); } _putenv(str); #else if (i == I_DEFAULT) { str[0] = '\0'; } else { sprintf (str, "%i", i); } setenv(metod.env, str, 1); #endif if (i == I_IMAGES) { base->setUseImages(true); if (base->useImages()) { if (base->addScratchImages()) { std::cerr << ">> FATAL ERROR, CANNOT CREATE SCRATCH IMAGES!" << std::endl << ">> Test skipped." << ::std::endl; SUCCEED(); } } } }
int pa_set_root(HANDLE handle) { char library_path[MAX_PATH + sizeof(PULSE_ROOTENV) + 1], *sep; strcpy(library_path, PULSE_ROOTENV "="); if (!GetModuleFileName(handle, library_path + sizeof(PULSE_ROOTENV), MAX_PATH)) return 0; sep = strrchr(library_path, PA_PATH_SEP_CHAR); if (sep) *sep = '\0'; if (_putenv(library_path) < 0) return 0; return 1; }
void Q_setenv( const char *name, const char *value ) { #ifdef _WIN32 if( !value ) { value = ""; } #if( _MSC_VER >= 1400 ) _putenv_s( name, value ); #else _putenv( va( "%s=%s", name, value ) ); #endif #else // _WIN32 if( value ) { setenv( name, value, 1 ); } else { unsetenv( name ); } #endif // !_WIN32 }
/** * Constructor. */ Menu::Menu() { /* Initialize defaults, Video and Audio */ if( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)==(-1) ) { system("pause"); exit(-1); } _putenv(_strdup("SDL_VIDEO_CENTERED=1")); /* Set up the video */ int WINWIDTH = 800, WINHEIGHT = 600, BPP = 32; screen = SDL_SetVideoMode( WINWIDTH,WINHEIGHT, BPP, SDL_SWSURFACE ); if( screen == NULL ) { exit(1); } SDL_ShowCursor( SDL_DISABLE ); stateContext = new MenuStateContext(new GameMenuState()); }
/*--------------------------------------------------------------------------*/ static BOOL AddScilabBinDirectoryToPATHEnvironnementVariable(char *DefaultPath) { #define SCILAB_BIN_PATH "%s/bin" #define NEW_PATH "PATH=%s;%s" BOOL bOK = FALSE; char *PATH = NULL; char *env = NULL; char scilabBinPath[MAX_PATH]; char *scilabBinPathConverted; PATH = getenv("PATH"); env = (char*) MALLOC(sizeof(char) * (strlen(NEW_PATH) + strlen(PATH) + strlen(DefaultPath) + 1)); if (env) { sprintf(scilabBinPath, SCILAB_BIN_PATH, DefaultPath); scilabBinPathConverted = (char*) MALLOC(MAX_PATH * sizeof(char)); #ifdef _MSC_VER scilabBinPathConverted = strsub(scilabBinPath, "/", "\\"); #else scilabBinPathConverted = strdup(scilabBinPath); #endif if (stristr(PATH, scilabBinPathConverted) == 0) { sprintf(env, NEW_PATH, scilabBinPathConverted, PATH); if (_putenv (env)) { bOK = FALSE; } else { bOK = TRUE; } FREE(env); env = NULL; } FREE(scilabBinPathConverted); } return bOK; }
static void test_environment_manipulation(void) { ok( _putenv("cat=") == 0, "_putenv failed on deletion of nonexistent environment variable\n" ); ok( _putenv("cat=dog") == 0, "failed setting cat=dog\n" ); ok( strcmp(getenv("cat"), "dog") == 0, "getenv did not return 'dog'\n" ); ok( _putenv("cat=") == 0, "failed deleting cat\n" ); ok( _putenv("=") == -1, "should not accept '=' as input\n" ); ok( _putenv("=dog") == -1, "should not accept '=dog' as input\n" ); ok( _putenv(a_very_long_env_string) == 0, "_putenv failed for long environment string\n"); ok( getenv("nonexistent") == NULL, "getenv should fail with nonexistent var name\n" ); }
int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd ) {//S$-c char* dxPlacementEnvVarValue("DXSDK_DIR=C:\Program Files (x86)\Microsoft DirectX SDK (August 2007)"); //S$-a _putenv(dxPlacementEnvVarValue); //S$-a if (false != CGame::GetInst().Create("Arkanoid.xml")) { CGame::GetInst().SetSettings(new CBaseSettings("PIPE Studio", "Arkanoid")); CGame::GetInst().OnShow(); new CArkanoidController(SC_01); CPreloadManager::GetInst().LoadFonts(); CGame::GetInst().StartScene(); CGame::GetInst().Run(); delete CRndGen::GetPtr(); } delete CGame::GetPtr(); return 0; }
openssl_scope() { ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); const boost::filesystem::path& boostPath = _configurationFilePath; if(boostPath.empty() == false) { std::string varSetting("OPENSSL_CONF="); varSetting += _configurationFilePath.to_native_ansi_path(); #if defined(WIN32) _putenv((char*)varSetting.c_str()); #else putenv((char*)varSetting.c_str()); #endif } OPENSSL_config(nullptr); }
int setenv(const char *name, const char *value, int overwrite) { char *old_name; char *str; size_t length; int res; if (!name || !*name) return -1; /* if '=' is found, return EINVAL */ if (strchr (name, '=')) { errno = EINVAL; return -1; } /* if name is already set and overwrite is 0, we exit with success */ old_name = getenv(name); if (!overwrite && old_name) return 0; length = value ? strlen(value) : 0; length += strlen(name) + 2; str = (char *)malloc(length); if (!str) { errno = ENOMEM; return -1; } if (!value) sprintf(str, "%s=", name); else sprintf(str, "%s=%s", name, value); res = _putenv(str); free(str); return res; }
static int setenv_with_putenv(const char *name, const char *value) { if(NULL != VMPI_strchr(name, '=')) { errno = EINVAL; return -1; } else { size_t nameLen = VMPI_strlen(name); size_t valueLen = VMPI_strlen(value); size_t required = 1 + nameLen + 1 + valueLen; char buffer_[101]; char *buffer = (ARRAY_SIZE(buffer_) < required) ? (char*)malloc(required * sizeof(char)) : &buffer_[0]; if(NULL == buffer) { errno = ENOMEM; return -1; } else { int r; (void)VMPI_strncpy(&buffer[0], name, nameLen); buffer[nameLen] = '='; buffer[nameLen + 1] = '\0'; (void)VMPI_strncpy(&buffer[nameLen + 1], value, valueLen); buffer[nameLen + 1 + valueLen] = '\0'; r = _putenv(&buffer[0]); if(buffer != &buffer_[0]) { VMPI_free(buffer); } return r; } } }
UInt32 GUCEFSetEnv( const char* key , const char* value ) {GUCEF_TRACE; #ifdef GUCEF_MSWIN_BUILD UInt32 retval; char* envstr = (char*) malloc( strlen( key ) + strlen( value )+2 ); sprintf( envstr, "%s=%s", key, value ); retval = _putenv( envstr ); free( envstr ); return retval == 0; #else return setenv( key, value, 1 ) == 0; #endif }
void Parrot_setenv(PARROT_INTERP, STRING *str_name, STRING *str_value) { char * const name = Parrot_str_to_cstring(interp, str_name); char * const value = Parrot_str_to_cstring(interp, str_value); assert(name != NULL); assert(value != NULL); { const int name_len = strlen(name); const int value_len = strlen(value); { char * const envstring = (char * const)mem_internal_allocate( name_len /* name */ + 1 /* '=' */ + value_len /* value */ + 1); /* string terminator */ /* Save a bit of time, by using the fact we already have the lengths, avoiding strcat */ strcpy(envstring, name); strcpy(envstring + name_len, "="); strcpy(envstring + name_len + 1, value); Parrot_str_free_cstring(name); Parrot_str_free_cstring(value); if (_putenv(envstring) == 0) { /* success */ mem_sys_free(envstring); } else { mem_sys_free(envstring); Parrot_x_force_error_exit(interp, 1, "Unable to set environment variable %s=%s", name, value); } } } }
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { // Must add 'bin' to the path.... char* pPath = getenv("PATH"); // Use the .EXE name to determine the root directory char moduleName[ MAX_PATH ]; char szBuffer[ 4096 ]; if ( !GetModuleFileName( hInstance, moduleName, MAX_PATH ) ) { MessageBox( 0, "Failed calling GetModuleFileName", "Launcher Error", MB_OK ); return 0; } // Get the root directory the .exe is in char* pRootDir = GetBaseDir( moduleName ); #ifdef _DEBUG int len = #endif sprintf( szBuffer, "PATH=%s\\bin\\;%s", pRootDir, pPath ); assert( len < 4096 ); _putenv( szBuffer ); HINSTANCE launcher = LoadLibrary("launcher.dll"); // STEAM OK ... filesystem not mounted yet if (!launcher) { char *pszError; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&pszError, 0, NULL); char szBuf[1024]; sprintf(szBuf, "Failed to load the launcher DLL:\n\n%s", pszError); MessageBox( 0, szBuf, "Launcher Error", MB_OK ); LocalFree(pszError); return 0; } LauncherMain_t main = (LauncherMain_t)GetProcAddress( launcher, "LauncherMain" ); return main( hInstance, hPrevInstance, lpCmdLine, nCmdShow ); }
int main(int argc, char* argv[]) { char *args[ARG_BUF_SIZE]; char base_path[PATH_BUF_SIZE + 1]; char script_path[PATH_BUF_SIZE + 1]; char shell_path[PATH_BUF_SIZE + 1]; char env_path[ENV_VAR_SIZE]; int argi; _fullpath(shell_path, argv[0], PATH_BUF_SIZE); strcpy(script_path, shell_path); strcpy(base_path, shell_path); parent(shell_path); strcat(shell_path, "\\sh.exe"); remove_extension(script_path); parent(base_path); args[0] = shell_path; args[1] = "--norc"; args[2] = script_path; /* Any parameters passed on the command line will be passed through to the shell script */ for (argi = 0; argi < MIN(argc - 1, ARG_BUF_SIZE); argi++) { printf("%s\n", argv[argi + 1]); args[argi + NUM_EXEC_ARGS] = argv[argi + 1]; } /* Signal the end of the argument list */ args[argi + NUM_EXEC_ARGS] = NULL; /* Add this executable's directory to the path */ strcpy(env_path, "PATH="); strcat(env_path, getenv("PATH")); strcat(env_path, ";"); strcat(env_path, base_path); _putenv(env_path); _spawnv(_P_WAIT, args[0], &args[1]); _flushall(); }
BOOL wfreerdp_client_global_init(void) { WSADATA wsaData; if (!getenv("HOME")) { char home[MAX_PATH * 2] = "HOME="; strcat(home, getenv("HOMEDRIVE")); strcat(home, getenv("HOMEPATH")); _putenv(home); } WSAStartup(0x101, &wsaData); #if defined(WITH_DEBUG) || defined(_DEBUG) wf_create_console(); #endif freerdp_register_addin_provider(freerdp_channels_load_static_addin_entry, 0); return TRUE; }
//! This function is documented in the header file void init_gpu(const gmx_device_info_t *deviceInfo) { assert(deviceInfo); // If the device is NVIDIA, for safety reasons we disable the JIT // caching as this is known to be broken at least until driver 364.19; // the cache does not always get regenerated when the source code changes, // e.g. if the path to the kernel sources remains the same if (deviceInfo->vendor_e == OCL_VENDOR_NVIDIA) { // Ignore return values, failing to set the variable does not mean // that something will go wrong later. #ifdef _MSC_VER _putenv("CUDA_CACHE_DISABLE=1"); #else // Don't override, maybe a dev is testing. setenv("CUDA_CACHE_DISABLE", "1", 0); #endif } }
static void gen_bin(char *name, char *full_src, char *minus) { // doesn't have to use full path because chdir(gcin user dir) minus[0]=0; char src[128]; strcat(strcpy(src, name),".src"); dbg("gen_bin %s %s\n", name, src); if (get_gcin_user_fname(src, full_src)) { dbg("%s %s\n", name, full_src); #if UNIX putenv("GCIN_NO_RELOAD="); unix_exec(GCIN_BIN_DIR"/tsa2d32 %s %s", src, name); #else _putenv("GCIN_NO_RELOAD=Y"); win32exec_va("tsa2d32", src, name, NULL); #endif sprintf(minus, " -minus %s", name); } else dbg("not exist %s\n", full_src); }
static void initialize_path() { char mclmcrrt_name[_MAX_PATH]; char* pSysPath=NULL; char matlabroot[_MAX_PATH]; memset(matlabroot,_MAX_PATH,0); build_mclmcrrt_name("9","0","0",mclmcrrt_name); if (pSysPath = getenv("PATH")) { char* newPath = (char *) malloc((strlen(pSysPath)+_MAX_PATH+1)*sizeof(char)); char* pch =NULL; newPath[0]='\0'; strcat(newPath,"PATH="); strcat(newPath,pSysPath); pch = strtok(pSysPath,";"); while (pch != NULL) { char filepath[_MAX_PATH]; strcpy(filepath,pch); strcat(filepath,"\\"); strcat(filepath,mclmcrrt_name); if (file_exist(filepath)) { strcpy(matlabroot,pch); strcat(matlabroot,"\\..\\.."); break; } pch = strtok(NULL,";"); } if (strlen(matlabroot)!=0) { strcat(matlabroot,"\\bin\\"); strcat(matlabroot,"win64"); strcat(newPath,";"); strcat(newPath,matlabroot); _putenv(newPath); } free(newPath); } }