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

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

Issue 145623011: Allow paths up to 32767 characters on Windows (so '\\?\' can be used). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add windows file test. Created 6 years, 10 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/directory.h" 8 #include "bin/directory.h"
9 #include "bin/file.h" 9 #include "bin/file.h"
10 #include "bin/utils.h" 10 #include "bin/utils.h"
11 11
12 #include <errno.h> // NOLINT 12 #include <errno.h> // NOLINT
13 #include <sys/stat.h> // NOLINT 13 #include <sys/stat.h> // NOLINT
14 14
15 #include "bin/log.h" 15 #include "bin/log.h"
16 16
17 #undef DeleteFile 17 #undef DeleteFile
18 18
19 #define MAX_LONG_PATH 32767
20
19 namespace dart { 21 namespace dart {
20 namespace bin { 22 namespace bin {
21 23
22 PathBuffer::PathBuffer() : length_(0) { 24 PathBuffer::PathBuffer() : length_(0) {
23 data_ = calloc(MAX_PATH + 1, sizeof(wchar_t)); // NOLINT 25 data_ = calloc(MAX_LONG_PATH + 1, sizeof(wchar_t)); // NOLINT
24 } 26 }
25 27
26 char* PathBuffer::AsString() const { 28 char* PathBuffer::AsString() const {
27 return StringUtils::WideToUtf8(AsStringW()); 29 return StringUtils::WideToUtf8(AsStringW());
28 } 30 }
29 31
30 wchar_t* PathBuffer::AsStringW() const { 32 wchar_t* PathBuffer::AsStringW() const {
31 return reinterpret_cast<wchar_t*>(data_); 33 return reinterpret_cast<wchar_t*>(data_);
32 } 34 }
33 35
34 bool PathBuffer::Add(const char* name) { 36 bool PathBuffer::Add(const char* name) {
35 const wchar_t* wide_name = StringUtils::Utf8ToWide(name); 37 const wchar_t* wide_name = StringUtils::Utf8ToWide(name);
36 bool success = AddW(wide_name); 38 bool success = AddW(wide_name);
37 free(const_cast<wchar_t*>(wide_name)); 39 free(const_cast<wchar_t*>(wide_name));
38 return success; 40 return success;
39 } 41 }
40 42
41 bool PathBuffer::AddW(const wchar_t* name) { 43 bool PathBuffer::AddW(const wchar_t* name) {
42 wchar_t* data = AsStringW(); 44 wchar_t* data = AsStringW();
43 int written = _snwprintf(data + length_, 45 int written = _snwprintf(data + length_,
44 MAX_PATH - length_, 46 MAX_LONG_PATH - length_,
45 L"%s", 47 L"%s",
46 name); 48 name);
47 data[MAX_PATH] = L'\0'; 49 data[MAX_LONG_PATH] = L'\0';
48 if (written <= MAX_PATH - length_ && 50 if (written <= MAX_LONG_PATH - length_ &&
49 written >= 0 && 51 written >= 0 &&
50 static_cast<size_t>(written) == wcsnlen(name, MAX_PATH + 1)) { 52 static_cast<size_t>(written) == wcsnlen(name, MAX_LONG_PATH + 1)) {
51 length_ += written; 53 length_ += written;
52 return true; 54 return true;
53 } else { 55 } else {
54 SetLastError(ERROR_BUFFER_OVERFLOW); 56 SetLastError(ERROR_BUFFER_OVERFLOW);
55 return false; 57 return false;
56 } 58 }
57 } 59 }
58 60
59 void PathBuffer::Reset(int new_length) { 61 void PathBuffer::Reset(int new_length) {
60 length_ = new_length; 62 length_ = new_length;
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 free(const_cast<wchar_t*>(system_name)); 385 free(const_cast<wchar_t*>(system_name));
384 return true; 386 return true;
385 } 387 }
386 free(const_cast<wchar_t*>(system_name)); 388 free(const_cast<wchar_t*>(system_name));
387 return (create_status != 0); 389 return (create_status != 0);
388 } 390 }
389 391
390 392
391 char* Directory::SystemTemp() { 393 char* Directory::SystemTemp() {
392 PathBuffer path; 394 PathBuffer path;
393 path.Reset(GetTempPathW(MAX_PATH, path.AsStringW()) - 1); // Remove \ at end. 395 // Remove \ at end.
396 path.Reset(GetTempPathW(MAX_LONG_PATH, path.AsStringW()) - 1);
394 return path.AsString(); 397 return path.AsString();
395 } 398 }
396 399
397 400
398 char* Directory::CreateTemp(const char* prefix) { 401 char* Directory::CreateTemp(const char* prefix) {
399 // Returns a new, unused directory name, adding characters to the 402 // Returns a new, unused directory name, adding characters to the
400 // end of prefix. 403 // end of prefix.
401 // Creates this directory, with a default security 404 // Creates this directory, with a default security
402 // descriptor inherited from its parent directory. 405 // descriptor inherited from its parent directory.
403 // The return value must be freed by the caller. 406 // The return value must be freed by the caller.
404 PathBuffer path; 407 PathBuffer path;
405 const wchar_t* system_prefix = StringUtils::Utf8ToWide(prefix); 408 const wchar_t* system_prefix = StringUtils::Utf8ToWide(prefix);
406 path.AddW(system_prefix); 409 path.AddW(system_prefix);
407 free(const_cast<wchar_t*>(system_prefix)); 410 free(const_cast<wchar_t*>(system_prefix));
408 411
409 // Length of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx is 36. 412 // Length of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx is 36.
410 if (path.length() > MAX_PATH - 36) { 413 if (path.length() > MAX_LONG_PATH - 36) {
411 return NULL; 414 return NULL;
412 } 415 }
413 416
414 UUID uuid; 417 UUID uuid;
415 RPC_STATUS status = UuidCreateSequential(&uuid); 418 RPC_STATUS status = UuidCreateSequential(&uuid);
416 if (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) { 419 if (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) {
417 return NULL; 420 return NULL;
418 } 421 }
419 RPC_WSTR uuid_string; 422 RPC_WSTR uuid_string;
420 status = UuidToStringW(&uuid, &uuid_string); 423 status = UuidToStringW(&uuid, &uuid_string);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 MoveFileExW(system_path, system_new_path, flags); 474 MoveFileExW(system_path, system_new_path, flags);
472 free(const_cast<wchar_t*>(system_path)); 475 free(const_cast<wchar_t*>(system_path));
473 free(const_cast<wchar_t*>(system_new_path)); 476 free(const_cast<wchar_t*>(system_new_path));
474 return (move_status != 0); 477 return (move_status != 0);
475 } 478 }
476 479
477 } // namespace bin 480 } // namespace bin
478 } // namespace dart 481 } // namespace dart
479 482
480 #endif // defined(TARGET_OS_WINDOWS) 483 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/file_windows_test.dart » ('j') | tests/standalone/io/file_windows_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698