}
}
+void
+setenv(const std::string& name, const std::string& value)
+{
+#ifdef HAVE_SETENV
+ ::setenv(name.c_str(), value.c_str(), true);
+#else
+ char* string;
+ asprintf(&string, "%s=%s", name.c_str(), value.c_str());
+ putenv(string); // Leak to environment.
+#endif
+}
+
std::vector<string_view>
split_into_views(string_view input, const char* separators)
{
// `strip_colors` is true. Throws `Error` on error.
void send_to_stderr(const std::string& text, bool strip_colors);
+// Set environment variable `name` to `value`.
+void setenv(const std::string& name, const std::string& value);
+
// Split `input` into words at any of the characters listed in `separators`.
// These words are a view into `input`; empty words are omitted. `separators`
// must neither be the empty string nor a nullptr.
std::string relpath_both =
fmt::format("{} {}", args_info.output_dep, relpath_obj);
if (using_sunpro_dependencies) {
- x_setenv("SUNPRO_DEPENDENCIES", relpath_both.c_str());
+ Util::setenv("SUNPRO_DEPENDENCIES", relpath_both);
} else {
- x_setenv("DEPENDENCIES_OUTPUT", relpath_both.c_str());
+ Util::setenv("DEPENDENCIES_OUTPUT", relpath_both);
}
} else {
// It's the "file" form.
state.dependency_implicit_target_specified = true;
// Ensure that the compiler gets a relative path.
if (using_sunpro_dependencies) {
- x_setenv("SUNPRO_DEPENDENCIES", args_info.output_dep.c_str());
+ Util::setenv("SUNPRO_DEPENDENCIES", args_info.output_dep);
} else {
- x_setenv("DEPENDENCIES_OUTPUT", args_info.output_dep.c_str());
+ Util::setenv("DEPENDENCIES_OUTPUT", args_info.output_dep);
}
}
}
failed(STATS_ERROR);
}
- x_setenv("UNCACHED_ERR_FD", fmt::format("{}", uncached_fd).c_str());
+ Util::setenv("UNCACHED_ERR_FD", fmt::format("{}", uncached_fd));
}
static void
# include <sys/time.h>
#endif
-// This is like setenv.
-void
-x_setenv(const char* name, const char* value)
-{
-#ifdef HAVE_SETENV
- setenv(name, value, true);
-#else
- char* string;
- asprintf(&string, "%s=%s", name, value);
- putenv(string); // Leak to environment.
-#endif
-}
-
// This is like unsetenv.
void
x_unsetenv(const char* name)
#include <string>
-void x_setenv(const char* name, const char* value);
void x_unsetenv(const char* name);
#ifndef HAVE_LOCALTIME_R
struct tm* localtime_r(const time_t* timep, struct tm* result);
main(int argc, char** argv)
{
#ifdef _WIN32
- x_setenv("CCACHE_DETECT_SHEBANG", "1");
+ Util::setenv("CCACHE_DETECT_SHEBANG", "1");
#endif
x_unsetenv("GCC_COLORS"); // Don't confuse argument processing tests.
TestContext test_context;
const char user[] = "rabbit";
- x_setenv("USER", user);
+ Util::setenv("USER", user);
#ifndef _WIN32
std::string base_dir = fmt::format("/{0}/foo/{0}", user);
{
Config config;
- x_setenv("CCACHE_COMPRESS", "1");
+ Util::setenv("CCACHE_COMPRESS", "1");
config.update_from_environment();
CHECK(config.compression());
x_unsetenv("CCACHE_COMPRESS");
- x_setenv("CCACHE_NOCOMPRESS", "1");
+ Util::setenv("CCACHE_NOCOMPRESS", "1");
config.update_from_environment();
CHECK(!config.compression());
}
TEST_CASE("Util::expand_environment_variables")
{
- x_setenv("FOO", "bar");
+ Util::setenv("FOO", "bar");
CHECK(Util::expand_environment_variables("") == "");
CHECK(Util::expand_environment_variables("$FOO") == "bar");