| 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/file.h" | 5 #include "bin/file.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <io.h> | 8 #include <io.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 bool File::IsAbsolutePath(const char* pathname) { | 160 bool File::IsAbsolutePath(const char* pathname) { |
| 161 // Should we consider network paths? | 161 // Should we consider network paths? |
| 162 if (pathname == NULL) return false; | 162 if (pathname == NULL) return false; |
| 163 return (strlen(pathname) > 2) && | 163 return (strlen(pathname) > 2) && |
| 164 (pathname[1] == ':') && | 164 (pathname[1] == ':') && |
| 165 (pathname[2] == '\\'); | 165 (pathname[2] == '\\'); |
| 166 } | 166 } |
| 167 | 167 |
| 168 | 168 |
| 169 char* File::GetCanonicalPath(const char* pathname) { | 169 char* File::GetCanonicalPath(const char* pathname) { |
| 170 struct stat st; |
| 171 if (stat(pathname, &st) != 0) { |
| 172 SetLastError(ERROR_FILE_NOT_FOUND); |
| 173 return NULL; |
| 174 } |
| 170 int required_size = GetFullPathName(pathname, 0, NULL, NULL); | 175 int required_size = GetFullPathName(pathname, 0, NULL, NULL); |
| 171 char* path = static_cast<char*>(malloc(required_size)); | 176 char* path = static_cast<char*>(malloc(required_size)); |
| 172 int written = GetFullPathName(pathname, required_size, path, NULL); | 177 int written = GetFullPathName(pathname, required_size, path, NULL); |
| 173 ASSERT(written == (required_size - 1)); | 178 ASSERT(written == (required_size - 1)); |
| 174 return path; | 179 return path; |
| 175 } | 180 } |
| 176 | 181 |
| 177 | 182 |
| 178 char* File::GetContainingDirectory(char* pathname) { | 183 char* File::GetContainingDirectory(char* pathname) { |
| 184 struct stat st; |
| 185 if (stat(pathname, &st) == 0) { |
| 186 if ((st.st_mode & S_IFMT) != S_IFREG) { |
| 187 SetLastError(ERROR_FILE_NOT_FOUND); |
| 188 return NULL; |
| 189 } |
| 190 } else { |
| 191 SetLastError(ERROR_FILE_NOT_FOUND); |
| 192 return NULL; |
| 193 } |
| 179 int required_size = GetFullPathName(pathname, 0, NULL, NULL); | 194 int required_size = GetFullPathName(pathname, 0, NULL, NULL); |
| 180 char* path = static_cast<char*>(malloc(required_size)); | 195 char* path = static_cast<char*>(malloc(required_size)); |
| 181 char* file_part = NULL; | 196 char* file_part = NULL; |
| 182 int written = GetFullPathName(pathname, required_size, path, &file_part); | 197 int written = GetFullPathName(pathname, required_size, path, &file_part); |
| 183 ASSERT(written == (required_size - 1)); | 198 ASSERT(written == (required_size - 1)); |
| 184 ASSERT(file_part != NULL); | 199 ASSERT(file_part != NULL); |
| 185 ASSERT(file_part > path); | 200 ASSERT(file_part > path); |
| 186 ASSERT(file_part[-1] == '\\'); | 201 ASSERT(file_part[-1] == '\\'); |
| 187 file_part[-1] = '\0'; | 202 file_part[-1] = '\0'; |
| 188 return path; | 203 return path; |
| 189 } | 204 } |
| 190 | 205 |
| 191 | 206 |
| 192 const char* File::PathSeparator() { | 207 const char* File::PathSeparator() { |
| 193 return "\\"; | 208 return "\\"; |
| 194 } | 209 } |
| 195 | 210 |
| 196 | 211 |
| 197 const char* File::StringEscapedPathSeparator() { | 212 const char* File::StringEscapedPathSeparator() { |
| 198 return "\\\\"; | 213 return "\\\\"; |
| 199 } | 214 } |
| 200 | 215 |
| 201 | 216 |
| 202 File::StdioHandleType File::GetStdioHandleType(int fd) { | 217 File::StdioHandleType File::GetStdioHandleType(int fd) { |
| 203 // Treat all stdio handles as pipes. The Windows event handler and | 218 // Treat all stdio handles as pipes. The Windows event handler and |
| 204 // socket code will handle the different handle types. | 219 // socket code will handle the different handle types. |
| 205 return kPipe; | 220 return kPipe; |
| 206 } | 221 } |
| OLD | NEW |