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

Unified Diff: runtime/bin/directory_linux.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_android.cc ('k') | runtime/bin/directory_macos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « runtime/bin/directory_android.cc ('k') | runtime/bin/directory_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698