[video] Fix the refresh of movies with additional versions or extras
[xbmc.git] / xbmc / platform / Environment.cpp
blob4655dcc11ec4d660f9e2402b10409bcf27221542
1 /*
2 * Copyright (C) 2013-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 /**
10 * \file platform\Environment.cpp
11 * \brief Implements CEnvironment class functions.
13 * Some ideas were inspired by PostgreSQL's pgwin32_putenv function.
14 * Refined, updated, enhanced and modified for XBMC by Karlson2k.
17 #include "Environment.h"
19 #include <stdlib.h>
22 // --------------------- Main Functions ---------------------
24 int CEnvironment::setenv(const std::string &name, const std::string &value, int overwrite /*= 1*/)
26 #ifdef TARGET_WINDOWS
27 return (win_setenv(name, value, overwrite ? autoDetect : addOnly) == 0) ? 0 : -1;
28 #else
29 if (value.empty() && overwrite != 0)
30 return ::unsetenv(name.c_str());
31 return ::setenv(name.c_str(), value.c_str(), overwrite);
32 #endif
35 std::string CEnvironment::getenv(const std::string &name)
37 #ifdef TARGET_WINDOWS
38 return win_getenv(name);
39 #else
40 char * str = ::getenv(name.c_str());
41 if (str == NULL)
42 return "";
43 return str;
44 #endif
47 int CEnvironment::unsetenv(const std::string &name)
49 #ifdef TARGET_WINDOWS
50 return (win_setenv(name, "", deleteVariable)) == 0 ? 0 : -1;
51 #else
52 return ::unsetenv(name.c_str());
53 #endif
56 int CEnvironment::putenv(const std::string &envstring)
58 if (envstring.empty())
59 return 0;
60 size_t pos = envstring.find('=');
61 if (pos == 0) // '=' is the first character
62 return -1;
63 if (pos == std::string::npos)
64 return unsetenv(envstring);
65 if (pos == envstring.length()-1) // '=' is in last position
67 std::string name(envstring);
68 name.erase(name.length()-1, 1);
69 return unsetenv(name);
71 std::string name(envstring, 0, pos), value(envstring, pos+1);
73 return setenv(name, value);