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

Side by Side Diff: bin/dartutils.cc

Issue 10344010: Canonicalize the reference_dir also when canonicalizing a path (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/vm/vm.status » ('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) 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/dartutils.h" 5 #include "bin/dartutils.h"
6 6
7 #include "bin/file.h" 7 #include "bin/file.h"
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/globals.h" 10 #include "platform/globals.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 return Dart_Error("wrong tag"); 225 return Dart_Error("wrong tag");
226 } 226 }
227 227
228 228
229 const char* DartUtils::GetCanonicalPath(const char* reference_dir, 229 const char* DartUtils::GetCanonicalPath(const char* reference_dir,
230 const char* filename) { 230 const char* filename) {
231 if (File::IsAbsolutePath(filename)) { 231 if (File::IsAbsolutePath(filename)) {
232 return strdup(filename); 232 return strdup(filename);
233 } 233 }
234 234
235 char* path = strdup(reference_dir); 235 char* canonical_path = File::GetCanonicalPath(reference_dir);
236 if (path == NULL) { 236 if (canonical_path == NULL) {
237 return NULL; 237 canonical_path = strdup(reference_dir);
238 ASSERT(canonical_path != NULL);
238 } 239 }
239 char* path_sep = strrchr(path, File::PathSeparator()[0]); 240 ASSERT(File::PathSeparator() != NULL && strlen(File::PathSeparator()) == 1);
241 char* path_sep = strrchr(canonical_path, File::PathSeparator()[0]);
240 if (path_sep == NULL) { 242 if (path_sep == NULL) {
241 // No separator found: Reference is a file in local directory. 243 // No separator found: Reference is a file in local directory.
244 free(canonical_path);
242 return strdup(filename); 245 return strdup(filename);
243 } 246 }
244 *path_sep = '\0'; 247 *path_sep = '\0';
245 intptr_t len = snprintf(NULL, 0, "%s%s%s", 248 intptr_t len = snprintf(NULL, 0, "%s%s%s",
246 path, File::PathSeparator(), filename); 249 canonical_path, File::PathSeparator(), filename);
247 char* absolute_filename = reinterpret_cast<char*>(malloc(len + 1)); 250 char* absolute_filename = reinterpret_cast<char*>(malloc(len + 1));
248 ASSERT(absolute_filename != NULL); 251 ASSERT(absolute_filename != NULL);
249 252
250 snprintf(absolute_filename, len + 1, "%s%s%s", 253 snprintf(absolute_filename, len + 1, "%s%s%s",
251 path, File::PathSeparator(), filename); 254 canonical_path, File::PathSeparator(), filename);
252 255 free(canonical_path);
253 free(path); 256 canonical_path = File::GetCanonicalPath(absolute_filename);
254 char* canonical_filename = File::GetCanonicalPath(absolute_filename); 257 if (canonical_path == NULL) {
255 if (canonical_filename == NULL) {
256 return absolute_filename; 258 return absolute_filename;
257 } 259 }
258 free(absolute_filename); 260 free(absolute_filename);
259 return canonical_filename; 261 return canonical_path;
260 } 262 }
261 263
262 264
263 bool DartUtils::PostNull(Dart_Port port_id) { 265 bool DartUtils::PostNull(Dart_Port port_id) {
264 // Post a message with just the null object. 266 // Post a message with just the null object.
265 return Dart_PostCObject(port_id, CObject::Null()->AsApiCObject()); 267 return Dart_PostCObject(port_id, CObject::Null()->AsApiCObject());
266 } 268 }
267 269
268 270
269 bool DartUtils::PostInt32(Dart_Port port_id, int32_t value) { 271 bool DartUtils::PostInt32(Dart_Port port_id, int32_t value) {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 433
432 CObject* CObject::NewOSError(OSError* os_error) { 434 CObject* CObject::NewOSError(OSError* os_error) {
433 CObject* error_message = 435 CObject* error_message =
434 new CObjectString(CObject::NewString(os_error->message())); 436 new CObjectString(CObject::NewString(os_error->message()));
435 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); 437 CObjectArray* result = new CObjectArray(CObject::NewArray(3));
436 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); 438 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError)));
437 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); 439 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code())));
438 result->SetAt(2, error_message); 440 result->SetAt(2, error_message);
439 return result; 441 return result;
440 } 442 }
OLDNEW
« no previous file with comments | « no previous file | tests/vm/vm.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698