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

Side by Side Diff: runtime/bin/directory_linux.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_android.cc ('k') | runtime/bin/directory_macos.cc » ('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/directory.h" 5 #include "bin/directory.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <string.h> 9 #include <string.h>
10 #include <sys/param.h> 10 #include <sys/param.h>
(...skipping 10 matching lines...) Expand all
21 } 21 }
22 22
23 ~PathBuffer() { 23 ~PathBuffer() {
24 delete[] data; 24 delete[] data;
25 } 25 }
26 26
27 char* data; 27 char* data;
28 int length; 28 int length;
29 29
30 bool Add(const char* name) { 30 bool Add(const char* name) {
31 size_t written = snprintf(data + length, 31 int written = snprintf(data + length,
32 PATH_MAX - length, 32 PATH_MAX - length,
33 "%s", 33 "%s",
34 name); 34 name);
35 data[PATH_MAX] = '\0'; 35 data[PATH_MAX] = '\0';
36 if (written == strnlen(name, PATH_MAX + 1)) { 36 if (written <= PATH_MAX - length &&
37 written >= 0 &&
38 static_cast<size_t>(written) == strnlen(name, PATH_MAX + 1)) {
37 length += written; 39 length += written;
38 return true; 40 return true;
39 } else { 41 } else {
40 errno = ENAMETOOLONG; 42 errno = ENAMETOOLONG;
41 return false; 43 return false;
42 } 44 }
43 } 45 }
44 46
45 void Reset(int new_length) { 47 void Reset(int new_length) {
46 length = new_length; 48 length = new_length;
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 return DeleteRecursively(&path); 378 return DeleteRecursively(&path);
377 } 379 }
378 } 380 }
379 381
380 382
381 bool Directory::Rename(const char* path, const char* new_path) { 383 bool Directory::Rename(const char* path, const char* new_path) {
382 ExistsResult exists = Exists(path); 384 ExistsResult exists = Exists(path);
383 if (exists != EXISTS) return false; 385 if (exists != EXISTS) return false;
384 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); 386 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0);
385 } 387 }
OLDNEW
« no previous file with comments | « runtime/bin/directory_android.cc ('k') | runtime/bin/directory_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698