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

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: Style issues 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
« 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>
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
109 // Report errors for non-regular files.
110 struct stat st;
111 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) {
112 if (!S_ISREG(st.st_mode)) {
113 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT;
114 return NULL
115 }
116 }
109 int flags = O_RDONLY; 117 int flags = O_RDONLY;
110 if ((mode & kWrite) != 0) { 118 if ((mode & kWrite) != 0) {
111 flags = (O_RDWR | O_CREAT); 119 flags = (O_RDWR | O_CREAT);
112 } 120 }
113 if ((mode & kTruncate) != 0) { 121 if ((mode & kTruncate) != 0) {
114 flags = flags | O_TRUNC; 122 flags = flags | O_TRUNC;
115 } 123 }
116 int fd = TEMP_FAILURE_RETRY(open(name, flags, 0666)); 124 int fd = TEMP_FAILURE_RETRY(open(name, flags, 0666));
117 if (fd < 0) { 125 if (fd < 0) {
118 return NULL; 126 return NULL;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 do { 186 do {
179 abs_path = realpath(pathname, NULL); 187 abs_path = realpath(pathname, NULL);
180 } while (abs_path == NULL && errno == EINTR); 188 } while (abs_path == NULL && errno == EINTR);
181 ASSERT(abs_path == NULL || IsAbsolutePath(abs_path)); 189 ASSERT(abs_path == NULL || IsAbsolutePath(abs_path));
182 } 190 }
183 return abs_path; 191 return abs_path;
184 } 192 }
185 193
186 194
187 char* File::GetContainingDirectory(char* pathname) { 195 char* File::GetContainingDirectory(char* pathname) {
196 // Report errors for non-regular files.
197 struct stat st;
198 if (TEMP_FAILURE_RETRY(stat(pathname, &st)) == 0) {
199 if (!S_ISREG(st.st_mode)) {
200 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT;
201 return NULL;
202 }
203 } else {
204 return NULL;
205 }
188 char* path = NULL; 206 char* path = NULL;
189 do { 207 do {
190 path = dirname(pathname); 208 path = dirname(pathname);
191 } while (path == NULL && errno == EINTR); 209 } while (path == NULL && errno == EINTR);
192 return GetCanonicalPath(path); 210 return GetCanonicalPath(path);
193 } 211 }
194 212
195 213
196 const char* File::PathSeparator() { 214 const char* File::PathSeparator() {
197 return "/"; 215 return "/";
(...skipping 11 matching lines...) Expand all
209 int result = fstat(fd, &buf); 227 int result = fstat(fd, &buf);
210 if (result == -1) { 228 if (result == -1) {
211 FATAL2("Failed stat on file descriptor %d: %s", fd, strerror(errno)); 229 FATAL2("Failed stat on file descriptor %d: %s", fd, strerror(errno));
212 } 230 }
213 if (S_ISCHR(buf.st_mode)) return kTerminal; 231 if (S_ISCHR(buf.st_mode)) return kTerminal;
214 if (S_ISFIFO(buf.st_mode)) return kPipe; 232 if (S_ISFIFO(buf.st_mode)) return kPipe;
215 if (S_ISSOCK(buf.st_mode)) return kSocket; 233 if (S_ISSOCK(buf.st_mode)) return kSocket;
216 if (S_ISREG(buf.st_mode)) return kFile; 234 if (S_ISREG(buf.st_mode)) return kFile;
217 return kOther; 235 return kOther;
218 } 236 }
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