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

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

Issue 11312242: Revised CL for customisable logging (replacing printfs). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « runtime/bin/file_linux.cc ('k') | runtime/bin/file_win.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/file.h" 5 #include "bin/file.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <unistd.h> 10 #include <unistd.h>
11 #include <libgen.h> 11 #include <libgen.h>
12 #include <limits.h> 12 #include <limits.h>
13 13
14 #include "bin/builtin.h" 14 #include "bin/builtin.h"
15 #include "bin/fdutils.h" 15 #include "bin/fdutils.h"
16 #include "bin/log.h"
16 17
17 class FileHandle { 18 class FileHandle {
18 public: 19 public:
19 explicit FileHandle(int fd) : fd_(fd) { } 20 explicit FileHandle(int fd) : fd_(fd) { }
20 ~FileHandle() { } 21 ~FileHandle() { }
21 int fd() const { return fd_; } 22 int fd() const { return fd_; }
22 void set_fd(int fd) { fd_ = fd; } 23 void set_fd(int fd) { fd_ = fd; }
23 24
24 private: 25 private:
25 int fd_; 26 int fd_;
(...skipping 11 matching lines...) Expand all
37 } 38 }
38 39
39 40
40 void File::Close() { 41 void File::Close() {
41 ASSERT(handle_->fd() >= 0); 42 ASSERT(handle_->fd() >= 0);
42 int err = TEMP_FAILURE_RETRY(close(handle_->fd())); 43 int err = TEMP_FAILURE_RETRY(close(handle_->fd()));
43 if (err != 0) { 44 if (err != 0) {
44 const int kBufferSize = 1024; 45 const int kBufferSize = 1024;
45 char error_message[kBufferSize]; 46 char error_message[kBufferSize];
46 strerror_r(errno, error_message, kBufferSize); 47 strerror_r(errno, error_message, kBufferSize);
47 fprintf(stderr, "%s\n", error_message); 48 Log::PrintErr("%s\n", error_message);
48 } 49 }
49 handle_->set_fd(kClosedFd); 50 handle_->set_fd(kClosedFd);
50 } 51 }
51 52
52 53
53 bool File::IsClosed() { 54 bool File::IsClosed() {
54 return handle_->fd() == kClosedFd; 55 return handle_->fd() == kClosedFd;
55 } 56 }
56 57
57 58
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 int result = fstat(fd, &buf); 243 int result = fstat(fd, &buf);
243 if (result == -1) { 244 if (result == -1) {
244 FATAL2("Failed stat on file descriptor %d: %s", fd, strerror(errno)); 245 FATAL2("Failed stat on file descriptor %d: %s", fd, strerror(errno));
245 } 246 }
246 if (S_ISCHR(buf.st_mode)) return kTerminal; 247 if (S_ISCHR(buf.st_mode)) return kTerminal;
247 if (S_ISFIFO(buf.st_mode)) return kPipe; 248 if (S_ISFIFO(buf.st_mode)) return kPipe;
248 if (S_ISSOCK(buf.st_mode)) return kSocket; 249 if (S_ISSOCK(buf.st_mode)) return kSocket;
249 if (S_ISREG(buf.st_mode)) return kFile; 250 if (S_ISREG(buf.st_mode)) return kFile;
250 return kOther; 251 return kOther;
251 } 252 }
OLDNEW
« no previous file with comments | « runtime/bin/file_linux.cc ('k') | runtime/bin/file_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698