Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Unified Diff: runtime/bin/directory_macos.cc

Issue 25279003: dart:io | Add Directory.CreateSystemTemp(template) and change Directory.CreateTemp(template). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add deadline for removing compatibility mode. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/bin/directory_macos.cc
diff --git a/runtime/bin/directory_macos.cc b/runtime/bin/directory_macos.cc
index 08232d539596e0109bec2cd91b3b1c3c23266a94..b73a3f370d1910bc6fca4d931b6802be0b5c8ef6 100644
--- a/runtime/bin/directory_macos.cc
+++ b/runtime/bin/directory_macos.cc
@@ -361,18 +361,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");
+ 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;
@@ -384,7 +390,7 @@ char* Directory::CreateTemp(const char* const_template) {
if (result == NULL) {
return NULL;
}
- int length = strlen(path.AsString());
+ int length = strnlen(path.AsString(), PATH_MAX);
result = static_cast<char*>(malloc(length + 1));
strncpy(result, path.AsString(), length);
result[length] = '\0';

Powered by Google App Engine
This is Rietveld 408576698