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

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

Issue 2480793002: clang-format runtime/bin (Closed)
Patch Set: Created 4 years, 1 month 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_linux.cc ('k') | runtime/bin/file_support.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_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include "bin/file.h" 8 #include "bin/file.h"
9 9
10 #include <copyfile.h> // NOLINT 10 #include <copyfile.h> // NOLINT
11 #include <errno.h> // NOLINT 11 #include <errno.h> // NOLINT
12 #include <fcntl.h> // NOLINT 12 #include <fcntl.h> // NOLINT
13 #include <libgen.h> // NOLINT 13 #include <libgen.h> // NOLINT
14 #include <limits.h> // NOLINT 14 #include <limits.h> // NOLINT
15 #include <sys/mman.h> // NOLINT 15 #include <sys/mman.h> // NOLINT
16 #include <sys/stat.h> // NOLINT 16 #include <sys/stat.h> // NOLINT
17 #include <unistd.h> // NOLINT 17 #include <unistd.h> // NOLINT
18 18
19 #include "bin/builtin.h" 19 #include "bin/builtin.h"
20 #include "bin/fdutils.h" 20 #include "bin/fdutils.h"
21 #include "bin/log.h" 21 #include "bin/log.h"
22 22
23 #include "platform/signal_blocker.h" 23 #include "platform/signal_blocker.h"
24 #include "platform/utils.h" 24 #include "platform/utils.h"
25 25
26 namespace dart { 26 namespace dart {
27 namespace bin { 27 namespace bin {
28 28
29 class FileHandle { 29 class FileHandle {
30 public: 30 public:
31 explicit FileHandle(int fd) : fd_(fd) { } 31 explicit FileHandle(int fd) : fd_(fd) {}
32 ~FileHandle() { } 32 ~FileHandle() {}
33 int fd() const { return fd_; } 33 int fd() const { return fd_; }
34 void set_fd(int fd) { fd_ = fd; } 34 void set_fd(int fd) { fd_ = fd; }
35 35
36 private: 36 private:
37 int fd_; 37 int fd_;
38 38
39 DISALLOW_COPY_AND_ASSIGN(FileHandle); 39 DISALLOW_COPY_AND_ASSIGN(FileHandle);
40 }; 40 };
41 41
42 42
43 File::~File() { 43 File::~File() {
44 if (!IsClosed() && 44 if (!IsClosed() && handle_->fd() != STDOUT_FILENO &&
45 handle_->fd() != STDOUT_FILENO && handle_->fd() != STDERR_FILENO) { 45 handle_->fd() != STDERR_FILENO) {
46 Close(); 46 Close();
47 } 47 }
48 delete handle_; 48 delete handle_;
49 } 49 }
50 50
51 51
52 void File::Close() { 52 void File::Close() {
53 ASSERT(handle_->fd() >= 0); 53 ASSERT(handle_->fd() >= 0);
54 if (handle_->fd() == STDOUT_FILENO) { 54 if (handle_->fd() == STDOUT_FILENO) {
55 // If stdout, redirect fd to /dev/null. 55 // If stdout, redirect fd to /dev/null.
(...skipping 30 matching lines...) Expand all
86 switch (type) { 86 switch (type) {
87 case kReadOnly: 87 case kReadOnly:
88 prot = PROT_READ; 88 prot = PROT_READ;
89 break; 89 break;
90 case kReadExecute: 90 case kReadExecute:
91 prot = PROT_READ | PROT_EXEC; 91 prot = PROT_READ | PROT_EXEC;
92 break; 92 break;
93 default: 93 default:
94 return NULL; 94 return NULL;
95 } 95 }
96 void* addr = mmap(NULL, length, prot, MAP_PRIVATE, 96 void* addr = mmap(NULL, length, prot, MAP_PRIVATE, handle_->fd(), position);
97 handle_->fd(), position);
98 if (addr == MAP_FAILED) { 97 if (addr == MAP_FAILED) {
99 return NULL; 98 return NULL;
100 } 99 }
101 return addr; 100 return addr;
102 } 101 }
103 102
104 103
105 int64_t File::Read(void* buffer, int64_t num_bytes) { 104 int64_t File::Read(void* buffer, int64_t num_bytes) {
106 ASSERT(handle_->fd() >= 0); 105 ASSERT(handle_->fd() >= 0);
107 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); 106 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes));
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 struct stat st; 318 struct stat st;
320 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { 319 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) {
321 return st.st_size; 320 return st.st_size;
322 } 321 }
323 return -1; 322 return -1;
324 } 323 }
325 324
326 325
327 static int64_t TimespecToMilliseconds(const struct timespec& t) { 326 static int64_t TimespecToMilliseconds(const struct timespec& t) {
328 return static_cast<int64_t>(t.tv_sec) * 1000L + 327 return static_cast<int64_t>(t.tv_sec) * 1000L +
329 static_cast<int64_t>(t.tv_nsec) / 1000000L; 328 static_cast<int64_t>(t.tv_nsec) / 1000000L;
330 } 329 }
331 330
332 331
333 void File::Stat(const char* name, int64_t* data) { 332 void File::Stat(const char* name, int64_t* data) {
334 struct stat st; 333 struct stat st;
335 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { 334 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) {
336 if (S_ISREG(st.st_mode)) { 335 if (S_ISREG(st.st_mode)) {
337 data[kType] = kIsFile; 336 data[kType] = kIsFile;
338 } else if (S_ISDIR(st.st_mode)) { 337 } else if (S_ISDIR(st.st_mode)) {
339 data[kType] = kIsDirectory; 338 data[kType] = kIsDirectory;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 return NULL; 370 return NULL;
372 } 371 }
373 if (!S_ISLNK(link_stats.st_mode)) { 372 if (!S_ISLNK(link_stats.st_mode)) {
374 errno = ENOENT; 373 errno = ENOENT;
375 return NULL; 374 return NULL;
376 } 375 }
377 // Don't rely on the link_stats.st_size for the size of the link 376 // Don't rely on the link_stats.st_size for the size of the link
378 // target. The link might have changed before the readlink call. 377 // target. The link might have changed before the readlink call.
379 const int kBufferSize = 1024; 378 const int kBufferSize = 1024;
380 char target[kBufferSize]; 379 char target[kBufferSize];
381 size_t target_size = TEMP_FAILURE_RETRY( 380 size_t target_size =
382 readlink(pathname, target, kBufferSize)); 381 TEMP_FAILURE_RETRY(readlink(pathname, target, kBufferSize));
383 if (target_size <= 0) { 382 if (target_size <= 0) {
384 return NULL; 383 return NULL;
385 } 384 }
386 char* target_name = DartUtils::ScopedCString(target_size + 1); 385 char* target_name = DartUtils::ScopedCString(target_size + 1);
387 ASSERT(target_name != NULL); 386 ASSERT(target_name != NULL);
388 memmove(target_name, target, target_size); 387 memmove(target_name, target, target_size);
389 target_name[target_size] = '\0'; 388 target_name[target_size] = '\0';
390 return target_name; 389 return target_name;
391 } 390 }
392 391
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 474
476 475
477 File::Identical File::AreIdentical(const char* file_1, const char* file_2) { 476 File::Identical File::AreIdentical(const char* file_1, const char* file_2) {
478 struct stat file_1_info; 477 struct stat file_1_info;
479 struct stat file_2_info; 478 struct stat file_2_info;
480 if ((NO_RETRY_EXPECTED(lstat(file_1, &file_1_info)) == -1) || 479 if ((NO_RETRY_EXPECTED(lstat(file_1, &file_1_info)) == -1) ||
481 (NO_RETRY_EXPECTED(lstat(file_2, &file_2_info)) == -1)) { 480 (NO_RETRY_EXPECTED(lstat(file_2, &file_2_info)) == -1)) {
482 return File::kError; 481 return File::kError;
483 } 482 }
484 return ((file_1_info.st_ino == file_2_info.st_ino) && 483 return ((file_1_info.st_ino == file_2_info.st_ino) &&
485 (file_1_info.st_dev == file_2_info.st_dev)) ? 484 (file_1_info.st_dev == file_2_info.st_dev))
486 File::kIdentical : 485 ? File::kIdentical
487 File::kDifferent; 486 : File::kDifferent;
488 } 487 }
489 488
490 } // namespace bin 489 } // namespace bin
491 } // namespace dart 490 } // namespace dart
492 491
493 #endif // defined(TARGET_OS_MACOS) 492 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/bin/file_linux.cc ('k') | runtime/bin/file_support.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698