| Index: runtime/bin/directory_linux.cc
|
| diff --git a/runtime/bin/directory_linux.cc b/runtime/bin/directory_linux.cc
|
| index e12dbfdfabfcb2b786518e4b9de14212a82929b2..e0fd987dbbc658b22fc6c5dd80b1c61471541913 100644
|
| --- a/runtime/bin/directory_linux.cc
|
| +++ b/runtime/bin/directory_linux.cc
|
| @@ -373,27 +373,25 @@ bool Directory::Create(const char* dir_name) {
|
| }
|
|
|
|
|
| -char* Directory::CreateTemp(const char* const_template, bool system) {
|
| - // Returns a new, unused directory name, modifying the contents of
|
| - // dir_template. Creates the directory with the permissions specified
|
| +char* Directory::SystemTemp() {
|
| + const char* temp_dir = getenv("TMPDIR");
|
| + if (temp_dir == NULL) {
|
| + temp_dir = getenv("TMP");
|
| + }
|
| + if (temp_dir == NULL) {
|
| + temp_dir = "/tmp";
|
| + }
|
| + return strdup(temp_dir);
|
| +}
|
| +
|
| +
|
| +char* Directory::CreateTemp(const char* prefix) {
|
| + // Returns a new, unused directory name, adding characters to the end
|
| + // of prefix. Creates the directory with the permissions specified
|
| // by the process umask.
|
| // The return value must be freed by the caller.
|
| PathBuffer path;
|
| - if (system) {
|
| - const char* temp_dir = getenv("TMPDIR");
|
| - if (temp_dir == NULL) {
|
| - temp_dir = getenv("TMP");
|
| - }
|
| - if (temp_dir != NULL) {
|
| - path.Add(temp_dir);
|
| - if (temp_dir[strlen(temp_dir) - 1] != '/') {
|
| - path.Add("/");
|
| - }
|
| - } else {
|
| - path.Add("/tmp/");
|
| - }
|
| - }
|
| - path.Add(const_template);
|
| + path.Add(prefix);
|
| if (!path.Add("XXXXXX")) {
|
| // Pattern has overflowed.
|
| return NULL;
|
| @@ -405,11 +403,7 @@ char* Directory::CreateTemp(const char* const_template, bool system) {
|
| if (result == NULL) {
|
| return NULL;
|
| }
|
| - int length = strnlen(path.AsString(), PATH_MAX);
|
| - result = static_cast<char*>(malloc(length + 1));
|
| - strncpy(result, path.AsString(), length);
|
| - result[length] = '\0';
|
| - return result;
|
| + return strdup(result);
|
| }
|
|
|
|
|
|
|