Пример #1
0
bool setEnv(string const & name, string const & value)
{
	// CHECK Look at and fix this.
	// f.ex. what about error checking?

	string encoded;
	try {
		encoded = to_local8bit(from_utf8(value));
	} catch (...) {
		return false;
	}

#if defined (HAVE_SETENV)
	return ::setenv(name.c_str(), encoded.c_str(), 1) == 0;
#elif defined (HAVE_PUTENV)
	// According to http://pubs.opengroup.org/onlinepubs/9699919799/functions/putenv.html
	// the argument of putenv() needs to be static, because changing its
	// value will change the environment. Therefore we need a different static
	// storage for each variable.
	// FIXME THREAD
	static map<string, string> varmap;
	varmap[name] = name + '=' + encoded;
	return ::putenv(const_cast<char*>(varmap[name].c_str())) == 0;
#else
#error No environment-setting function has been defined.
#endif
	return false;
}
Пример #2
0
bool setEnv(string const & name, string const & value)
{
	// CHECK Look at and fix this.
	// f.ex. what about error checking?

	string const encoded = to_local8bit(from_utf8(value));
#if defined (HAVE_SETENV)
	return ::setenv(name.c_str(), encoded.c_str(), 1) == 0;
#elif defined (HAVE_PUTENV)
	static map<string, string> varmap;
	varmap[name] = name + '=' + encoded;
	return ::putenv(const_cast<char*>(varmap[name].c_str())) == 0;
#else
#error No environment-setting function has been defined.
#endif
	return false;
}