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

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

Issue 9630012: Error reporting on File in dart:io (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 months 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
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>
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if (position < 0) { 98 if (position < 0) {
99 // The file is not capable of seeking. Return an error. 99 // The file is not capable of seeking. Return an error.
100 return -1; 100 return -1;
101 } 101 }
102 off_t result = TEMP_FAILURE_RETRY(lseek(handle_->fd(), 0, SEEK_END)); 102 off_t result = TEMP_FAILURE_RETRY(lseek(handle_->fd(), 0, SEEK_END));
103 TEMP_FAILURE_RETRY(lseek(handle_->fd(), position, SEEK_SET)); 103 TEMP_FAILURE_RETRY(lseek(handle_->fd(), position, SEEK_SET));
104 return result; 104 return result;
105 } 105 }
106 106
107 107
108 File* File::Open(const char* name, FileOpenMode mode) { 108 File* File::Open(const char* name, FileOpenMode mode, OSError* os_error) {
109 int flags = O_RDONLY; 109 int flags = O_RDONLY;
110 if ((mode & kWrite) != 0) { 110 if ((mode & kWrite) != 0) {
111 flags = (O_RDWR | O_CREAT); 111 flags = (O_RDWR | O_CREAT);
112 } 112 }
113 if ((mode & kTruncate) != 0) { 113 if ((mode & kTruncate) != 0) {
114 flags = flags | O_TRUNC; 114 flags = flags | O_TRUNC;
115 } 115 }
116 int fd = TEMP_FAILURE_RETRY(open(name, flags, 0666)); 116 int fd = TEMP_FAILURE_RETRY(open(name, flags, 0666));
117 if (fd < 0) { 117 if (fd < 0) {
118 if (os_error != NULL) {
119 os_error->errno_ = errno;
120 os_error->strerror_ = strerror(errno);
121 }
118 return NULL; 122 return NULL;
119 } 123 }
120 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { 124 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) {
121 int position = TEMP_FAILURE_RETRY(lseek(fd, 0, SEEK_END)); 125 int position = TEMP_FAILURE_RETRY(lseek(fd, 0, SEEK_END));
122 if (position < 0) { 126 if (position < 0) {
123 return NULL; 127 return NULL;
124 } 128 }
125 } 129 }
126 return new File(name, new FileHandle(fd)); 130 return new File(name, new FileHandle(fd));
127 } 131 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 int result = fstat(fd, &buf); 213 int result = fstat(fd, &buf);
210 if (result == -1) { 214 if (result == -1) {
211 FATAL2("Failed stat on file descriptor %d: %s", fd, strerror(errno)); 215 FATAL2("Failed stat on file descriptor %d: %s", fd, strerror(errno));
212 } 216 }
213 if (S_ISCHR(buf.st_mode)) return kTerminal; 217 if (S_ISCHR(buf.st_mode)) return kTerminal;
214 if (S_ISFIFO(buf.st_mode)) return kPipe; 218 if (S_ISFIFO(buf.st_mode)) return kPipe;
215 if (S_ISSOCK(buf.st_mode)) return kSocket; 219 if (S_ISSOCK(buf.st_mode)) return kSocket;
216 if (S_ISREG(buf.st_mode)) return kFile; 220 if (S_ISREG(buf.st_mode)) return kFile;
217 return kOther; 221 return kOther;
218 } 222 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698