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

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

Issue 2615473002: Signal an error for File.length on a directory (Closed)
Patch Set: Fix windows error code Created 3 years, 11 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
« no previous file with comments | « runtime/bin/file_fuchsia.cc ('k') | runtime/bin/file_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 "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_LINUX) 6 #if defined(TARGET_OS_LINUX)
7 7
8 #include "bin/file.h" 8 #include "bin/file.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } else { 368 } else {
369 errno = ENOENT; 369 errno = ENOENT;
370 } 370 }
371 return false; 371 return false;
372 } 372 }
373 373
374 374
375 int64_t File::LengthFromPath(const char* name) { 375 int64_t File::LengthFromPath(const char* name) {
376 struct stat64 st; 376 struct stat64 st;
377 if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) { 377 if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) {
378 // Signal an error if it's a directory.
379 if (S_ISDIR(st.st_mode)) {
380 errno = EISDIR;
381 return -1;
382 }
383 // Otherwise assume the caller knows what it's doing.
378 return st.st_size; 384 return st.st_size;
379 } 385 }
380 return -1; 386 return -1;
381 } 387 }
382 388
383 389
384 static int64_t TimespecToMilliseconds(const struct timespec& t) { 390 static int64_t TimespecToMilliseconds(const struct timespec& t) {
385 return static_cast<int64_t>(t.tv_sec) * 1000L + 391 return static_cast<int64_t>(t.tv_sec) * 1000L +
386 static_cast<int64_t>(t.tv_nsec) / 1000000L; 392 static_cast<int64_t>(t.tv_nsec) / 1000000L;
387 } 393 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 return ((file_1_info.st_ino == file_2_info.st_ino) && 542 return ((file_1_info.st_ino == file_2_info.st_ino) &&
537 (file_1_info.st_dev == file_2_info.st_dev)) 543 (file_1_info.st_dev == file_2_info.st_dev))
538 ? File::kIdentical 544 ? File::kIdentical
539 : File::kDifferent; 545 : File::kDifferent;
540 } 546 }
541 547
542 } // namespace bin 548 } // namespace bin
543 } // namespace dart 549 } // namespace dart
544 550
545 #endif // defined(TARGET_OS_LINUX) 551 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/file_fuchsia.cc ('k') | runtime/bin/file_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698