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

Side by Side 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: Added Windows code. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "bin/directory.h" 5 #include "bin/directory.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <sys/param.h> 9 #include <sys/param.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } 246 }
247 247
248 248
249 bool Directory::Create(const char* dir_name) { 249 bool Directory::Create(const char* dir_name) {
250 // Create the directory with the permissions specified by the 250 // Create the directory with the permissions specified by the
251 // process umask. 251 // process umask.
252 return (mkdir(dir_name, 0777) == 0); 252 return (mkdir(dir_name, 0777) == 0);
253 } 253 }
254 254
255 255
256 char* Directory::CreateTemp(const char* const_template) {
257 // Returns a new, unused directory name, modifying the contents of
258 // dir_template. Creates this directory, with mode ???.
Mads Ager (google) 2011/11/18 09:50:45 Update comment with the actual mode.
Bill Hesse 2011/11/21 15:48:41 Done.
259 // The return value must be freed by the caller.
260 char* path = static_cast<char*>(malloc(PATH_MAX + 1));
261 strncpy(path, const_template, PATH_MAX + 1);
262 path[PATH_MAX] = '\0';
263 char* result = mkdtemp(path);
264 if (result == NULL) {
265 // Return the empty string, but as a freeable array.
266 path[0] = '\0';
267 }
268 return path;
269 }
270
271
256 bool Directory::Delete(const char* dir_name) { 272 bool Directory::Delete(const char* dir_name) {
257 return (rmdir(dir_name) == 0); 273 return (rmdir(dir_name) == 0);
258 } 274 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698