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

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

Issue 15832003: Change File.directory to not do any IO (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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
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 "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_WINDOWS) 6 #if defined(TARGET_OS_WINDOWS)
7 7
8 #include "bin/file.h" 8 #include "bin/file.h"
9 9
10 #include <fcntl.h> // NOLINT 10 #include <fcntl.h> // NOLINT
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 static_cast<wchar_t*>(malloc(required_size * sizeof(wchar_t))); 451 static_cast<wchar_t*>(malloc(required_size * sizeof(wchar_t)));
452 int written = GetFullPathNameW(system_name, required_size, path, NULL); 452 int written = GetFullPathNameW(system_name, required_size, path, NULL);
453 free(const_cast<wchar_t*>(system_name)); 453 free(const_cast<wchar_t*>(system_name));
454 ASSERT(written <= (required_size - 1)); 454 ASSERT(written <= (required_size - 1));
455 char* result = StringUtils::WideToUtf8(path); 455 char* result = StringUtils::WideToUtf8(path);
456 free(path); 456 free(path);
457 return result; 457 return result;
458 } 458 }
459 459
460 460
461 char* File::GetContainingDirectory(char* pathname) {
462 struct _stat st;
463 wchar_t* system_name = StringUtils::Utf8ToWide(pathname);
464 int stat_status = _wstat(system_name, &st);
465 if (stat_status == 0) {
466 if ((st.st_mode & S_IFMT) != S_IFREG) {
467 SetLastError(ERROR_FILE_NOT_FOUND);
468 free(system_name);
469 return NULL;
470 }
471 } else {
472 SetLastError(ERROR_FILE_NOT_FOUND);
473 free(system_name);
474 return NULL;
475 }
476 int required_size = GetFullPathNameW(system_name, 0, NULL, NULL);
477 wchar_t* path =
478 static_cast<wchar_t*>(malloc(required_size * sizeof(wchar_t)));
479 wchar_t* file_part = NULL;
480 int written =
481 GetFullPathNameW(system_name, required_size, path, &file_part);
482 free(system_name);
483 ASSERT(written == (required_size - 1));
484 ASSERT(file_part != NULL);
485 ASSERT(file_part > path);
486 ASSERT(file_part[-1] == L'\\');
487 file_part[-1] = '\0';
488 char* result = StringUtils::WideToUtf8(path);
489 free(path);
490 return result;
491 }
492
493
494 const char* File::PathSeparator() { 461 const char* File::PathSeparator() {
495 // This is already UTF-8 encoded. 462 // This is already UTF-8 encoded.
496 return "\\"; 463 return "\\";
497 } 464 }
498 465
499 466
500 const char* File::StringEscapedPathSeparator() { 467 const char* File::StringEscapedPathSeparator() {
501 // This is already UTF-8 encoded. 468 // This is already UTF-8 encoded.
502 return "\\\\"; 469 return "\\\\";
503 } 470 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 return kIdentical; 545 return kIdentical;
579 } else { 546 } else {
580 return kDifferent; 547 return kDifferent;
581 } 548 }
582 } 549 }
583 550
584 } // namespace bin 551 } // namespace bin
585 } // namespace dart 552 } // namespace dart
586 553
587 #endif // defined(TARGET_OS_WINDOWS) 554 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« no previous file with comments | « runtime/bin/file_patch.dart ('k') | sdk/lib/_internal/compiler/implementation/lib/io_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698