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

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

Issue 12326007: dart:io Directory.list: Fix use of snprintf return value to work with both C99, Windows, and pre-C9… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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
« no previous file with comments | « runtime/bin/directory_macos.cc ('k') | no next file » | 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/directory.h" 5 #include "bin/directory.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 9
10 #include "bin/log.h" 10 #include "bin/log.h"
11 11
12 class PathBuffer { 12 class PathBuffer {
13 public: 13 public:
14 PathBuffer() : length(0) { 14 PathBuffer() : length(0) {
15 data = new wchar_t[MAX_PATH + 1]; 15 data = new wchar_t[MAX_PATH + 1];
16 } 16 }
17 17
18 ~PathBuffer() { 18 ~PathBuffer() {
19 delete[] data; 19 delete[] data;
20 } 20 }
21 21
22 wchar_t* data; 22 wchar_t* data;
23 int length; 23 int length;
24 24
25 bool Add(const wchar_t* name) { 25 bool Add(const wchar_t* name) {
26 size_t written = _snwprintf(data + length, 26 int written = _snwprintf(data + length,
27 MAX_PATH - length, 27 MAX_PATH - length,
28 L"%s", 28 L"%s",
29 name); 29 name);
30 data[MAX_PATH] = L'\0'; 30 data[MAX_PATH] = L'\0';
31 if (written == wcsnlen(name, MAX_PATH + 1)) { 31 if (written <= MAX_PATH - length &&
32 written >= 0 &&
33 static_cast<size_t>(written) == wcsnlen(name, MAX_PATH + 1)) {
32 length += written; 34 length += written;
33 return true; 35 return true;
34 } else { 36 } else {
35 SetLastError(ERROR_BUFFER_OVERFLOW); 37 SetLastError(ERROR_BUFFER_OVERFLOW);
36 return false; 38 return false;
37 } 39 }
38 } 40 }
39 41
40 void Reset(int new_length) { 42 void Reset(int new_length) {
41 length = new_length; 43 length = new_length;
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 bool success = Delete(new_path, true); 389 bool success = Delete(new_path, true);
388 if (!success) return false; 390 if (!success) return false;
389 } 391 }
390 DWORD flags = MOVEFILE_WRITE_THROUGH; 392 DWORD flags = MOVEFILE_WRITE_THROUGH;
391 int move_status = 393 int move_status =
392 MoveFileExW(system_path, system_new_path, flags); 394 MoveFileExW(system_path, system_new_path, flags);
393 free(const_cast<wchar_t*>(system_path)); 395 free(const_cast<wchar_t*>(system_path));
394 free(const_cast<wchar_t*>(system_new_path)); 396 free(const_cast<wchar_t*>(system_new_path));
395 return (move_status != 0); 397 return (move_status != 0);
396 } 398 }
OLDNEW
« no previous file with comments | « runtime/bin/directory_macos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698