forked from OSchip/llvm-project
Add a simple routine to determine the typical system directory for
temporary data. llvm-svn: 139725
This commit is contained in:
parent
0c40637012
commit
123dc70c50
|
@ -187,7 +187,7 @@ const StringRef root_name(StringRef path);
|
||||||
/// @result The root directory of \a path if it has one, otherwise
|
/// @result The root directory of \a path if it has one, otherwise
|
||||||
/// "".
|
/// "".
|
||||||
const StringRef root_directory(StringRef path);
|
const StringRef root_directory(StringRef path);
|
||||||
|
|
||||||
/// @brief Get root path.
|
/// @brief Get root path.
|
||||||
///
|
///
|
||||||
/// Equivalent to root_name + root_directory.
|
/// Equivalent to root_name + root_directory.
|
||||||
|
@ -264,6 +264,14 @@ const StringRef extension(StringRef path);
|
||||||
/// @result true if \a value is a path separator character on the host OS
|
/// @result true if \a value is a path separator character on the host OS
|
||||||
bool is_separator(char value);
|
bool is_separator(char value);
|
||||||
|
|
||||||
|
/// @brief Get the typical temporary directory for the system, e.g.,
|
||||||
|
/// "/var/tmp" or "C:/TEMP"
|
||||||
|
///
|
||||||
|
/// @param erasedOnReboot Whether to favor a path that is erased on reboot
|
||||||
|
/// rather than one that potentially persists longer.
|
||||||
|
/// @param Result Holds the resulting path name.
|
||||||
|
void system_temp_directory(bool erasedOnReboot, SmallVectorImpl<char> &result);
|
||||||
|
|
||||||
/// @brief Has root name?
|
/// @brief Has root name?
|
||||||
///
|
///
|
||||||
/// root_name != ""
|
/// root_name != ""
|
||||||
|
|
|
@ -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) {
|
bool has_root_name(const Twine &path) {
|
||||||
SmallString<128> path_storage;
|
SmallString<128> path_storage;
|
||||||
StringRef p = path.toStringRef(path_storage);
|
StringRef p = path.toStringRef(path_storage);
|
||||||
|
|
Loading…
Reference in New Issue