]> git.lyx.org Git - lyx.git/blobdiff - src/support/environment.cpp
installer: further preparation
[lyx.git] / src / support / environment.cpp
index 67e55a731ea88f429ba57f40a566f8d3b084df17..a3539220d9457832b2b117cc21b48014ed307112 100644 (file)
@@ -28,10 +28,17 @@ using namespace std;
 namespace lyx {
 namespace support {
 
-string const getEnv(string const & envname)
+
+bool hasEnv(string const & name)
+{
+       return getenv(name.c_str());
+}
+
+
+string const getEnv(string const & name)
 {
        // f.ex. what about error checking?
-       char const * const ch = getenv(envname.c_str());
+       char const * const ch = getenv(name.c_str());
        return ch ? to_utf8(from_local8bit(ch)) : string();
 }
 
@@ -62,7 +69,7 @@ bool setEnv(string const & name, string const & value)
 
        string const encoded = to_local8bit(from_utf8(value));
 #if defined (HAVE_SETENV)
-       return ::setenv(name.c_str(), encoded.c_str(), true);
+       return ::setenv(name.c_str(), encoded.c_str(), 1) == 0;
 #elif defined (HAVE_PUTENV)
        static map<string, string> varmap;
        varmap[name] = name + '=' + encoded;
@@ -117,5 +124,20 @@ void prependEnvPath(string const & name, string const & prefix)
        setEnvPath(name, env_var);
 }
 
+
+bool unsetEnv(string const & name)
+{
+#if defined(HAVE_UNSETENV)
+       // FIXME: does it leak?
+       return ::unsetenv(name.c_str()) == 0;
+#elif defined(HAVE_PUTENV)
+       // This is OK with MSVC and MinGW at least.
+       return ::putenv(const_cast<char*>((name + "=").c_str())) == 0;
+#else
+#error No environment-unsetting function has been defined.
+#endif
+}
+
+
 } // namespace support
 } // namespace lyx