summaryrefslogtreecommitdiffstats
path: root/base/file_util_posix.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/file_util_posix.cc')
-rw-r--r--base/file_util_posix.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 8947d6a..4d4e572 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -10,6 +10,7 @@
#include <fnmatch.h>
#include <libgen.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/errno.h>
#include <sys/mman.h>
@@ -21,6 +22,8 @@
#if defined(OS_MACOSX)
#include <AvailabilityMacros.h>
+#else
+#include <glib.h>
#endif
#include <fstream>
@@ -728,6 +731,23 @@ bool GetShmemTempDir(FilePath* path) {
return true;
}
+FilePath GetHomeDir() {
+ const char* home_dir = getenv("HOME");
+ if (home_dir && home_dir[0])
+ return FilePath(home_dir);
+
+ home_dir = g_get_home_dir();
+ if (home_dir && home_dir[0])
+ return FilePath(home_dir);
+
+ FilePath rv;
+ if (file_util::GetTempDir(&rv))
+ return rv;
+
+ // Last resort.
+ return FilePath("/tmp");
+}
+
bool CopyFile(const FilePath& from_path, const FilePath& to_path) {
int infile = open(from_path.value().c_str(), O_RDONLY);
if (infile < 0)