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/dartutils.h" | 5 #include "bin/dartutils.h" |
6 | 6 |
7 #include "bin/file.h" | 7 #include "bin/file.h" |
8 #include "bin/globals.h" | 8 #include "bin/globals.h" |
9 | 9 |
10 const char* DartUtils::kDartScheme = "dart:"; | 10 const char* DartUtils::kDartScheme = "dart:"; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // Calculate the canonical path. | 123 // Calculate the canonical path. |
124 const char* canon_url_str = GetCanonicalPath(library_url_str, url_str); | 124 const char* canon_url_str = GetCanonicalPath(library_url_str, url_str); |
125 Dart_Handle canon_url = Dart_NewString(canon_url_str); | 125 Dart_Handle canon_url = Dart_NewString(canon_url_str); |
126 free(const_cast<char*>(canon_url_str)); | 126 free(const_cast<char*>(canon_url_str)); |
127 | 127 |
128 return canon_url; | 128 return canon_url; |
129 } | 129 } |
130 | 130 |
131 | 131 |
132 Dart_Handle DartUtils::ReadStringFromFile(const char* filename) { | 132 Dart_Handle DartUtils::ReadStringFromFile(const char* filename) { |
133 File* file = File::Open(filename, false); | 133 File* file = File::Open(filename, File::kRead); |
134 if (file == NULL) { | 134 if (file == NULL) { |
135 const char* format = "Unable to open file: %s"; | 135 const char* format = "Unable to open file: %s"; |
136 intptr_t len = snprintf(NULL, 0, format, filename); | 136 intptr_t len = snprintf(NULL, 0, format, filename); |
137 // TODO(iposva): Allocate from the zone instead of leaking error string | 137 // TODO(iposva): Allocate from the zone instead of leaking error string |
138 // here. On the other hand the binary is about the exit anyway. | 138 // here. On the other hand the binary is about the exit anyway. |
139 char* error_msg = reinterpret_cast<char*>(malloc(len + 1)); | 139 char* error_msg = reinterpret_cast<char*>(malloc(len + 1)); |
140 snprintf(error_msg, len + 1, format, filename); | 140 snprintf(error_msg, len + 1, format, filename); |
141 return Dart_Error(error_msg); | 141 return Dart_Error(error_msg); |
142 } | 142 } |
143 intptr_t len = file->Length(); | 143 intptr_t len = file->Length(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 path, File::PathSeparator(), filename); | 213 path, File::PathSeparator(), filename); |
214 | 214 |
215 free(path); | 215 free(path); |
216 char* canonical_filename = File::GetCanonicalPath(absolute_filename); | 216 char* canonical_filename = File::GetCanonicalPath(absolute_filename); |
217 if (canonical_filename == NULL) { | 217 if (canonical_filename == NULL) { |
218 return absolute_filename; | 218 return absolute_filename; |
219 } | 219 } |
220 free(absolute_filename); | 220 free(absolute_filename); |
221 return canonical_filename; | 221 return canonical_filename; |
222 } | 222 } |
OLD | NEW |