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

Unified Diff: runtime/bin/directory_macos.cc

Issue 25720002: Add Directory.systemTemp getter to replace createSystemTemp(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Don't add an extra / to a directory ending in // Created 7 years, 2 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
« no previous file with comments | « runtime/bin/directory_linux.cc ('k') | runtime/bin/directory_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « runtime/bin/directory_linux.cc ('k') | runtime/bin/directory_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698