Index: runtime/bin/directory_win.cc |
diff --git a/runtime/bin/directory_win.cc b/runtime/bin/directory_win.cc |
index 0f48408adc3cc71788df0c547de0dc2c7fb1ebc4..ae905c01decee344753032b7270660057f6cc599 100644 |
--- a/runtime/bin/directory_win.cc |
+++ b/runtime/bin/directory_win.cc |
@@ -5,6 +5,7 @@ |
#include "bin/directory.h" |
#include <errno.h> |
+#include <time.h> |
#include <sys/stat.h> |
#include "bin/platform.h" |
@@ -238,6 +239,35 @@ bool Directory::Create(const char* dir_name) { |
} |
+char* Directory::CreateTemp(const char* const_template) { |
Mads Ager (google)
2011/11/18 09:50:45
You are not using the template here. So we should
Bill Hesse
2011/11/21 15:48:41
We are using a non-empty template on both platform
|
+ // Returns a new, unused directory name, modifying the contents of |
+ // dir_template. Creates this directory, with mode ???. |
+ // The return value must be freed by the caller. |
+ char* path = static_cast<char*>(malloc(MAX_PATH)); |
+ int path_length = GetTempPath(MAX_PATH, path); |
+ if (path_length > MAX_PATH - 1) { |
+ path[0] = '\0'; |
Mads Ager (google)
2011/11/18 09:50:45
Funky indentation. Are there tabs here or somethin
Bill Hesse
2011/11/21 15:48:41
Done.
|
+ return path; |
+ } |
+ |
+ strncpy_s(path + path_length, MAX_PATH, "tempdir", 8); |
Mads Ager (google)
2011/11/18 09:50:45
Use snprintf instead. That is what we have done in
|
+ bool success = false; |
+ int tries = 0; |
+ int numeric_part = time(NULL) % 1000000; |
Mads Ager (google)
2011/11/18 09:50:45
We could use UuidCreate or something to make it mo
Bill Hesse
2011/11/21 15:48:41
Using Math.Random from dart.
On 2011/11/18 09:50:
|
+ while (!success && tries < 100) { |
+ sprintf(path + path_length + 7, "%.6d", numeric_part); |
Mads Ager (google)
2011/11/18 09:50:45
snprintf
|
+ success = CreateDirectory(path, NULL); |
+ if (!success) { |
+ numeric_part++; |
+ tries++; |
+ // Return the empty string, but as a freeable array. |
+ // path[0] = '\0'; |
Mads Ager (google)
2011/11/18 09:50:45
Commented out code and very strange indentation.
|
+ } |
+ } |
+ return path; |
+} |
+ |
+ |
bool Directory::Delete(const char* dir_name) { |
return (RemoveDirectory(dir_name) != 0); |
} |