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

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

Issue 8383037: Improve error handling in the process library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 <errno.h> 5 #include <errno.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <sys/stat.h> 7 #include <sys/stat.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 #include <libgen.h> 9 #include <libgen.h>
10 10
(...skipping 18 matching lines...) Expand all
29 File::~File() { 29 File::~File() {
30 // Close the file (unless it's a standard stream). 30 // Close the file (unless it's a standard stream).
31 if (handle_->fd() > STDERR_FILENO) { 31 if (handle_->fd() > STDERR_FILENO) {
32 Close(); 32 Close();
33 } 33 }
34 delete handle_; 34 delete handle_;
35 } 35 }
36 36
37 37
38 void File::Close() { 38 void File::Close() {
39 assert(handle_->fd() >= 0); 39 ASSERT(handle_->fd() >= 0);
40 int err = close(handle_->fd()); 40 int err = close(handle_->fd());
41 if (err != 0) { 41 if (err != 0) {
42 const int kBufferSize = 1024; 42 const int kBufferSize = 1024;
43 char error_message[kBufferSize]; 43 char error_message[kBufferSize];
44 strerror_r(errno, error_message, kBufferSize); 44 strerror_r(errno, error_message, kBufferSize);
45 fprintf(stderr, "%s\n", error_message); 45 fprintf(stderr, "%s\n", error_message);
46 } 46 }
47 handle_->set_fd(kClosedFd); 47 handle_->set_fd(kClosedFd);
48 } 48 }
49 49
50 50
51 bool File::IsClosed() { 51 bool File::IsClosed() {
52 return handle_->fd() == kClosedFd; 52 return handle_->fd() == kClosedFd;
53 } 53 }
54 54
55 55
56 int64_t File::Read(void* buffer, int64_t num_bytes) { 56 int64_t File::Read(void* buffer, int64_t num_bytes) {
57 assert(handle_->fd() >= 0); 57 ASSERT(handle_->fd() >= 0);
58 return read(handle_->fd(), buffer, num_bytes); 58 return read(handle_->fd(), buffer, num_bytes);
59 } 59 }
60 60
61 61
62 int64_t File::Write(const void* buffer, int64_t num_bytes) { 62 int64_t File::Write(const void* buffer, int64_t num_bytes) {
63 assert(handle_->fd() >= 0); 63 ASSERT(handle_->fd() >= 0);
64 return write(handle_->fd(), buffer, num_bytes); 64 return write(handle_->fd(), buffer, num_bytes);
65 } 65 }
66 66
67 67
68 off_t File::Position() { 68 off_t File::Position() {
69 assert(handle_->fd() >= 0); 69 ASSERT(handle_->fd() >= 0);
70 return lseek(handle_->fd(), 0, SEEK_CUR); 70 return lseek(handle_->fd(), 0, SEEK_CUR);
71 } 71 }
72 72
73 73
74 void File::Flush() { 74 void File::Flush() {
75 assert(handle_->fd() >= 0); 75 ASSERT(handle_->fd() >= 0);
76 fsync(handle_->fd()); 76 fsync(handle_->fd());
77 } 77 }
78 78
79 79
80 off_t File::Length() { 80 off_t File::Length() {
81 assert(handle_->fd() >= 0); 81 ASSERT(handle_->fd() >= 0);
82 off_t position = lseek(handle_->fd(), 0, SEEK_CUR); 82 off_t position = lseek(handle_->fd(), 0, SEEK_CUR);
83 if (position < 0) { 83 if (position < 0) {
84 // The file is not capable of seeking. Return an error. 84 // The file is not capable of seeking. Return an error.
85 return -1; 85 return -1;
86 } 86 }
87 off_t result = lseek(handle_->fd(), 0, SEEK_END); 87 off_t result = lseek(handle_->fd(), 0, SEEK_END);
88 lseek(handle_->fd(), position, SEEK_SET); 88 lseek(handle_->fd(), position, SEEK_SET);
89 return result; 89 return result;
90 } 90 }
91 91
(...skipping 27 matching lines...) Expand all
119 119
120 120
121 const char* File::PathSeparator() { 121 const char* File::PathSeparator() {
122 return "/"; 122 return "/";
123 } 123 }
124 124
125 125
126 const char* File::StringEscapedPathSeparator() { 126 const char* File::StringEscapedPathSeparator() {
127 return "/"; 127 return "/";
128 } 128 }
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