| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 <string.h> | 9 #include <string.h> |
| 10 #include <sys/param.h> | 10 #include <sys/param.h> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 } | 21 } |
| 22 | 22 |
| 23 ~PathBuffer() { | 23 ~PathBuffer() { |
| 24 delete[] data; | 24 delete[] data; |
| 25 } | 25 } |
| 26 | 26 |
| 27 char* data; | 27 char* data; |
| 28 int length; | 28 int length; |
| 29 | 29 |
| 30 bool Add(const char* name) { | 30 bool Add(const char* name) { |
| 31 size_t written = snprintf(data + length, | 31 int written = snprintf(data + length, |
| 32 PATH_MAX - length, | 32 PATH_MAX - length, |
| 33 "%s", | 33 "%s", |
| 34 name); | 34 name); |
| 35 data[PATH_MAX] = '\0'; | 35 data[PATH_MAX] = '\0'; |
| 36 if (written == strlen(name)) { | 36 if (written <= PATH_MAX - length && |
| 37 written >= 0 && |
| 38 static_cast<size_t>(written) == strlen(name)) { |
| 37 length += written; | 39 length += written; |
| 38 return true; | 40 return true; |
| 39 } else { | 41 } else { |
| 40 errno = ENAMETOOLONG; | 42 errno = ENAMETOOLONG; |
| 41 return false; | 43 return false; |
| 42 } | 44 } |
| 43 } | 45 } |
| 44 | 46 |
| 45 void Reset(int new_length) { | 47 void Reset(int new_length) { |
| 46 length = new_length; | 48 length = new_length; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 return DeleteRecursively(&path); | 378 return DeleteRecursively(&path); |
| 377 } | 379 } |
| 378 } | 380 } |
| 379 | 381 |
| 380 | 382 |
| 381 bool Directory::Rename(const char* path, const char* new_path) { | 383 bool Directory::Rename(const char* path, const char* new_path) { |
| 382 ExistsResult exists = Exists(path); | 384 ExistsResult exists = Exists(path); |
| 383 if (exists != EXISTS) return false; | 385 if (exists != EXISTS) return false; |
| 384 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); | 386 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); |
| 385 } | 387 } |
| OLD | NEW |