summaryrefslogtreecommitdiffstats
path: root/xbmc/platform/Environment.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
commitc04dcc2e7d834218ef2d4194331e383402495ae1 (patch)
tree7333e38d10d75386e60f336b80c2443c1166031d /xbmc/platform/Environment.cpp
parentInitial commit. (diff)
downloadkodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz
kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/platform/Environment.cpp')
-rw-r--r--xbmc/platform/Environment.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/xbmc/platform/Environment.cpp b/xbmc/platform/Environment.cpp
new file mode 100644
index 0000000..4655dcc
--- /dev/null
+++ b/xbmc/platform/Environment.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2013-2018 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+/**
+ * \file platform\Environment.cpp
+ * \brief Implements CEnvironment class functions.
+ *
+ * Some ideas were inspired by PostgreSQL's pgwin32_putenv function.
+ * Refined, updated, enhanced and modified for XBMC by Karlson2k.
+ */
+
+#include "Environment.h"
+
+#include <stdlib.h>
+
+
+// --------------------- Main Functions ---------------------
+
+int CEnvironment::setenv(const std::string &name, const std::string &value, int overwrite /*= 1*/)
+{
+#ifdef TARGET_WINDOWS
+ return (win_setenv(name, value, overwrite ? autoDetect : addOnly) == 0) ? 0 : -1;
+#else
+ if (value.empty() && overwrite != 0)
+ return ::unsetenv(name.c_str());
+ return ::setenv(name.c_str(), value.c_str(), overwrite);
+#endif
+}
+
+std::string CEnvironment::getenv(const std::string &name)
+{
+#ifdef TARGET_WINDOWS
+ return win_getenv(name);
+#else
+ char * str = ::getenv(name.c_str());
+ if (str == NULL)
+ return "";
+ return str;
+#endif
+}
+
+int CEnvironment::unsetenv(const std::string &name)
+{
+#ifdef TARGET_WINDOWS
+ return (win_setenv(name, "", deleteVariable)) == 0 ? 0 : -1;
+#else
+ return ::unsetenv(name.c_str());
+#endif
+}
+
+int CEnvironment::putenv(const std::string &envstring)
+{
+ if (envstring.empty())
+ return 0;
+ size_t pos = envstring.find('=');
+ if (pos == 0) // '=' is the first character
+ return -1;
+ if (pos == std::string::npos)
+ return unsetenv(envstring);
+ if (pos == envstring.length()-1) // '=' is in last position
+ {
+ std::string name(envstring);
+ name.erase(name.length()-1, 1);
+ return unsetenv(name);
+ }
+ std::string name(envstring, 0, pos), value(envstring, pos+1);
+
+ return setenv(name, value);
+}
+