Index: runtime/bin/directory_macos.cc |
diff --git a/runtime/bin/directory_macos.cc b/runtime/bin/directory_macos.cc |
index 5757a9c1a05075795acf968827ede4c2c4fa463d..e046bb5683f33db3bdbeb8d9d692c69275cae8d1 100644 |
--- a/runtime/bin/directory_macos.cc |
+++ b/runtime/bin/directory_macos.cc |
@@ -361,27 +361,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; |
@@ -393,11 +391,7 @@ char* Directory::CreateTemp(const char* const_template, bool system) { |
if (result == NULL) { |
return NULL; |
} |
- int length = strlen(path.AsString()); |
- result = static_cast<char*>(malloc(length + 1)); |
- strncpy(result, path.AsString(), length); |
- result[length] = '\0'; |
- return result; |
+ return strdup(result); |
} |