]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
C++-ify x_unsetenv
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 30 Jul 2020 05:24:28 +0000 (07:24 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 30 Jul 2020 19:04:01 +0000 (21:04 +0200)
src/Util.cpp
src/Util.hpp
src/ccache.cpp
src/legacy_util.cpp
src/legacy_util.hpp
unittest/main.cpp
unittest/test_Config.cpp

index c6294dcc6133421e76d97ddba70f1dba91cfe957..e6c02e07bbb694c5ed603122d6762fe976b7cc3a 100644 (file)
@@ -1108,7 +1108,7 @@ setenv(const std::string& name, const std::string& value)
 #else
   char* string;
   asprintf(&string, "%s=%s", name.c_str(), value.c_str());
-  putenv(string); // Leak to environment.
+  putenv(string);               // Leak to environment.
 #endif
 }
 
@@ -1268,6 +1268,16 @@ unlink_tmp(const std::string& path, UnlinkLog unlink_log)
   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)
 {
index e01b8ffb2a1975c72d7f27fa983d2c0c1b254d5d..c3485c5c8463fc74705aae3872f8ce4fe9ccca4b 100644 (file)
@@ -387,6 +387,9 @@ bool unlink_safe(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.
 //
index a47f3af95b4526a75d1bed0944f3da8ffd5636e2..e1e49cdc8efda9921db252442fc0afd6447f0d4d 100644 (file)
@@ -843,8 +843,8 @@ to_cache(Context& ctx,
   // 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);
index e528d07dcf68c8ff48dfe7983d0a8c65a1da67bb..e77ee159eb641b26c8bef528796804edc53ffd88 100644 (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.)
index 7dabe62fe52c2ae118ad558acb06ee364e558c35..89e0973af35ed769e12366a561e3acb418798da7 100644 (file)
@@ -22,7 +22,6 @@
 
 #include <string>
 
-void x_unsetenv(const char* name);
 #ifndef HAVE_LOCALTIME_R
 struct tm* localtime_r(const time_t* timep, struct tm* result);
 #endif
index 53887e294b6103979be4c53c32473349a1a85261..645fc58964ad96a726ff89bce73f732fede29609 100644 (file)
@@ -31,7 +31,7 @@ main(int argc, char** argv)
 #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());
index c487e2f035dd895e5261960a947c2d90372567f3..454fcc24404417071624ebefe19227828a005652 100644 (file)
@@ -309,7 +309,7 @@ TEST_CASE("Config::update_from_environment")
   config.update_from_environment();
   CHECK(config.compression());
 
-  x_unsetenv("CCACHE_COMPRESS");
+  Util::unsetenv("CCACHE_COMPRESS");
 
   Util::setenv("CCACHE_NOCOMPRESS", "1");
   config.update_from_environment();