| OLD | NEW |
| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { | 119 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { |
| 120 int position = TEMP_FAILURE_RETRY(lseek(fd, 0, SEEK_END)); | 120 int position = TEMP_FAILURE_RETRY(lseek(fd, 0, SEEK_END)); |
| 121 if (position < 0) { | 121 if (position < 0) { |
| 122 return NULL; | 122 return NULL; |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 return new File(name, new FileHandle(fd)); | 125 return new File(name, new FileHandle(fd)); |
| 126 } | 126 } |
| 127 | 127 |
| 128 | 128 |
| 129 File* File::OpenStdio(int fd) { |
| 130 if (fd < 0 || 2 < fd) return NULL; |
| 131 return new File(NULL, new FileHandle(fd)); |
| 132 } |
| 133 |
| 134 |
| 129 bool File::Exists(const char* name) { | 135 bool File::Exists(const char* name) { |
| 130 struct stat st; | 136 struct stat st; |
| 131 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { | 137 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { |
| 132 return S_ISREG(st.st_mode); // Deal with symlinks? | 138 return S_ISREG(st.st_mode); // Deal with symlinks? |
| 133 } else { | 139 } else { |
| 134 return false; | 140 return false; |
| 135 } | 141 } |
| 136 } | 142 } |
| 137 | 143 |
| 138 | 144 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 178 |
| 173 | 179 |
| 174 const char* File::PathSeparator() { | 180 const char* File::PathSeparator() { |
| 175 return "/"; | 181 return "/"; |
| 176 } | 182 } |
| 177 | 183 |
| 178 | 184 |
| 179 const char* File::StringEscapedPathSeparator() { | 185 const char* File::StringEscapedPathSeparator() { |
| 180 return "/"; | 186 return "/"; |
| 181 } | 187 } |
| 188 |
| 189 |
| 190 File::StdioHandleType File::GetStdioHandleType(int fd) { |
| 191 ASSERT(0 <= fd && fd <= 2); |
| 192 struct stat buf; |
| 193 int result = fstat(fd, &buf); |
| 194 if (result == -1) { |
| 195 FATAL2("Failed stat on file descriptor %d: %s", fd, strerror(errno)); |
| 196 } |
| 197 if (S_ISCHR(buf.st_mode)) return kTerminal; |
| 198 if (S_ISFIFO(buf.st_mode)) return kPipe; |
| 199 if (S_ISREG(buf.st_mode)) return kFile; |
| 200 return kOther; |
| 201 } |
| OLD | NEW |