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

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

Issue 1450113003: Avoid strerror_r portability issues (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: oops namespace 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_linux.cc ('k') | runtime/bin/process_android.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 <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
11 #include <fcntl.h> // NOLINT 11 #include <fcntl.h> // NOLINT
12 #include <copyfile.h> // NOLINT 12 #include <copyfile.h> // NOLINT
13 #include <sys/stat.h> // NOLINT 13 #include <sys/stat.h> // NOLINT
14 #include <unistd.h> // NOLINT 14 #include <unistd.h> // NOLINT
15 #include <libgen.h> // NOLINT 15 #include <libgen.h> // NOLINT
16 #include <limits.h> // NOLINT 16 #include <limits.h> // NOLINT
17 17
18 #include "bin/builtin.h" 18 #include "bin/builtin.h"
19 #include "bin/fdutils.h" 19 #include "bin/fdutils.h"
20 #include "bin/log.h" 20 #include "bin/log.h"
21 21
22 #include "platform/signal_blocker.h" 22 #include "platform/signal_blocker.h"
23 #include "platform/utils.h"
23 24
24 namespace dart { 25 namespace dart {
25 namespace bin { 26 namespace bin {
26 27
27 class FileHandle { 28 class FileHandle {
28 public: 29 public:
29 explicit FileHandle(int fd) : fd_(fd) { } 30 explicit FileHandle(int fd) : fd_(fd) { }
30 ~FileHandle() { } 31 ~FileHandle() { }
31 int fd() const { return fd_; } 32 int fd() const { return fd_; }
32 void set_fd(int fd) { fd_ = fd; } 33 void set_fd(int fd) { fd_ = fd; }
(...skipping 17 matching lines...) Expand all
50 // If stdout, redirect fd to /dev/null. 51 // If stdout, redirect fd to /dev/null.
51 intptr_t null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); 52 intptr_t null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY));
52 ASSERT(null_fd >= 0); 53 ASSERT(null_fd >= 0);
53 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, handle_->fd())); 54 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, handle_->fd()));
54 VOID_TEMP_FAILURE_RETRY(close(null_fd)); 55 VOID_TEMP_FAILURE_RETRY(close(null_fd));
55 } else { 56 } else {
56 intptr_t err = TEMP_FAILURE_RETRY(close(handle_->fd())); 57 intptr_t err = TEMP_FAILURE_RETRY(close(handle_->fd()));
57 if (err != 0) { 58 if (err != 0) {
58 const int kBufferSize = 1024; 59 const int kBufferSize = 1024;
59 char error_message[kBufferSize]; 60 char error_message[kBufferSize];
60 strerror_r(errno, error_message, kBufferSize); 61 Utils::StrError(errno, error_message, kBufferSize);
61 Log::PrintErr("%s\n", error_message); 62 Log::PrintErr("%s\n", error_message);
62 } 63 }
63 } 64 }
64 handle_->set_fd(kClosedFd); 65 handle_->set_fd(kClosedFd);
65 } 66 }
66 67
67 68
68 intptr_t File::GetFD() { 69 intptr_t File::GetFD() {
69 return handle_->fd(); 70 return handle_->fd();
70 } 71 }
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 } 388 }
388 389
389 390
390 File::StdioHandleType File::GetStdioHandleType(int fd) { 391 File::StdioHandleType File::GetStdioHandleType(int fd) {
391 ASSERT(0 <= fd && fd <= 2); 392 ASSERT(0 <= fd && fd <= 2);
392 struct stat buf; 393 struct stat buf;
393 int result = fstat(fd, &buf); 394 int result = fstat(fd, &buf);
394 if (result == -1) { 395 if (result == -1) {
395 const int kBufferSize = 1024; 396 const int kBufferSize = 1024;
396 char error_message[kBufferSize]; 397 char error_message[kBufferSize];
397 strerror_r(errno, error_message, kBufferSize); 398 Utils::StrError(errno, error_message, kBufferSize);
398 FATAL2("Failed stat on file descriptor %d: %s", fd, error_message); 399 FATAL2("Failed stat on file descriptor %d: %s", fd, error_message);
399 } 400 }
400 if (S_ISCHR(buf.st_mode)) return kTerminal; 401 if (S_ISCHR(buf.st_mode)) return kTerminal;
401 if (S_ISFIFO(buf.st_mode)) return kPipe; 402 if (S_ISFIFO(buf.st_mode)) return kPipe;
402 if (S_ISSOCK(buf.st_mode)) return kSocket; 403 if (S_ISSOCK(buf.st_mode)) return kSocket;
403 if (S_ISREG(buf.st_mode)) return kFile; 404 if (S_ISREG(buf.st_mode)) return kFile;
404 return kOther; 405 return kOther;
405 } 406 }
406 407
407 408
(...skipping 23 matching lines...) Expand all
431 return (file_1_info.st_ino == file_2_info.st_ino && 432 return (file_1_info.st_ino == file_2_info.st_ino &&
432 file_1_info.st_dev == file_2_info.st_dev) ? 433 file_1_info.st_dev == file_2_info.st_dev) ?
433 File::kIdentical : 434 File::kIdentical :
434 File::kDifferent; 435 File::kDifferent;
435 } 436 }
436 437
437 } // namespace bin 438 } // namespace bin
438 } // namespace dart 439 } // namespace dart
439 440
440 #endif // defined(TARGET_OS_MACOS) 441 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/bin/file_linux.cc ('k') | runtime/bin/process_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698