diff options
| author | Douglas Gregor <dgregor@apple.com> | 2011-09-14 20:27:01 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2011-09-14 20:27:01 +0000 |
| commit | 123dc70c503bf6ddb68b20ee1a47bc4726f975fc (patch) | |
| tree | 61f567f32a30ed4f92faca64f0a2245fd5672e77 /llvm/lib/Support/PathV2.cpp | |
| parent | 0c40637012f8ed203c323a539ebd3ff0e0a1626c (diff) | |
| download | bcm5719-llvm-123dc70c503bf6ddb68b20ee1a47bc4726f975fc.tar.gz bcm5719-llvm-123dc70c503bf6ddb68b20ee1a47bc4726f975fc.zip | |
Add a simple routine to determine the typical system directory for
temporary data.
llvm-svn: 139725
Diffstat (limited to 'llvm/lib/Support/PathV2.cpp')
| -rw-r--r-- | llvm/lib/Support/PathV2.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/lib/Support/PathV2.cpp b/llvm/lib/Support/PathV2.cpp index c2880caa492..4d969fe25f9 100644 --- a/llvm/lib/Support/PathV2.cpp +++ b/llvm/lib/Support/PathV2.cpp @@ -490,6 +490,36 @@ bool is_separator(char value) { } } +void system_temp_directory(bool erasedOnReboot, SmallVectorImpl<char> &result) { + result.clear(); + + // Check whether the temporary directory is specified by an environment + // variable. + const char *EnvironmentVariable; +#ifdef LLVM_ON_WIN32 + EnvironmentVariable = "TEMP"; +#else + EnvironmentVariable = "TMPDIR"; +#endif + if (char *RequestedDir = getenv(EnvironmentVariable)) { + result.append(RequestedDir, RequestedDir + strlen(RequestedDir)); + return; + } + + // Fall back to a system default. + const char *DefaultResult; +#ifdef LLVM_ON_WIN32 + (void)erasedOnReboot; + DefaultResult = "C:\TEMP"; +#else + if (erasedOnReboot) + DefaultResult = "/tmp"; + else + DefaultResult = "/var/tmp"; +#endif + result.append(DefaultResult, DefaultResult + strlen(DefaultResult)); +} + bool has_root_name(const Twine &path) { SmallString<128> path_storage; StringRef p = path.toStringRef(path_storage); |

