#else
char* string;
asprintf(&string, "%s=%s", name.c_str(), value.c_str());
- putenv(string); // Leak to environment.
+ putenv(string); // Leak to environment.
#endif
}
return success;
}
+void
+unsetenv(const std::string& name)
+{
+#ifdef HAVE_UNSETENV
+ ::unsetenv(name.c_str());
+#else
+ putenv(strdup(name.c_str())); // Leak to environment.
+#endif
+}
+
void
wipe_path(const std::string& path)
{
bool unlink_tmp(const std::string& path,
UnlinkLog unlink_log = UnlinkLog::log_failure);
+// Unset environment variable `name`.
+void unsetenv(const std::string& name);
+
// Remove `path` (and its contents if it's a directory). A non-existing path is
// not considered an error.
//
// emit a line like this:
//
// tmp.stdout.vexed.732.o: /home/mbp/.ccache/tmp.stdout.vexed.732.i
- x_unsetenv("DEPENDENCIES_OUTPUT");
- x_unsetenv("SUNPRO_DEPENDENCIES");
+ Util::unsetenv("DEPENDENCIES_OUTPUT");
+ Util::unsetenv("SUNPRO_DEPENDENCIES");
if (ctx.config.run_second_cpp()) {
args.push_back(ctx.args_info.input_file);
# include <sys/time.h>
#endif
-// This is like unsetenv.
-void
-x_unsetenv(const char* name)
-{
-#ifdef HAVE_UNSETENV
- unsetenv(name);
-#else
- putenv(strdup(name)); // Leak to environment.
-#endif
-}
-
#if !defined(_WIN32) && !defined(HAVE_LOCALTIME_R)
// localtime_r replacement. (Mingw-w64 has an inline localtime_r which is not
// detected by AC_CHECK_FUNCS.)
#include <string>
-void x_unsetenv(const char* name);
#ifndef HAVE_LOCALTIME_R
struct tm* localtime_r(const time_t* timep, struct tm* result);
#endif
#ifdef _WIN32
Util::setenv("CCACHE_DETECT_SHEBANG", "1");
#endif
- x_unsetenv("GCC_COLORS"); // Don't confuse argument processing tests.
+ Util::unsetenv("GCC_COLORS"); // Don't confuse argument processing tests.
std::string dir_before = Util::get_actual_cwd();
std::string testdir = fmt::format("testdir.{}", getpid());
config.update_from_environment();
CHECK(config.compression());
- x_unsetenv("CCACHE_COMPRESS");
+ Util::unsetenv("CCACHE_COMPRESS");
Util::setenv("CCACHE_NOCOMPRESS", "1");
config.update_from_environment();