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

Side by Side Diff: runtime/bin/directory_fuchsia.cc

Issue 2480793002: clang-format runtime/bin (Closed)
Patch Set: Created 4 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
« no previous file with comments | « runtime/bin/directory_android.cc ('k') | runtime/bin/directory_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_FUCHSIA) 6 #if defined(TARGET_OS_FUCHSIA)
7 7
8 #include "bin/directory.h" 8 #include "bin/directory.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
11 #include <stdlib.h> // NOLINT 11 #include <stdlib.h> // NOLINT
12 #include <string.h> // NOLINT 12 #include <string.h> // NOLINT
13 #include <sys/stat.h> // NOLINT 13 #include <sys/stat.h> // NOLINT
14 #include <unistd.h> // NOLINT 14 #include <unistd.h> // NOLINT
15 15
16 #include "bin/dartutils.h" 16 #include "bin/dartutils.h"
17 #include "bin/file.h" 17 #include "bin/file.h"
18 #include "bin/platform.h" 18 #include "bin/platform.h"
19 #include "platform/signal_blocker.h" 19 #include "platform/signal_blocker.h"
20 20
21 namespace dart { 21 namespace dart {
22 namespace bin { 22 namespace bin {
23 23
24 PathBuffer::PathBuffer() : length_(0) { 24 PathBuffer::PathBuffer() : length_(0) {
(...skipping 28 matching lines...) Expand all
53 } 53 }
54 54
55 55
56 bool PathBuffer::Add(const char* name) { 56 bool PathBuffer::Add(const char* name) {
57 const intptr_t name_length = strnlen(name, PATH_MAX + 1); 57 const intptr_t name_length = strnlen(name, PATH_MAX + 1);
58 if (name_length == 0) { 58 if (name_length == 0) {
59 errno = EINVAL; 59 errno = EINVAL;
60 return false; 60 return false;
61 } 61 }
62 char* data = AsString(); 62 char* data = AsString();
63 int written = snprintf(data + length_, 63 int written = snprintf(data + length_, PATH_MAX - length_, "%s", name);
64 PATH_MAX - length_,
65 "%s",
66 name);
67 data[PATH_MAX] = '\0'; 64 data[PATH_MAX] = '\0';
68 if ((written <= (PATH_MAX - length_)) && 65 if ((written <= (PATH_MAX - length_)) && (written > 0) &&
69 (written > 0) &&
70 (static_cast<size_t>(written) == strnlen(name, PATH_MAX + 1))) { 66 (static_cast<size_t>(written) == strnlen(name, PATH_MAX + 1))) {
71 length_ += written; 67 length_ += written;
72 return true; 68 return true;
73 } else { 69 } else {
74 errno = ENAMETOOLONG; 70 errno = ENAMETOOLONG;
75 return false; 71 return false;
76 } 72 }
77 } 73 }
78 74
79 75
(...skipping 22 matching lines...) Expand all
102 Directory::ExistsResult Directory::Exists(const char* dir_name) { 98 Directory::ExistsResult Directory::Exists(const char* dir_name) {
103 struct stat entry_info; 99 struct stat entry_info;
104 int success = NO_RETRY_EXPECTED(stat(dir_name, &entry_info)); 100 int success = NO_RETRY_EXPECTED(stat(dir_name, &entry_info));
105 if (success == 0) { 101 if (success == 0) {
106 if (S_ISDIR(entry_info.st_mode)) { 102 if (S_ISDIR(entry_info.st_mode)) {
107 return EXISTS; 103 return EXISTS;
108 } else { 104 } else {
109 return DOES_NOT_EXIST; 105 return DOES_NOT_EXIST;
110 } 106 }
111 } else { 107 } else {
112 if ((errno == EACCES) || 108 if ((errno == EACCES) || (errno == EBADF) || (errno == EFAULT) ||
113 (errno == EBADF) || 109 (errno == ENOMEM) || (errno == EOVERFLOW)) {
114 (errno == EFAULT) ||
115 (errno == ENOMEM) ||
116 (errno == EOVERFLOW)) {
117 // Search permissions denied for one of the directories in the 110 // Search permissions denied for one of the directories in the
118 // path or a low level error occured. We do not know if the 111 // path or a low level error occured. We do not know if the
119 // directory exists. 112 // directory exists.
120 return UNKNOWN; 113 return UNKNOWN;
121 } 114 }
122 ASSERT((errno == ELOOP) || 115 ASSERT((errno == ELOOP) || (errno == ENAMETOOLONG) || (errno == ENOENT) ||
123 (errno == ENAMETOOLONG) ||
124 (errno == ENOENT) ||
125 (errno == ENOTDIR)); 116 (errno == ENOTDIR));
126 return DOES_NOT_EXIST; 117 return DOES_NOT_EXIST;
127 } 118 }
128 } 119 }
129 120
130 121
131 char* Directory::CurrentNoScope() { 122 char* Directory::CurrentNoScope() {
132 return getcwd(NULL, 0); 123 return getcwd(NULL, 0);
133 } 124 }
134 125
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 if (exists != EXISTS) { 216 if (exists != EXISTS) {
226 return false; 217 return false;
227 } 218 }
228 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0); 219 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0);
229 } 220 }
230 221
231 } // namespace bin 222 } // namespace bin
232 } // namespace dart 223 } // namespace dart
233 224
234 #endif // defined(TARGET_OS_LINUX) 225 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/directory_android.cc ('k') | runtime/bin/directory_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698