#include "TemporaryFile.hpp"
#include "Util.hpp"
#include "exceptions.hpp"
+#include "legacy_util.hpp"
#include "third_party/fmt/core.h"
#include "ccache.hpp"
#include "exceptions.hpp"
+#include "third_party/fmt/core.h"
+
#include <algorithm>
#include <cassert>
#include <fstream>
#include "system.hpp"
#include "NonCopyable.hpp"
+#include "Util.hpp"
#include "legacy_util.hpp"
-#include "third_party/fmt/core.h"
#include "third_party/nonstd/optional.hpp"
#include <functional>
std::string m_secondary_config_path;
std::string m_base_dir = "";
- std::string m_cache_dir = fmt::format("{}/.ccache", get_home_directory());
+ std::string m_cache_dir = Util::get_home_directory() + "/.ccache";
uint32_t m_cache_dir_levels = 2;
std::string m_compiler = "";
std::string m_compiler_check = "mtime";
#include <algorithm>
#include <fstream>
+#ifdef HAVE_PWD_H
+# include <pwd.h>
+#endif
+
#ifdef HAVE_LINUX_FS_H
# include <linux/magic.h>
# include <sys/statfs.h>
progress_receiver(1.0);
}
+std::string
+get_home_directory()
+{
+ const char* p = getenv("HOME");
+ if (p) {
+ return p;
+ }
+#ifdef _WIN32
+ p = getenv("APPDATA");
+ if (p) {
+ return p;
+ }
+#endif
+#ifdef HAVE_GETPWUID
+ {
+ struct passwd* pwd = getpwuid(getuid());
+ if (pwd) {
+ return pwd->pw_dir;
+ }
+ }
+#endif
+ FATAL("Could not determine home directory from $HOME or getpwuid(3)");
+}
+
const char*
get_hostname()
{
#include "system.hpp"
#include "CacheFile.hpp"
-#include "Config.hpp"
#include "third_party/nonstd/optional.hpp"
#include "third_party/nonstd/string_view.hpp"
const ProgressReceiver& progress_receiver,
std::vector<std::shared_ptr<CacheFile>>& files);
+// Return the current user's home directory, or throw `FatalError` if it can't
+// be determined.
+std::string get_home_directory();
+
// Return a static string with the current hostname.
const char* get_hostname();
# include "Win32Util.hpp"
#endif
-#ifdef HAVE_PWD_H
-# include <pwd.h>
-#endif
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
-// Return current user's home directory, or throw FatalError if it can't be
-// determined.
-const char*
-get_home_directory()
-{
- const char* p = getenv("HOME");
- if (p) {
- return p;
- }
-#ifdef _WIN32
- p = getenv("APPDATA");
- if (p) {
- return p;
- }
-#endif
-#ifdef HAVE_GETPWUID
- {
- struct passwd* pwd = getpwuid(getuid());
- if (pwd) {
- return pwd->pw_dir;
- }
- }
-#endif
- FATAL("Could not determine home directory from $HOME or getpwuid(3)");
-}
-
// Return whether the argument is a full path.
bool
is_full_path(const char* path)
#include <string>
-const char* get_home_directory();
bool is_full_path(const char* path);
void update_mtime(const char* path);
void x_exit(int status) ATTR_NORETURN;
{
Config config;
- std::string expected_cache_dir =
- fmt::format("{}/.ccache", get_home_directory());
+ std::string expected_cache_dir = Util::get_home_directory() + "/.ccache";
CHECK(config.base_dir().empty());
CHECK(config.cache_dir() == expected_cache_dir);