Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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, int64_t number) { | |
| 257 // Returns a new, unused directory name, modifying the contents of | |
| 258 // dir_template. Creates the directory with the permissions specified | |
| 259 // by the process umask. | |
| 260 // The return value must be freed by the caller. | |
| 261 char* path = static_cast<char*>(malloc(PATH_MAX + 1)); | |
| 262 strncpy(path, const_template, PATH_MAX + 1); | |
| 263 path[PATH_MAX] = '\0'; | |
| 264 int path_length = strlen(path); | |
| 265 if (path_length > 0) { | |
| 266 if (path[path_length - 1] == '/') { | |
| 267 snprintf(path + path_length, PATH_MAX - path_length, "temp_dir_XXXXXX"); | |
| 268 } else { | |
| 269 snprintf(path + path_length, PATH_MAX - path_length, "XXXXXX"); | |
| 270 } | |
| 271 } else { | |
| 272 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.
| |
| 273 } | |
| 274 char* result = mkdtemp(path); | |
| 275 if (result == NULL) { | |
| 276 // Return the empty string, but as a freeable array. | |
| 277 path[0] = '\0'; | |
| 278 } | |
| 279 return path; | |
| 280 } | |
| 281 | |
| 282 | |
| 256 bool Directory::Delete(const char* dir_name) { | 283 bool Directory::Delete(const char* dir_name) { |
| 257 return (rmdir(dir_name) == 0); | 284 return (rmdir(dir_name) == 0); |
| 258 } | 285 } |
| OLD | NEW |