| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 134 |
| 135 File* File::OpenStdio(int fd) { | 135 File* File::OpenStdio(int fd) { |
| 136 if (fd < 0 || 2 < fd) return NULL; | 136 if (fd < 0 || 2 < fd) return NULL; |
| 137 return new File(NULL, new FileHandle(fd)); | 137 return new File(NULL, new FileHandle(fd)); |
| 138 } | 138 } |
| 139 | 139 |
| 140 | 140 |
| 141 bool File::Exists(const char* name) { | 141 bool File::Exists(const char* name) { |
| 142 struct stat st; | 142 struct stat st; |
| 143 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { | 143 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { |
| 144 return S_ISREG(st.st_mode); // Deal with symlinks? | 144 return S_ISREG(st.st_mode); |
| 145 } else { | 145 } else { |
| 146 return false; | 146 return false; |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 | 150 |
| 151 bool File::Create(const char* name) { | 151 bool File::Create(const char* name) { |
| 152 int fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_CREAT, 0666)); | 152 int fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_CREAT, 0666)); |
| 153 if (fd < 0) { | 153 if (fd < 0) { |
| 154 return false; | 154 return false; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 int result = fstat(fd, &buf); | 233 int result = fstat(fd, &buf); |
| 234 if (result == -1) { | 234 if (result == -1) { |
| 235 FATAL2("Failed stat on file descriptor %d: %s", fd, strerror(errno)); | 235 FATAL2("Failed stat on file descriptor %d: %s", fd, strerror(errno)); |
| 236 } | 236 } |
| 237 if (S_ISCHR(buf.st_mode)) return kTerminal; | 237 if (S_ISCHR(buf.st_mode)) return kTerminal; |
| 238 if (S_ISFIFO(buf.st_mode)) return kPipe; | 238 if (S_ISFIFO(buf.st_mode)) return kPipe; |
| 239 if (S_ISSOCK(buf.st_mode)) return kSocket; | 239 if (S_ISSOCK(buf.st_mode)) return kSocket; |
| 240 if (S_ISREG(buf.st_mode)) return kFile; | 240 if (S_ISREG(buf.st_mode)) return kFile; |
| 241 return kOther; | 241 return kOther; |
| 242 } | 242 } |
| OLD | NEW |