Chromium Code Reviews| Index: runtime/bin/directory_linux.cc |
| diff --git a/runtime/bin/directory_linux.cc b/runtime/bin/directory_linux.cc |
| index 88c6f7cfe47934b601352dff9dd0703be003411f..86eb137490a3ba4155b48a94e97ff5788225127a 100644 |
| --- a/runtime/bin/directory_linux.cc |
| +++ b/runtime/bin/directory_linux.cc |
| @@ -9,6 +9,7 @@ |
| #include <dirent.h> // NOLINT |
| #include <errno.h> // NOLINT |
| +#include <stdlib.h> // NOLINT |
| #include <string.h> // NOLINT |
| #include <sys/param.h> // NOLINT |
| #include <sys/stat.h> // NOLINT |
| @@ -372,18 +373,24 @@ bool Directory::Create(const char* dir_name) { |
| } |
| -char* Directory::CreateTemp(const char* const_template) { |
| +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 |
| // by the process umask. |
| // The return value must be freed by the caller. |
| PathBuffer path; |
| - path.Add(const_template); |
| - if (path.length() == 0) { |
| - path.Add("/tmp/temp_dir1_"); |
| - } else if ((path.AsString())[path.length() - 1] == '/') { |
| - path.Add("temp_dir_"); |
| + if (system) { |
| + const char* temp_dir = getenv("TMPDIR"); |
|
Søren Gjesse
2013/10/01 14:28:47
Should we check TMP as well?
|
| + 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); |
| if (!path.Add("XXXXXX")) { |
| // Pattern has overflowed. |
| return NULL; |