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

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

Issue 1466523002: Landing patch set 7 from https://codereview.chromium.org/1450113003/ (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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_android.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
11 #include <fcntl.h> // NOLINT 11 #include <fcntl.h> // NOLINT
12 #include <sys/stat.h> // NOLINT 12 #include <sys/stat.h> // NOLINT
13 #include <sys/types.h> // NOLINT 13 #include <sys/types.h> // NOLINT
14 #include <sys/sendfile.h> // NOLINT 14 #include <sys/sendfile.h> // NOLINT
15 #include <unistd.h> // NOLINT 15 #include <unistd.h> // NOLINT
16 #include <libgen.h> // NOLINT 16 #include <libgen.h> // NOLINT
17 17
18 #include "platform/signal_blocker.h"
19 #include "bin/builtin.h" 18 #include "bin/builtin.h"
20 #include "bin/log.h" 19 #include "bin/log.h"
20 #include "platform/signal_blocker.h"
21 #include "platform/utils.h"
21 22
22 23
23 namespace dart { 24 namespace dart {
24 namespace bin { 25 namespace bin {
25 26
26 class FileHandle { 27 class FileHandle {
27 public: 28 public:
28 explicit FileHandle(int fd) : fd_(fd) { } 29 explicit FileHandle(int fd) : fd_(fd) { }
29 ~FileHandle() { } 30 ~FileHandle() { }
30 int fd() const { return fd_; } 31 int fd() const { return fd_; }
(...skipping 18 matching lines...) Expand all
49 // If stdout, redirect fd to /dev/null. 50 // If stdout, redirect fd to /dev/null.
50 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); 51 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY));
51 ASSERT(null_fd >= 0); 52 ASSERT(null_fd >= 0);
52 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, handle_->fd())); 53 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, handle_->fd()));
53 VOID_TEMP_FAILURE_RETRY(close(null_fd)); 54 VOID_TEMP_FAILURE_RETRY(close(null_fd));
54 } else { 55 } else {
55 int err = TEMP_FAILURE_RETRY(close(handle_->fd())); 56 int err = TEMP_FAILURE_RETRY(close(handle_->fd()));
56 if (err != 0) { 57 if (err != 0) {
57 const int kBufferSize = 1024; 58 const int kBufferSize = 1024;
58 char error_buf[kBufferSize]; 59 char error_buf[kBufferSize];
59 Log::PrintErr("%s\n", strerror_r(errno, error_buf, kBufferSize)); 60 Log::PrintErr("%s\n", Utils::StrError(errno, error_buf, kBufferSize));
60 } 61 }
61 } 62 }
62 handle_->set_fd(kClosedFd); 63 handle_->set_fd(kClosedFd);
63 } 64 }
64 65
65 66
66 intptr_t File::GetFD() { 67 intptr_t File::GetFD() {
67 return handle_->fd(); 68 return handle_->fd();
68 } 69 }
69 70
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 423
423 424
424 File::StdioHandleType File::GetStdioHandleType(int fd) { 425 File::StdioHandleType File::GetStdioHandleType(int fd) {
425 ASSERT(0 <= fd && fd <= 2); 426 ASSERT(0 <= fd && fd <= 2);
426 struct stat64 buf; 427 struct stat64 buf;
427 int result = TEMP_FAILURE_RETRY(fstat64(fd, &buf)); 428 int result = TEMP_FAILURE_RETRY(fstat64(fd, &buf));
428 if (result == -1) { 429 if (result == -1) {
429 const int kBufferSize = 1024; 430 const int kBufferSize = 1024;
430 char error_buf[kBufferSize]; 431 char error_buf[kBufferSize];
431 FATAL2("Failed stat on file descriptor %d: %s", fd, 432 FATAL2("Failed stat on file descriptor %d: %s", fd,
432 strerror_r(errno, error_buf, kBufferSize)); 433 Utils::StrError(errno, error_buf, kBufferSize));
433 } 434 }
434 if (S_ISCHR(buf.st_mode)) return kTerminal; 435 if (S_ISCHR(buf.st_mode)) return kTerminal;
435 if (S_ISFIFO(buf.st_mode)) return kPipe; 436 if (S_ISFIFO(buf.st_mode)) return kPipe;
436 if (S_ISSOCK(buf.st_mode)) return kSocket; 437 if (S_ISSOCK(buf.st_mode)) return kSocket;
437 if (S_ISREG(buf.st_mode)) return kFile; 438 if (S_ISREG(buf.st_mode)) return kFile;
438 return kOther; 439 return kOther;
439 } 440 }
440 441
441 442
442 File::Type File::GetType(const char* pathname, bool follow_links) { 443 File::Type File::GetType(const char* pathname, bool follow_links) {
(...skipping 22 matching lines...) Expand all
465 return (file_1_info.st_ino == file_2_info.st_ino && 466 return (file_1_info.st_ino == file_2_info.st_ino &&
466 file_1_info.st_dev == file_2_info.st_dev) ? 467 file_1_info.st_dev == file_2_info.st_dev) ?
467 File::kIdentical : 468 File::kIdentical :
468 File::kDifferent; 469 File::kDifferent;
469 } 470 }
470 471
471 } // namespace bin 472 } // namespace bin
472 } // namespace dart 473 } // namespace dart
473 474
474 #endif // defined(TARGET_OS_LINUX) 475 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/file_android.cc ('k') | runtime/bin/file_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698