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