| 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 <errno.h> | 5 #include <errno.h> |
| 6 #include <fcntl.h> | 6 #include <fcntl.h> |
| 7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 #include <libgen.h> | 9 #include <libgen.h> |
| 10 #include <limits.h> | 10 #include <limits.h> |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 128 |
| 129 bool File::Create(const char* name) { | 129 bool File::Create(const char* name) { |
| 130 int fd = open(name, O_RDONLY | O_CREAT, 0666); | 130 int fd = open(name, O_RDONLY | O_CREAT, 0666); |
| 131 if (fd < 0) { | 131 if (fd < 0) { |
| 132 return false; | 132 return false; |
| 133 } | 133 } |
| 134 return (close(fd) == 0); | 134 return (close(fd) == 0); |
| 135 } | 135 } |
| 136 | 136 |
| 137 | 137 |
| 138 bool File::Delete(const char* name) { |
| 139 int status = remove(name); |
| 140 if (status == -1) { |
| 141 return false; |
| 142 } |
| 143 return true; |
| 144 } |
| 145 |
| 146 |
| 138 char* File::GetCanonicalPath(const char* pathname) { | 147 char* File::GetCanonicalPath(const char* pathname) { |
| 139 char* abs_path = NULL; | 148 char* abs_path = NULL; |
| 140 if (pathname != NULL) { | 149 if (pathname != NULL) { |
| 141 // On some older MacOs versions the default behaviour of realpath allocating | 150 // On some older MacOs versions the default behaviour of realpath allocating |
| 142 // space for the resolved_path when a NULL is passed in does not seem to | 151 // space for the resolved_path when a NULL is passed in does not seem to |
| 143 // work, so we explicitly allocate space. The caller is responsible for | 152 // work, so we explicitly allocate space. The caller is responsible for |
| 144 // freeing this space as in a regular realpath call. | 153 // freeing this space as in a regular realpath call. |
| 145 char* resolved_path = reinterpret_cast<char*>(malloc(PATH_MAX+1)); | 154 char* resolved_path = reinterpret_cast<char*>(malloc(PATH_MAX+1)); |
| 146 ASSERT(resolved_path != NULL); | 155 ASSERT(resolved_path != NULL); |
| 147 abs_path = realpath(pathname, resolved_path); | 156 abs_path = realpath(pathname, resolved_path); |
| 148 assert(abs_path == NULL || IsAbsolutePath(abs_path)); | 157 assert(abs_path == NULL || IsAbsolutePath(abs_path)); |
| 149 } | 158 } |
| 150 return abs_path; | 159 return abs_path; |
| 151 } | 160 } |
| 152 | 161 |
| 153 | 162 |
| 154 const char* File::PathSeparator() { | 163 const char* File::PathSeparator() { |
| 155 return "/"; | 164 return "/"; |
| 156 } | 165 } |
| 157 | 166 |
| 158 | 167 |
| 159 const char* File::StringEscapedPathSeparator() { | 168 const char* File::StringEscapedPathSeparator() { |
| 160 return "/"; | 169 return "/"; |
| 161 } | 170 } |
| OLD | NEW |