| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 186 |
| 187 char* File::GetContainingDirectory(char* pathname) { | 187 char* File::GetContainingDirectory(char* pathname) { |
| 188 char* path = NULL; | 188 char* path = NULL; |
| 189 do { | 189 do { |
| 190 path = dirname(pathname); | 190 path = dirname(pathname); |
| 191 } while (path == NULL && errno == EINTR); | 191 } while (path == NULL && errno == EINTR); |
| 192 return GetCanonicalPath(path); | 192 return GetCanonicalPath(path); |
| 193 } | 193 } |
| 194 | 194 |
| 195 | 195 |
| 196 const char* File::GetWorkingDirectory() { |
| 197 return getcwd(NULL, 0); |
| 198 } |
| 199 |
| 200 |
| 196 const char* File::PathSeparator() { | 201 const char* File::PathSeparator() { |
| 197 return "/"; | 202 return "/"; |
| 198 } | 203 } |
| 199 | 204 |
| 200 | 205 |
| 201 const char* File::StringEscapedPathSeparator() { | 206 const char* File::StringEscapedPathSeparator() { |
| 202 return "/"; | 207 return "/"; |
| 203 } | 208 } |
| 204 | 209 |
| 205 | 210 |
| 206 File::StdioHandleType File::GetStdioHandleType(int fd) { | 211 File::StdioHandleType File::GetStdioHandleType(int fd) { |
| 207 ASSERT(0 <= fd && fd <= 2); | 212 ASSERT(0 <= fd && fd <= 2); |
| 208 struct stat buf; | 213 struct stat buf; |
| 209 int result = fstat(fd, &buf); | 214 int result = fstat(fd, &buf); |
| 210 if (result == -1) { | 215 if (result == -1) { |
| 211 FATAL2("Failed stat on file descriptor %d: %s", fd, strerror(errno)); | 216 FATAL2("Failed stat on file descriptor %d: %s", fd, strerror(errno)); |
| 212 } | 217 } |
| 213 if (S_ISCHR(buf.st_mode)) return kTerminal; | 218 if (S_ISCHR(buf.st_mode)) return kTerminal; |
| 214 if (S_ISFIFO(buf.st_mode)) return kPipe; | 219 if (S_ISFIFO(buf.st_mode)) return kPipe; |
| 215 if (S_ISREG(buf.st_mode)) return kFile; | 220 if (S_ISREG(buf.st_mode)) return kFile; |
| 216 return kOther; | 221 return kOther; |
| 217 } | 222 } |
| OLD | NEW |