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

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

Issue 12476021: Handle /dev/null on linux, as an closed device. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Apply same fix for mac Created 7 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/eventhandler_macos.cc ('k') | runtime/bin/file_macos.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_LINUX) 6 #if defined(TARGET_OS_LINUX)
7 7
8 #include "bin/file.h" 8 #include "bin/file.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 return st.st_size; 100 return st.st_size;
101 } 101 }
102 return -1; 102 return -1;
103 } 103 }
104 104
105 105
106 File* File::Open(const char* name, FileOpenMode mode) { 106 File* File::Open(const char* name, FileOpenMode mode) {
107 // Report errors for non-regular files. 107 // Report errors for non-regular files.
108 struct stat st; 108 struct stat st;
109 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { 109 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) {
110 if (!S_ISREG(st.st_mode)) { 110 // Only accept regular files and character devices.
111 if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode)) {
111 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; 112 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT;
112 return NULL; 113 return NULL;
113 } 114 }
114 } 115 }
115 int flags = O_RDONLY; 116 int flags = O_RDONLY;
116 if ((mode & kWrite) != 0) { 117 if ((mode & kWrite) != 0) {
117 flags = (O_RDWR | O_CREAT); 118 flags = (O_RDWR | O_CREAT);
118 } 119 }
119 if ((mode & kTruncate) != 0) { 120 if ((mode & kTruncate) != 0) {
120 flags = flags | O_TRUNC; 121 flags = flags | O_TRUNC;
121 } 122 }
122 flags |= O_CLOEXEC; 123 flags |= O_CLOEXEC;
123 int fd = TEMP_FAILURE_RETRY(open(name, flags, 0666)); 124 int fd = TEMP_FAILURE_RETRY(open(name, flags, 0666));
124 if (fd < 0) { 125 if (fd < 0) {
126 printf("Open failed\n");
Søren Gjesse 2013/03/11 15:08:16 Debug print.
Anders Johnsen 2013/06/11 12:14:41 Done.
125 return NULL; 127 return NULL;
126 } 128 }
127 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { 129 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) {
128 int position = TEMP_FAILURE_RETRY(lseek(fd, 0, SEEK_END)); 130 int position = TEMP_FAILURE_RETRY(lseek(fd, 0, SEEK_END));
129 if (position < 0) { 131 if (position < 0) {
130 return NULL; 132 return NULL;
131 } 133 }
132 } 134 }
133 return new File(new FileHandle(fd)); 135 return new File(new FileHandle(fd));
134 } 136 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info)); 258 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info));
257 } 259 }
258 if (stat_success == -1) return File::kDoesNotExist; 260 if (stat_success == -1) return File::kDoesNotExist;
259 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; 261 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory;
260 if (S_ISREG(entry_info.st_mode)) return File::kIsFile; 262 if (S_ISREG(entry_info.st_mode)) return File::kIsFile;
261 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; 263 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink;
262 return File::kDoesNotExist; 264 return File::kDoesNotExist;
263 } 265 }
264 266
265 #endif // defined(TARGET_OS_LINUX) 267 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler_macos.cc ('k') | runtime/bin/file_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698