#include "third_party/fmt/core.h"
+#include <sys/types.h>
+
+#ifdef HAVE_PWD_H
+# include <pwd.h>
+#endif
+
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
}
#endif
+std::string
+home_directory()
+{
+#ifdef _WIN32
+ if (const char* p = getenv("USERPROFILE")) {
+ return p;
+ }
+ throw core::Fatal(
+ "The USERPROFILE environment variable must be set to your user profile"
+ " folder");
+#else
+ if (const char* p = getenv("HOME")) {
+ return p;
+ }
+# ifdef HAVE_GETPWUID
+ {
+ struct passwd* pwd = getpwuid(getuid());
+ if (pwd) {
+ return pwd->pw_dir;
+ }
+ }
+# endif
+ throw core::Fatal(
+ "Could not determine home directory from $HOME or getpwuid(3)");
+#endif
+}
+
std::string
compiler_type_to_string(CompilerType compiler_type)
{
auto cmdline_settings_map =
create_cmdline_settings_map(cmdline_config_settings);
- const std::string home_dir = Util::get_home_directory();
+ const std::string home_dir = home_directory();
const std::string legacy_ccache_dir = Util::make_path(home_dir, ".ccache");
const bool legacy_ccache_dir_exists =
Stat::stat(legacy_ccache_dir).is_directory();
#include <fcntl.h>
-#ifdef HAVE_PWD_H
-# include <pwd.h>
-#endif
-
using IncludeDelimiter = util::Tokenizer::IncludeDelimiter;
namespace fs = util::filesystem;
}
}
-std::string
-get_home_directory()
-{
-#ifdef _WIN32
- if (const char* p = getenv("USERPROFILE")) {
- return p;
- }
- throw core::Fatal(
- "The USERPROFILE environment variable must be set to your user profile "
- "folder");
-#else
- if (const char* p = getenv("HOME")) {
- return p;
- }
-# ifdef HAVE_GETPWUID
- {
- struct passwd* pwd = getpwuid(getuid());
- if (pwd) {
- return pwd->pw_dir;
- }
- }
-# endif
- throw core::Fatal(
- "Could not determine home directory from $HOME or getpwuid(3)");
-#endif
-}
-
const char*
get_hostname()
{
// `path` has no file extension, an empty string_view is returned.
std::string_view get_extension(std::string_view path);
-// Return the current user's home directory, or throw `Fatal` if it can't
-// be determined.
-std::string get_home_directory();
-
// Return a static string with the current hostname.
const char* get_hostname();