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

Unified Diff: runtime/bin/directory_posix.cc

Issue 8588029: Add Directory.createTemp() to asynchronously create a temporary directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use snprintf. Created 9 years, 1 month 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_posix.cc
diff --git a/runtime/bin/directory_posix.cc b/runtime/bin/directory_posix.cc
index 21cc054db8bebde6617d05c1ca4704031bc7c722..66962f3bbec49ef6dc92dbbe20fdb649fd1cb51a 100644
--- a/runtime/bin/directory_posix.cc
+++ b/runtime/bin/directory_posix.cc
@@ -253,6 +253,33 @@ bool Directory::Create(const char* dir_name) {
}
+char* Directory::CreateTemp(const char* const_template, int64_t number) {
+ // 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.
+ char* path = static_cast<char*>(malloc(PATH_MAX + 1));
+ strncpy(path, const_template, PATH_MAX + 1);
+ path[PATH_MAX] = '\0';
+ int path_length = strlen(path);
+ if (path_length > 0) {
+ if (path[path_length - 1] == '/') {
+ snprintf(path + path_length, PATH_MAX - path_length, "temp_dir_XXXXXX");
+ } else {
+ snprintf(path + path_length, PATH_MAX - path_length, "XXXXXX");
+ }
+ } else {
+ snprintf(path, PATH_MAX, "/tmp/temp_dir1_XXXXXX");
Mads Ager (google) 2011/11/21 16:29:37 Remove extra space between ',' and 'PATH_MAX'.
Bill Hesse 2011/11/22 12:49:39 Done.
+ }
+ char* result = mkdtemp(path);
+ if (result == NULL) {
+ // Return the empty string, but as a freeable array.
+ path[0] = '\0';
+ }
+ return path;
+}
+
+
bool Directory::Delete(const char* dir_name) {
return (rmdir(dir_name) == 0);
}

Powered by Google App Engine
This is Rietveld 408576698