diff options
author | Douglas Gregor <dgregor@apple.com> | 2013-03-21 21:46:10 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2013-03-21 21:46:10 +0000 |
commit | a86ddf0411a733652e682c2ba0d35101199d4456 (patch) | |
tree | 64f257c31be49c8628cab0af91f65b3059e64d58 /llvm/lib | |
parent | 3d0ffd10aafeff23a101bb8c54e5e820d5b0a3e0 (diff) | |
download | bcm5719-llvm-a86ddf0411a733652e682c2ba0d35101199d4456.tar.gz bcm5719-llvm-a86ddf0411a733652e682c2ba0d35101199d4456.zip |
<rdar://problem/13477190> On Darwin, use DARWIN_USER_TEMP_DIR or DARWIN_USER_CACHE_DIR for the system temporary directory.
The DARWIN_USER_TEMP_DIR and DARWIN_USER_CACHE_DIR configuration
settings are more idiomatic for Darwin than the TMPDIR environment
variable.
llvm-svn: 177669
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Support/PathV2.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/Support/PathV2.cpp b/llvm/lib/Support/PathV2.cpp index 41add96194f..58a6ea720e7 100644 --- a/llvm/lib/Support/PathV2.cpp +++ b/llvm/lib/Support/PathV2.cpp @@ -18,6 +18,9 @@ #include <cctype> #include <cstdio> #include <cstring> +#ifdef __APPLE__ +#include <unistd.h> +#endif namespace { using llvm::StringRef; @@ -493,6 +496,27 @@ bool is_separator(char value) { void system_temp_directory(bool erasedOnReboot, SmallVectorImpl<char> &result) { result.clear(); +#ifdef __APPLE__ + // On Darwin, use DARWIN_USER_TEMP_DIR or DARWIN_USER_CACHE_DIR. + int ConfName = erasedOnReboot? _CS_DARWIN_USER_TEMP_DIR + : _CS_DARWIN_USER_CACHE_DIR; + size_t ConfLen = confstr(ConfName, 0, 0); + if (ConfLen > 0) { + do { + result.resize(ConfLen); + ConfLen = confstr(ConfName, result.data(), result.size()); + } while (ConfLen > 0 && ConfLen != result.size()); + + if (ConfLen > 0) { + assert(result.back() == 0); + result.pop_back(); + return; + } + + result.clear(); + } +#endif + // Check whether the temporary directory is specified by an environment // variable. const char *EnvironmentVariable; |